Fix IPFS upload: sync instead of background task
The background IPFS upload task was running on workers that don't have the file locally, causing uploads to fail silently. Now uploads go to IPFS synchronously so the IPFS CID is available immediately. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -554,13 +554,13 @@ class CacheService:
|
|||||||
# Detect media type (video/image/audio) before moving file
|
# Detect media type (video/image/audio) before moving file
|
||||||
media_type = detect_media_type(tmp_path)
|
media_type = detect_media_type(tmp_path)
|
||||||
|
|
||||||
# Store locally first (skip_ipfs=True for fast response)
|
# Store locally AND upload to IPFS synchronously
|
||||||
# IPFS upload happens in background
|
# This ensures the IPFS CID is available immediately for distributed access
|
||||||
cached, ipfs_cid = self.cache.put(tmp_path, node_type="upload", move=True, skip_ipfs=True)
|
cached, ipfs_cid = self.cache.put(tmp_path, node_type="upload", move=True, skip_ipfs=False)
|
||||||
cid = cached.cid # Use local hash since we skipped IPFS
|
cid = ipfs_cid or cached.cid # Prefer IPFS CID, fall back to local hash
|
||||||
|
|
||||||
# Save to database with media category type
|
# Save to database with media category type
|
||||||
await self.db.create_cache_item(cid, ipfs_cid) # ipfs_cid is None initially
|
await self.db.create_cache_item(cached.cid, ipfs_cid)
|
||||||
await self.db.save_item_metadata(
|
await self.db.save_item_metadata(
|
||||||
cid=cid,
|
cid=cid,
|
||||||
actor_id=actor_id,
|
actor_id=actor_id,
|
||||||
@@ -568,13 +568,10 @@ class CacheService:
|
|||||||
filename=filename
|
filename=filename
|
||||||
)
|
)
|
||||||
|
|
||||||
# Queue background IPFS upload
|
if ipfs_cid:
|
||||||
try:
|
logger.info(f"Uploaded to IPFS: {ipfs_cid[:16]}...")
|
||||||
from tasks.ipfs_upload import upload_to_ipfs
|
else:
|
||||||
upload_to_ipfs.delay(cid, actor_id)
|
logger.warning(f"IPFS upload failed, using local hash: {cid[:16]}...")
|
||||||
logger.info(f"Queued background IPFS upload for {cid[:16]}...")
|
|
||||||
except Exception as e:
|
|
||||||
logger.warning(f"Failed to queue IPFS upload (will retry manually): {e}")
|
|
||||||
|
|
||||||
return cid, ipfs_cid, None
|
return cid, ipfs_cid, None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -422,3 +422,20 @@ def prim_audio_beat_count(analyzer: AudioAnalyzer, t: float) -> int:
|
|||||||
def prim_audio_duration(analyzer: AudioAnalyzer) -> float:
|
def prim_audio_duration(analyzer: AudioAnalyzer) -> float:
|
||||||
"""Get audio duration in seconds."""
|
"""Get audio duration in seconds."""
|
||||||
return analyzer.duration
|
return analyzer.duration
|
||||||
|
|
||||||
|
|
||||||
|
# Export primitives
|
||||||
|
PRIMITIVES = {
|
||||||
|
# Video source
|
||||||
|
'make-video-source': prim_make_video_source,
|
||||||
|
'source-read': prim_source_read,
|
||||||
|
'source-skip': prim_source_skip,
|
||||||
|
'source-size': prim_source_size,
|
||||||
|
|
||||||
|
# Audio analyzer
|
||||||
|
'make-audio-analyzer': prim_make_audio_analyzer,
|
||||||
|
'audio-energy': prim_audio_energy,
|
||||||
|
'audio-beat': prim_audio_beat,
|
||||||
|
'audio-beat-count': prim_audio_beat_count,
|
||||||
|
'audio-duration': prim_audio_duration,
|
||||||
|
}
|
||||||
|
|||||||
@@ -414,7 +414,6 @@ class StreamInterpreter:
|
|||||||
self._load_effect(resolved)
|
self._load_effect(resolved)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"Could not resolve include name '{fname}' - make sure it's uploaded and you're logged in")
|
raise RuntimeError(f"Could not resolve include name '{fname}' - make sure it's uploaded and you're logged in")
|
||||||
raise RuntimeError(f"Could not resolve include name '{fname}' - make sure it's uploaded and you're logged in")
|
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user