Skip to content

Commit

Permalink
Upload assets dividing by kind
Browse files Browse the repository at this point in the history
  • Loading branch information
namse committed Sep 23, 2024
1 parent e976d39 commit 6c9ef0e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
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)
}

0 comments on commit 6c9ef0e

Please sign in to comment.