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

Put tags in asset, remove sprite & audio doc #962

Merged
merged 1 commit into from
Sep 21, 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
9 changes: 9 additions & 0 deletions luda-editor/new-server/database/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,12 @@ impl<AbortReason> MaybeAborted<AbortReason> {
}
}
}

impl MaybeAborted<()> {
pub fn unwrap(self) {
match self {
MaybeAborted::Aborted { .. } => unreachable!("You should make AbortReason generic"),
MaybeAborted::No => (),
}
}
}
8 changes: 0 additions & 8 deletions luda-editor/new-server/database/schema/0/src/asset/audio.rs

This file was deleted.

15 changes: 11 additions & 4 deletions luda-editor/new-server/database/schema/0/src/asset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
//! Any member of the team can delete the assets uploaded by the team.
//! Trash can function. What the team deleted is temporarily stored for 1 week by default, and can be forcibly deleted

mod audio;
mod sprite;
mod tag;

use crate::*;
pub use audio::*;
pub use sprite::*;
use std::collections::HashSet;
pub use tag::*;

#[document]
struct AssetDoc {
Expand All @@ -21,6 +20,7 @@ struct AssetDoc {
shared: bool,
asset_kind: AssetKind,
byte_size: u64,
tags: HashSet<AssetTag>,
}

#[doc_part]
Expand All @@ -38,6 +38,13 @@ struct TeamAssetDoc {
asset_id: String,
}

#[document]
struct AssetTeamDoc {
#[pk]
asset_id: String,
team_id: String,
}

#[document]
struct TeamAssetTotalBytesDoc {
#[pk]
Expand Down
45 changes: 0 additions & 45 deletions luda-editor/new-server/database/schema/0/src/asset/sprite/mod.rs

This file was deleted.

31 changes: 31 additions & 0 deletions luda-editor/new-server/database/schema/0/src/asset/tag.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use crate::*;

#[doc_part]
#[derive(Copy, PartialEq, Eq, Hash)]
#[archive_attr(derive(PartialEq, Eq, Hash))]
#[repr(u8)]
enum AssetSystemTag {
// Sprite 0 ~ 39
SpriteCharacter = 0,
SpriteObject = 1,
SpriteBackground = 2,
// Audio 40 ~ 79
AudioCharacter = 40,
AudioProp = 41,
AudioBackground = 42,
}

#[document]
struct AssetCustomTagDoc {
#[pk]
id: String,
names: Translations,
}

#[doc_part]
#[derive(PartialEq, Eq, Hash)]
#[archive_attr(derive(PartialEq, Eq, Hash))]
enum AssetTag {
System { tag: AssetSystemTag },
Custom { id: String },
}
16 changes: 15 additions & 1 deletion luda-editor/new-server/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ rpc_macro::define_rpc! {
team_id: String,
asset_name: String,
byte_size: u64,
asset_kind: migration::schema::AssetKind,
asset_kind: AssetKind,
tags: Vec<AssetTag>,
}
struct Response {
asset_id: String,
Expand All @@ -291,5 +292,18 @@ rpc_macro::define_rpc! {
PermissionDenied,
}
},
update_asset_tags_for_asset: {
struct Request {
asset_id: String,
tags: Vec<AssetTag>,
}
struct Response {
}
enum Error {
NeedLogin,
AssetNotExist,
PermissionDenied,
}
},
},
}
8 changes: 1 addition & 7 deletions luda-editor/new-server/rpc/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,4 @@ pub enum EpisodeEditAction {
},
}

pub type SceneSprite = migration::schema::SceneSprite;
pub type SpriteDoc = migration::schema::SpriteDoc;
pub type Sprite = migration::schema::Sprite;
pub type SystemTag = migration::schema::SystemTag;
pub type SpriteTag = migration::schema::SpriteTag;
pub type AssetKind = migration::schema::AssetKind;
pub type AssetDoc = migration::schema::AssetDoc;
pub use migration::schema::{AssetDoc, AssetKind, AssetSystemTag, AssetTag, SceneSprite};
1 change: 1 addition & 0 deletions luda-editor/new-server/server/src/api/asset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod common;
pub mod get_team_asset_docs;
pub mod reserve_team_asset_upload;
pub mod update_asset_tags_for_asset;

#[allow(unused_imports)]
pub use common::*;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub async fn reserve_team_asset_upload(
asset_name,
byte_size,
asset_kind,
tags,
}: &ArchivedRequest,
db: &Database,
session: Session,
Expand Down Expand Up @@ -46,13 +47,19 @@ pub async fn reserve_team_asset_upload(
asset_id: &asset_id,
ttl: None,
},
AssetTeamDocPut {
asset_id: &asset_id,
team_id,
ttl: None,
},
AssetDocPut {
id: &asset_id,
name: asset_name,
shared: false,
asset_kind: &asset_kind.deserialize(),
byte_size: *byte_size,
ttl: None,
tags: &tags.iter().map(|x| x.deserialize()).collect(),
},
))
.await?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use crate::*;
use api::team::is_team_member;
use database::{schema::*, DeserializeInfallible, WantUpdate};
use luda_rpc::asset::update_asset_tags_for_asset::*;

pub async fn update_asset_tags_for_asset(
ArchivedRequest { asset_id, tags }: &ArchivedRequest,
db: &Database,
session: Session,
) -> Result<Response> {
let user_id = session.user_id().await.ok_or(Error::NeedLogin)?;

let asset_team_doc = db
.get(AssetTeamDocGet { asset_id })
.await?
.ok_or(Error::AssetNotExist)?;

if !is_team_member(db, &asset_team_doc.team_id, &user_id).await? {
bail!(Error::PermissionDenied)
}

db.transact::<()>(AssetDocUpdate {
id: asset_id,
want_update: |_| WantUpdate::Yes,
update: |doc| {
doc.tags = tags.iter().map(|x| x.deserialize()).collect();
},
})
.await?
.unwrap();

Ok(Response {})
}
Loading