1
This commit is contained in:
@@ -6,11 +6,12 @@ use module_puzzle::{
|
||||
PuzzleGeneratedImagesSaveInput, PuzzlePublicationStatus, PuzzlePublishInput, PuzzleResultDraft,
|
||||
PuzzleRunDragInput, PuzzleRunGetInput, PuzzleRunNextLevelInput, PuzzleRunProcedureResult,
|
||||
PuzzleRunSnapshot, PuzzleRunStartInput, PuzzleRunSwapInput, PuzzleRuntimeLevelStatus,
|
||||
PuzzleSelectCoverImageInput, PuzzleWorkGetInput, PuzzleWorkProcedureResult, PuzzleWorkProfile,
|
||||
PuzzleWorkUpsertInput, PuzzleWorksListInput, PuzzleWorksProcedureResult,
|
||||
apply_publish_overrides_to_draft, apply_selected_candidate, build_result_preview,
|
||||
compile_result_draft, create_work_profile, infer_anchor_pack, normalize_theme_tags,
|
||||
publish_work_profile, resolve_puzzle_grid_size, select_next_profile, start_run, swap_pieces,
|
||||
PuzzleSelectCoverImageInput, PuzzleWorkDeleteInput, PuzzleWorkGetInput,
|
||||
PuzzleWorkProcedureResult, PuzzleWorkProfile, PuzzleWorkUpsertInput, PuzzleWorksListInput,
|
||||
PuzzleWorksProcedureResult, apply_publish_overrides_to_draft, apply_selected_candidate,
|
||||
build_result_preview, compile_result_draft, create_work_profile, infer_anchor_pack,
|
||||
normalize_theme_tags, publish_work_profile, resolve_puzzle_grid_size, select_next_profile,
|
||||
start_run, swap_pieces,
|
||||
};
|
||||
use serde_json::from_str as json_from_str;
|
||||
use serde_json::to_string as json_to_string;
|
||||
@@ -310,6 +311,25 @@ pub fn update_puzzle_work(
|
||||
}
|
||||
}
|
||||
|
||||
#[spacetimedb::procedure]
|
||||
pub fn delete_puzzle_work(
|
||||
ctx: &mut ProcedureContext,
|
||||
input: PuzzleWorkDeleteInput,
|
||||
) -> PuzzleWorksProcedureResult {
|
||||
match ctx.try_with_tx(|tx| delete_puzzle_work_tx(tx, input.clone())) {
|
||||
Ok(items) => PuzzleWorksProcedureResult {
|
||||
ok: true,
|
||||
items_json: Some(serialize_json(&items)),
|
||||
error_message: None,
|
||||
},
|
||||
Err(message) => PuzzleWorksProcedureResult {
|
||||
ok: false,
|
||||
items_json: None,
|
||||
error_message: Some(message),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[spacetimedb::procedure]
|
||||
pub fn list_puzzle_gallery(ctx: &mut ProcedureContext) -> PuzzleWorksProcedureResult {
|
||||
match ctx.try_with_tx(|tx| list_puzzle_gallery_tx(tx)) {
|
||||
@@ -890,6 +910,65 @@ fn update_puzzle_work_tx(
|
||||
)
|
||||
}
|
||||
|
||||
fn delete_puzzle_work_tx(
|
||||
ctx: &TxContext,
|
||||
input: PuzzleWorkDeleteInput,
|
||||
) -> Result<Vec<PuzzleWorkProfile>, String> {
|
||||
let row = ctx
|
||||
.db
|
||||
.puzzle_work_profile()
|
||||
.profile_id()
|
||||
.find(&input.profile_id)
|
||||
.ok_or_else(|| "拼图作品不存在".to_string())?;
|
||||
if row.owner_user_id != input.owner_user_id {
|
||||
return Err("无权删除该拼图作品".to_string());
|
||||
}
|
||||
|
||||
// 删除作品时同步清理来源 Agent 会话和运行快照,保持创作页列表与运行态数据一致。
|
||||
ctx.db
|
||||
.puzzle_work_profile()
|
||||
.profile_id()
|
||||
.delete(&row.profile_id);
|
||||
if let Some(session_id) = row.source_session_id.as_ref() {
|
||||
if let Some(session) = ctx.db.puzzle_agent_session().session_id().find(session_id) {
|
||||
ctx.db
|
||||
.puzzle_agent_session()
|
||||
.session_id()
|
||||
.delete(&session.session_id);
|
||||
}
|
||||
for message in ctx
|
||||
.db
|
||||
.puzzle_agent_message()
|
||||
.iter()
|
||||
.filter(|message| message.session_id == *session_id)
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
ctx.db
|
||||
.puzzle_agent_message()
|
||||
.message_id()
|
||||
.delete(&message.message_id);
|
||||
}
|
||||
}
|
||||
for run in ctx
|
||||
.db
|
||||
.puzzle_runtime_run()
|
||||
.iter()
|
||||
.filter(|run| {
|
||||
run.owner_user_id == input.owner_user_id && run.entry_profile_id == input.profile_id
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
ctx.db.puzzle_runtime_run().run_id().delete(&run.run_id);
|
||||
}
|
||||
|
||||
list_puzzle_works_tx(
|
||||
ctx,
|
||||
PuzzleWorksListInput {
|
||||
owner_user_id: input.owner_user_id,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn list_puzzle_gallery_tx(ctx: &TxContext) -> Result<Vec<PuzzleWorkProfile>, String> {
|
||||
let mut items = ctx
|
||||
.db
|
||||
|
||||
Reference in New Issue
Block a user