fix: use cache for input files instead of hardcoded paths

This commit is contained in:
gilesb
2026-01-07 13:42:36 +00:00
parent 32b6aef1ea
commit e6184b8bd3

View File

@@ -54,12 +54,11 @@ def render_effect(self, input_hash: str, effect_name: str, output_name: str) ->
Returns: Returns:
Provenance record with output hash Provenance record with output hash
""" """
# Registry hashes # Cache directory (shared between server and worker)
CACHE_DIR = Path(os.environ.get("CACHE_DIR", str(Path.home() / ".artdag" / "cache")))
# Registry hashes (for effects/infra metadata only)
REGISTRY = { REGISTRY = {
"cat": {
"hash": "33268b6e167deaf018cc538de12dbe562612b33e89a749391cef855b320a269b",
"path": Path.home() / "artdag-art" / "cat.jpg"
},
"effect:dog": { "effect:dog": {
"hash": "d048fe313433eb4e38f0e24194ffae91b896ca3e6eed3e50b2cc37b7be495555" "hash": "d048fe313433eb4e38f0e24194ffae91b896ca3e6eed3e50b2cc37b7be495555"
}, },
@@ -74,27 +73,19 @@ def render_effect(self, input_hash: str, effect_name: str, output_name: str) ->
} }
} }
# Find input by hash # Input comes from cache by hash
input_asset = None input_path = CACHE_DIR / input_hash
input_name = None if not input_path.exists():
for name, data in REGISTRY.items(): raise ValueError(f"Input not in cache: {input_hash}")
if data.get("hash") == input_hash and "path" in data:
input_asset = data
input_name = name
break
if not input_asset: output_dir = CACHE_DIR
raise ValueError(f"Unknown input hash: {input_hash}")
input_path = input_asset["path"]
output_dir = Path.home() / "artdag-art"
# Verify input # Verify input
actual_hash = file_hash(input_path) actual_hash = file_hash(input_path)
if actual_hash != input_hash: if actual_hash != input_hash:
raise ValueError(f"Input hash mismatch: expected {input_hash}, got {actual_hash}") raise ValueError(f"Input hash mismatch: expected {input_hash}, got {actual_hash}")
self.update_state(state='RENDERING', meta={'effect': effect_name, 'input': input_name}) self.update_state(state='RENDERING', meta={'effect': effect_name, 'input': input_hash[:16]})
# Load and apply effect # Load and apply effect
if effect_name == "dog": if effect_name == "dog":
@@ -126,7 +117,7 @@ def render_effect(self, input_hash: str, effect_name: str, output_name: str) ->
"local_path": str(result) "local_path": str(result)
}, },
"inputs": [ "inputs": [
{"name": input_name, "content_hash": input_hash} {"content_hash": input_hash}
], ],
"effects": [ "effects": [
{"name": f"effect:{effect_name}", "content_hash": REGISTRY[f"effect:{effect_name}"]["hash"]} {"name": f"effect:{effect_name}", "content_hash": REGISTRY[f"effect:{effect_name}"]["hash"]}