129 lines
4.1 KiB
Rust
129 lines
4.1 KiB
Rust
//! 资产领域模型。
|
|
//!
|
|
//! 本层只保留资产对象、实体绑定、访问策略、版本和业务归属等纯领域事实。
|
|
//! OSS 对象探测、HTTP DTO 映射和 SpacetimeDB row 写入都属于外层 adapter。
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
#[cfg(feature = "spacetime-types")]
|
|
use spacetimedb::SpacetimeType;
|
|
|
|
pub const ASSET_OBJECT_ID_PREFIX: &str = "assetobj_";
|
|
pub const ASSET_BINDING_ID_PREFIX: &str = "assetbind_";
|
|
pub const INITIAL_ASSET_OBJECT_VERSION: u32 = 1;
|
|
|
|
// 资产对象访问策略先冻结为枚举,避免 reducer、HTTP DTO 和脚本里散落字符串字面量。
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum AssetObjectAccessPolicy {
|
|
Private,
|
|
PublicRead,
|
|
}
|
|
|
|
impl AssetObjectAccessPolicy {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Self::Private => "private",
|
|
Self::PublicRead => "public_read",
|
|
}
|
|
}
|
|
}
|
|
|
|
/// SpacetimeDB 写入前的资产对象快照。
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct AssetObjectUpsertSnapshot {
|
|
pub asset_object_id: String,
|
|
pub bucket: String,
|
|
pub object_key: String,
|
|
pub access_policy: AssetObjectAccessPolicy,
|
|
pub content_type: Option<String>,
|
|
pub content_length: u64,
|
|
pub content_hash: Option<String>,
|
|
pub version: u32,
|
|
pub source_job_id: Option<String>,
|
|
pub owner_user_id: Option<String>,
|
|
pub profile_id: Option<String>,
|
|
pub entity_id: Option<String>,
|
|
pub asset_kind: String,
|
|
pub created_at_micros: i64,
|
|
pub updated_at_micros: i64,
|
|
}
|
|
|
|
/// 资产历史列表的领域快照。
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct AssetHistoryEntrySnapshot {
|
|
pub asset_object_id: String,
|
|
pub asset_kind: String,
|
|
pub image_src: String,
|
|
pub owner_user_id: Option<String>,
|
|
pub profile_id: Option<String>,
|
|
pub entity_id: Option<String>,
|
|
pub created_at_micros: i64,
|
|
pub updated_at_micros: i64,
|
|
}
|
|
|
|
/// 业务实体与资产对象的绑定快照。
|
|
#[cfg_attr(feature = "spacetime-types", derive(SpacetimeType))]
|
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct AssetEntityBindingSnapshot {
|
|
pub binding_id: String,
|
|
pub asset_object_id: String,
|
|
pub entity_kind: String,
|
|
pub entity_id: String,
|
|
pub slot: String,
|
|
pub asset_kind: String,
|
|
pub owner_user_id: Option<String>,
|
|
pub profile_id: Option<String>,
|
|
pub created_at_micros: i64,
|
|
pub updated_at_micros: i64,
|
|
}
|
|
|
|
/// 面向 API 与前端展示的资产对象记录。
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct AssetObjectRecord {
|
|
pub asset_object_id: String,
|
|
pub bucket: String,
|
|
pub object_key: String,
|
|
pub access_policy: AssetObjectAccessPolicy,
|
|
pub content_type: Option<String>,
|
|
pub content_length: u64,
|
|
pub content_hash: Option<String>,
|
|
pub version: u32,
|
|
pub source_job_id: Option<String>,
|
|
pub owner_user_id: Option<String>,
|
|
pub profile_id: Option<String>,
|
|
pub entity_id: Option<String>,
|
|
pub asset_kind: String,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
}
|
|
|
|
/// 面向 API 与前端展示的资产历史记录。
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct AssetHistoryEntryRecord {
|
|
pub asset_object_id: String,
|
|
pub asset_kind: String,
|
|
pub image_src: String,
|
|
pub owner_user_id: Option<String>,
|
|
pub profile_id: Option<String>,
|
|
pub entity_id: Option<String>,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
}
|
|
|
|
/// 面向 API 与前端展示的实体绑定记录。
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct AssetEntityBindingRecord {
|
|
pub binding_id: String,
|
|
pub asset_object_id: String,
|
|
pub entity_kind: String,
|
|
pub entity_id: String,
|
|
pub slot: String,
|
|
pub asset_kind: String,
|
|
pub owner_user_id: Option<String>,
|
|
pub profile_id: Option<String>,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
}
|