fix(wcd): create sticker assets when reused content is a reference
This commit is contained in:
@@ -1342,7 +1342,7 @@ def _find_asset_by_sha256(digest: str) -> dict | None:
|
||||
def _register_import_asset(name: str, content: bytes, mime: str) -> dict:
|
||||
digest = hashlib.sha256(content).hexdigest()
|
||||
existing = _find_asset_by_sha256(digest)
|
||||
if existing:
|
||||
if existing and existing.get("type") == "sticker":
|
||||
return existing
|
||||
|
||||
asset_id = f"asset_{uuid.uuid4().hex}"
|
||||
|
||||
@@ -90,6 +90,31 @@ def test_stale_sha256_meta_does_not_reuse_mismatched_file(isolated_asset_store):
|
||||
assert len(asset_dirs(isolated_asset_store)) == 2
|
||||
|
||||
|
||||
def test_reference_with_same_content_creates_sticker_asset(isolated_asset_store):
|
||||
content = SVG.encode()
|
||||
existing_id = "asset_reference00000000000000000000000"
|
||||
existing_dir = isolated_asset_store / existing_id[:2] / existing_id
|
||||
existing_dir.mkdir(parents=True)
|
||||
(existing_dir / "asset.svg").write_bytes(content)
|
||||
(existing_dir / "meta.json").write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"asset_id": existing_id,
|
||||
"name": "old",
|
||||
"type": "reference",
|
||||
"mime_type": "image/svg+xml",
|
||||
"sha256": hashlib.sha256(content).hexdigest(),
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
imported = app._register_import_asset("new", content, "image/svg+xml")
|
||||
|
||||
assert imported["asset_id"] != existing_id
|
||||
assert imported["type"] == "sticker"
|
||||
assert len(asset_dirs(isolated_asset_store)) == 2
|
||||
|
||||
|
||||
def test_wcd_production_uses_real_asset_ids(tmp_path, isolated_asset_store, monkeypatch):
|
||||
manifest = {
|
||||
"format": "wordcloud-canvas",
|
||||
|
||||
Reference in New Issue
Block a user