Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload assets dividing by kind #968

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions luda-editor/new-server/rpc/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ pub enum EpisodeEditAction {
}

pub use migration::schema::{AssetDoc, AssetKind, AssetSystemTag, AssetTag, SceneSprite};

/// Use this on the client side to get the S3 URL of an asset.
pub fn asset_s3_get_key(asset_id: &str, asset_kind: AssetKind) -> String {
match asset_kind {
AssetKind::Sprite => format!("sprite/{asset_id}"),
AssetKind::Audio => format!("audio/after-transcode/{asset_id}"),
}
}

/// I guess you don't need to use this on the client side.
pub fn asset_s3_put_key(asset_id: &str, asset_kind: AssetKind) -> String {
match asset_kind {
AssetKind::Sprite => format!("sprite/{asset_id}"),
AssetKind::Audio => format!("audio/before-transcode/{asset_id}"),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::*;
use api::team::is_team_member;
use aws_sdk_s3::presigning::PresigningConfig;
use database::{schema::*, DeserializeInfallible, WantUpdate};
use luda_rpc::asset::reserve_team_asset_upload::*;
use luda_rpc::{asset::reserve_team_asset_upload::*, asset_s3_put_key};
use randum::rand;

pub async fn reserve_team_asset_upload(
Expand Down Expand Up @@ -70,7 +70,7 @@ pub async fn reserve_team_asset_upload(
let presigned = s3::s3()
.put_object()
.bucket(s3::asset_bucket_name())
.key(s3::asset_key(&asset_id))
.key(asset_s3_put_key(&asset_id, asset_kind.deserialize()))
.content_length(*byte_size as i64)
.presigned(PresigningConfig::expires_in(
std::time::Duration::from_secs(180),
Expand Down
4 changes: 0 additions & 4 deletions luda-editor/new-server/server/src/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,3 @@ pub fn asset_bucket_name() -> &'static str {
static ASSET_BUCKET_NAME: OnceLock<String> = OnceLock::new();
ASSET_BUCKET_NAME.get_or_init(|| std::env::var("ASSET_BUCKET_NAME").unwrap())
}

pub fn asset_key(asset_id: &str) -> String {
format!("asset/{}", asset_id)
}
Loading