diff --git a/luda-editor/new-server/rpc/src/types/mod.rs b/luda-editor/new-server/rpc/src/types/mod.rs index 01ea99ed2..39fad0a22 100644 --- a/luda-editor/new-server/rpc/src/types/mod.rs +++ b/luda-editor/new-server/rpc/src/types/mod.rs @@ -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}"), + } +} diff --git a/luda-editor/new-server/server/src/api/asset/reserve_team_asset_upload/mod.rs b/luda-editor/new-server/server/src/api/asset/reserve_team_asset_upload/mod.rs index 7983d4423..c1e2d2cc2 100644 --- a/luda-editor/new-server/server/src/api/asset/reserve_team_asset_upload/mod.rs +++ b/luda-editor/new-server/server/src/api/asset/reserve_team_asset_upload/mod.rs @@ -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( @@ -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), diff --git a/luda-editor/new-server/server/src/s3.rs b/luda-editor/new-server/server/src/s3.rs index a5a61c8d3..5e7c6975a 100644 --- a/luda-editor/new-server/server/src/s3.rs +++ b/luda-editor/new-server/server/src/s3.rs @@ -32,7 +32,3 @@ pub fn asset_bucket_name() -> &'static str { static ASSET_BUCKET_NAME: OnceLock = 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) -}