仅交付正式成品并独立备份工程
This commit is contained in:
parent
dad14e57cd
commit
978836cf52
@ -76,20 +76,12 @@ pub(super) fn detail_artifacts(project: &Path) -> R<Vec<Artifact>> {
|
||||
{
|
||||
return Err("成品版本与制作回执不一致,请重新导出".into());
|
||||
}
|
||||
let files = manifest["files"].as_array().filter(|rows| !rows.is_empty()).ok_or("成品图片缺失")?;
|
||||
let screens = manifest["screenFiles"].as_array().filter(|rows| !rows.is_empty());
|
||||
let image_group = if component == "detail" && screens.is_some() { "files" } else { group };
|
||||
let files = if component == "detail" { screens.or_else(|| manifest["files"].as_array()) }
|
||||
else { manifest["files"].as_array() }.filter(|rows| !rows.is_empty()).ok_or("成品图片缺失")?;
|
||||
for (index, row) in files.iter().enumerate() {
|
||||
artifacts.push(artifact(generation, row, image_group, format!("{component}-{:03}-{:03}.jpg", output_index + 1, index + 1))?);
|
||||
artifacts.push(artifact(generation, row, group, format!("{component}-{:03}-{:03}.jpg", output_index + 1, index + 1))?);
|
||||
}
|
||||
if component == "detail" {
|
||||
for (index, row) in screens.into_iter().flatten().enumerate() {
|
||||
artifacts.push(artifact(generation, row, group, format!("detail-screen-{:03}-{:03}.jpg", output_index + 1, index + 1))?);
|
||||
}
|
||||
}
|
||||
let layered = &manifest["layeredDocument"];
|
||||
let format = layered["format"].as_str().filter(|v| matches!(*v, "psd" | "psb")).ok_or("成品分层文件缺失")?;
|
||||
artifacts.push(artifact(generation, layered, "files", format!("{component}-{:03}.{format}", output_index + 1))?);
|
||||
}
|
||||
for component in ["detail", "main_images", "sku_images"] {
|
||||
if !found.iter().any(|(_, item)| item == component) {
|
||||
@ -163,7 +155,7 @@ impl Backend {
|
||||
return Err(format!("此项目已有完结交付,素材 ID:{id};已有素材已保留"));
|
||||
}
|
||||
let purpose = format!("xiaoyi:{cloud_id}:{request_id}");
|
||||
let mut groups = json!({"main":[],"sku":[],"detail":[],"files":[]});
|
||||
let mut groups = json!({"main":[],"sku":[],"detail":[]});
|
||||
for (index, artifact) in artifacts.iter().enumerate() {
|
||||
self.check_dispatch()?;
|
||||
let key = index.to_string();
|
||||
|
||||
@ -644,37 +644,66 @@ impl Backend {
|
||||
let revision = input["revision"].as_u64().ok_or("缺少本机版本")?;
|
||||
self.ensure_owner(id)?;
|
||||
let dir = self.project_dir(id)?;
|
||||
super::projects::idle(&dir)?;
|
||||
let artifacts = super::material_delivery::detail_artifacts(&dir)?;
|
||||
let context = { let _guard = context_guard(); read_json(&dir.join("context.json"))? };
|
||||
let synced = if context["revision"].as_u64() == Some(revision)
|
||||
&& context["syncedRevision"].as_u64() == Some(revision)
|
||||
&& context["syncDirty"] == false && context["project"]["source"] == "desktop"
|
||||
&& context["project"]["id"].is_string()
|
||||
{
|
||||
json!({"cloudLink":context["project"],"syncDirty":false})
|
||||
} else {
|
||||
let mut draft = input.clone();
|
||||
draft["status"] = json!("draft");
|
||||
self.sync_project_core(&draft)?
|
||||
};
|
||||
if synced["syncDirty"] == true {
|
||||
return Err("本机项目在同步期间发生变化,请重新保存后完结".into());
|
||||
}
|
||||
let cloud_id = synced["cloudLink"]["id"].as_str().ok_or("云项目身份缺失")?;
|
||||
let receipt = self.upload_material_delivery(&dir, cloud_id, revision, &artifacts)?;
|
||||
{
|
||||
let cloud_id = self.delivery_project_id(&dir, revision)?;
|
||||
let receipt = self.upload_material_delivery(&dir, &cloud_id, revision, &artifacts)?;
|
||||
let context = {
|
||||
let _guard = context_guard();
|
||||
let mut context = read_json(&dir.join("context.json"))?;
|
||||
context["materialDelivery"] = receipt.clone();
|
||||
context["syncDirty"] = json!(true);
|
||||
if context["revision"].as_u64() == Some(revision) {
|
||||
context["status"] = json!("completed");
|
||||
}
|
||||
write_json(&dir.join("context.json"), &context)?;
|
||||
context
|
||||
};
|
||||
Ok(json!({"doc":id,"revision":revision,"localId":context["localId"],"cloudLink":context["project"],
|
||||
"syncedRevision":context["syncedRevision"],"syncDirty":true,"status":context["status"],
|
||||
"accountId":self.auth["account"]["id"],"origin":self.origin,"materialDelivery":receipt,
|
||||
"projects":self.native_projects()?}))
|
||||
}
|
||||
|
||||
fn delivery_project_id(&self, dir: &Path, revision: u64) -> R<String> {
|
||||
let context = { let _guard = context_guard(); read_json(&dir.join("context.json"))? };
|
||||
if context["revision"].as_u64() != Some(revision) { return Err("本机版本已变化,请保存后重新完结".into()); }
|
||||
if context["project"]["source"] == "desktop" {
|
||||
return context["project"]["id"].as_str().filter(|id| Uuid::parse_str(id).is_ok())
|
||||
.map(str::to_owned).ok_or_else(|| "云项目身份无效".into());
|
||||
}
|
||||
let mut result = self.sync_project_core(input).map_err(|error| format!(
|
||||
"素材已入库(素材 ID:{}),重新完结会继续同步:{error}",
|
||||
receipt["materialId"].as_str().unwrap_or("未知")
|
||||
))?;
|
||||
result["materialDelivery"] = receipt;
|
||||
Ok(result)
|
||||
let pending_file = dir.join("cloud-sync.json");
|
||||
let pending = if pending_file.exists() { read_json(&pending_file)? } else { json!({}) };
|
||||
let cloud_id = pending["id"].as_str().filter(|id| Uuid::parse_str(id).is_ok())
|
||||
.map(str::to_owned).unwrap_or_else(|| Uuid::new_v4().to_string());
|
||||
if pending["id"] != cloud_id {
|
||||
write_json(&pending_file, &json!({"id":cloud_id,"revision":0,"localRevision":revision,"phase":"prepared"}))?;
|
||||
}
|
||||
let remote_revision = if let Some(remote) = self.cloud_snapshot(&cloud_id)? {
|
||||
remote["project"]["revision"].as_u64().ok_or("云项目版本缺失")?
|
||||
} else {
|
||||
let doc = photocraft_format::load_path(&dir.join("canvas.pcraft")).map_err(|_| "本机工程读取失败")?;
|
||||
let screens = screen_rects(&doc)?.into_iter().enumerate().map(|(index, rect)|
|
||||
json!({"id":format!("s{}",index + 1),"name":format!("第{}屏",index + 1),
|
||||
"width":rect.width(),"height":rect.height(),"previewSource":null})).collect::<Vec<_>>();
|
||||
let source_web = if context["project"]["source"] == "web" { context["project"]["id"].clone() }
|
||||
else { context["project"]["sourceWebId"].clone() };
|
||||
let result = self.put_sync_json(&cloud_id, &json!({"document":{"version":3,"id":cloud_id,
|
||||
"name":doc.name,"native":{"format":"photocraft","schemaVersion":1,"documentSource":null,"files":[]},
|
||||
"screens":screens},"revision":0,"status":"draft","conversation":[],"composer":"","sourceWebId":source_web}))?;
|
||||
result["project"]["revision"].as_u64().ok_or("云项目版本缺失")?
|
||||
};
|
||||
let _guard = context_guard();
|
||||
let mut current = read_json(&dir.join("context.json"))?;
|
||||
let previous = current["project"].clone();
|
||||
current["project"] = json!({"source":"desktop","id":cloud_id,"revision":remote_revision,
|
||||
"sourceWebId":if previous["source"] == "web" { previous["id"].clone() } else { previous["sourceWebId"].clone() }});
|
||||
for key in ["document", "materialReferences"] {
|
||||
if !previous[key].is_null() { current["project"][key] = previous[key].clone(); }
|
||||
}
|
||||
current["syncDirty"] = json!(true);
|
||||
write_json(&dir.join("context.json"), ¤t)?;
|
||||
Ok(cloud_id)
|
||||
}
|
||||
|
||||
fn sync_project_core(&mut self, input: &Value) -> R<Value> {
|
||||
|
||||
@ -664,7 +664,9 @@ pub(super) fn sync_received(w: &mut Workspace, app: &PhotocraftApp, value: &Valu
|
||||
w.note(format!("成品已提交素材库,素材 ID:{id}"));
|
||||
}
|
||||
w.project_refresh_requested = true;
|
||||
w.creation_progress = if w.sync_dirty { "云端已保存该版本,当前仍有新修改" } else { "已同步" }.into();
|
||||
w.creation_progress = if value["materialDelivery"]["materialId"].is_string() {
|
||||
"成品已提交素材库;项目可另行云同步"
|
||||
} else if w.sync_dirty { "云端已保存该版本,当前仍有新修改" } else { "已同步" }.into();
|
||||
}
|
||||
// The import worker reports a final receipt rather than intermediate bytes;
|
||||
// expose activity only and never manufacture an upload percentage.
|
||||
@ -873,7 +875,7 @@ impl Workspace {
|
||||
self.sync_confirm = true;
|
||||
}
|
||||
let closed = stitch_ui::dialog(ui, egui::Id::unique("xiaoyi-finish-project"), "完结项目", self.sync_confirm, self.reduce_motion, 360.0, |ui| {
|
||||
ui.label("将已完成的详情、主图和 SKU 成品提交到素材库,并同步项目?");
|
||||
ui.label("将已完成的详情、主图和 SKU 成品提交到素材库?项目备份可另行云同步。");
|
||||
if let Some(id) = self.project_context["materialDelivery"]["materialId"].as_str() {
|
||||
ui.label(format!("上次提交的素材 ID:{id}"));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user