diff --git a/backend/service/product_archive.py b/backend/service/product_archive.py index 696b4ab..223d38c 100644 --- a/backend/service/product_archive.py +++ b/backend/service/product_archive.py @@ -34,7 +34,8 @@ def find_visible_wordcloud_sources( asset_id = str(element.get("assetId") or "") meta = load_asset_meta(asset_id) job_id = str(meta.get("job_id") or "") - if meta.get("type") == "wordcloud" and job_id and job_id not in seen: + asset_type = str(meta.get("type") or "") + if asset_type in {"wordcloud", "sticker"} and job_id and job_id not in seen: seen.add(job_id) result.append(WordcloudSource(asset_id, job_id)) return result diff --git a/backend/tests/test_product_archive.py b/backend/tests/test_product_archive.py index 7045c05..c334aa0 100644 --- a/backend/tests/test_product_archive.py +++ b/backend/tests/test_product_archive.py @@ -145,6 +145,15 @@ def test_scanner_skips_wordcloud_without_job_id(): assert find_visible_wordcloud_sources(document, assets.__getitem__) == [] +def test_scanner_accepts_job_imported_wordcloud_stickers(): + document = {"elements": [{"type": "sticker", "assetId": "wc-a"}]} + assets = {"wc-a": {"type": "sticker", "job_id": "a" * 32}} + + assert find_visible_wordcloud_sources(document, assets.__getitem__) == [ + WordcloudSource("wc-a", "a" * 32) + ] + + def test_snapshot_rejects_non_sqlite_file_without_creating_destination(tmp_path): source = tmp_path / "not-a-database.sqlite" destination = tmp_path / "archive" / "word_locations.sqlite" diff --git a/frontend/src/lib/stickerLibrary.ts b/frontend/src/lib/stickerLibrary.ts index 4ca69ec..dc6c28c 100644 --- a/frontend/src/lib/stickerLibrary.ts +++ b/frontend/src/lib/stickerLibrary.ts @@ -154,7 +154,7 @@ export async function addStickerAssetFromJob( ): Promise { const form = new FormData(); form.append('name', name || `词云 ${new Date().toLocaleString('zh-CN')}`); - form.append('type', 'sticker'); + form.append('type', 'wordcloud'); const res = await ensureOk( await fetch(apiUrl(`/api/assets/from-job/${jobId}`), { method: 'POST', body: form }), '从任务导入贴纸失败', @@ -166,6 +166,7 @@ export async function addStickerAssetFromJob( type: asset.mime_type === 'image/svg+xml' ? 'svg' : 'image', source: asset.file_url, createdAt: asset.created_at, + jobId: asset.job_id || undefined, mimeType: asset.mime_type, }; window.dispatchEvent(new CustomEvent(STICKER_LIBRARY_EVENT));