Commit ·
ae40e4a
1
Parent(s): ee1bf0a
Complete cloud storage: return cloud URL when HF upload successful, redirect download
Browse files
modules/story_reels/router.py
CHANGED
|
@@ -86,7 +86,21 @@ async def get_story_status(video_id: str):
|
|
| 86 |
}
|
| 87 |
)
|
| 88 |
async def download_story_reel(video_id: str):
|
| 89 |
-
"""Download/stream a story reel"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
video_path = story_creator.get_video_path(video_id)
|
| 91 |
|
| 92 |
if not video_path.exists():
|
|
|
|
| 86 |
}
|
| 87 |
)
|
| 88 |
async def download_story_reel(video_id: str):
|
| 89 |
+
"""Download/stream a story reel - supports both local and cloud storage"""
|
| 90 |
+
# Get job status to check storage type
|
| 91 |
+
status = story_creator.get_status(video_id)
|
| 92 |
+
|
| 93 |
+
if status.get("status") == "not_found":
|
| 94 |
+
raise HTTPException(status_code=404, detail="Video not found")
|
| 95 |
+
|
| 96 |
+
video_url = status.get("video_url")
|
| 97 |
+
|
| 98 |
+
# If video is in cloud (HF Hub), redirect to cloud URL
|
| 99 |
+
if video_url and video_url.startswith("https://"):
|
| 100 |
+
from fastapi.responses import RedirectResponse
|
| 101 |
+
return RedirectResponse(url=video_url, status_code=302)
|
| 102 |
+
|
| 103 |
+
# Otherwise serve from local storage
|
| 104 |
video_path = story_creator.get_video_path(video_id)
|
| 105 |
|
| 106 |
if not video_path.exists():
|
modules/video_creator/router.py
CHANGED
|
@@ -72,7 +72,18 @@ async def get_video_status(video_id: str):
|
|
| 72 |
}
|
| 73 |
)
|
| 74 |
async def get_video(video_id: str):
|
| 75 |
-
"""Download/stream a video"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
video_path = short_creator.get_video_path(video_id)
|
| 77 |
|
| 78 |
if not video_path.exists():
|
|
|
|
| 72 |
}
|
| 73 |
)
|
| 74 |
async def get_video(video_id: str):
|
| 75 |
+
"""Download/stream a video - supports both local and cloud storage"""
|
| 76 |
+
from config import config
|
| 77 |
+
|
| 78 |
+
# Check if video is in cloud (has .cloud metadata file)
|
| 79 |
+
cloud_meta_path = config.videos_dir_path / f"{video_id}.cloud"
|
| 80 |
+
if cloud_meta_path.exists():
|
| 81 |
+
cloud_url = cloud_meta_path.read_text().strip()
|
| 82 |
+
if cloud_url:
|
| 83 |
+
from fastapi.responses import RedirectResponse
|
| 84 |
+
return RedirectResponse(url=cloud_url, status_code=302)
|
| 85 |
+
|
| 86 |
+
# Otherwise serve from local storage
|
| 87 |
video_path = short_creator.get_video_path(video_id)
|
| 88 |
|
| 89 |
if not video_path.exists():
|
modules/video_creator/services/short_creator.py
CHANGED
|
@@ -339,8 +339,10 @@ class ShortCreator:
|
|
| 339 |
folder="short_video" # Module-specific folder
|
| 340 |
)
|
| 341 |
if cloud_url:
|
| 342 |
-
#
|
| 343 |
-
|
|
|
|
|
|
|
| 344 |
output_path.unlink()
|
| 345 |
logger.info(f"Video {video_id} uploaded to HF Hub, local file deleted")
|
| 346 |
except Exception as e:
|
|
|
|
| 339 |
folder="short_video" # Module-specific folder
|
| 340 |
)
|
| 341 |
if cloud_url:
|
| 342 |
+
# Save cloud URL to metadata file for download redirect
|
| 343 |
+
cloud_meta_path = self.config.videos_dir_path / f"{video_id}.cloud"
|
| 344 |
+
cloud_meta_path.write_text(cloud_url)
|
| 345 |
+
# Delete local video file to save space
|
| 346 |
output_path.unlink()
|
| 347 |
logger.info(f"Video {video_id} uploaded to HF Hub, local file deleted")
|
| 348 |
except Exception as e:
|