Update storage/media_routers.py
Browse files- storage/media_routers.py +30 -0
storage/media_routers.py
CHANGED
|
@@ -25,6 +25,36 @@ def validate_token(token: str):
|
|
| 25 |
raise HTTPException(status_code=401, detail="Invalid token")
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
@router.post("/upload_cast_csv/{sha1}", tags=["Media Manager"])
|
| 29 |
async def upload_cast_csv(
|
| 30 |
sha1: str,
|
|
|
|
| 25 |
raise HTTPException(status_code=401, detail="Invalid token")
|
| 26 |
|
| 27 |
|
| 28 |
+
@router.delete("/clear_media", tags=["Media Manager"])
|
| 29 |
+
def clear_media(token: str = Query(..., description="Token required for authorization")):
|
| 30 |
+
"""
|
| 31 |
+
Delete all contents of the /data/media folder.
|
| 32 |
+
|
| 33 |
+
Steps:
|
| 34 |
+
- Validate the token.
|
| 35 |
+
- Ensure the folder exists.
|
| 36 |
+
- Delete all files and subfolders inside /data/media.
|
| 37 |
+
- Return a JSON response confirming the deletion.
|
| 38 |
+
|
| 39 |
+
Warning: This will remove all stored videos, clips, and cast CSV files.
|
| 40 |
+
"""
|
| 41 |
+
validate_token(token)
|
| 42 |
+
|
| 43 |
+
if not MEDIA_ROOT.exists() or not MEDIA_ROOT.is_dir():
|
| 44 |
+
raise HTTPException(status_code=404, detail="/data/media folder does not exist")
|
| 45 |
+
|
| 46 |
+
# Delete contents
|
| 47 |
+
for item in MEDIA_ROOT.iterdir():
|
| 48 |
+
try:
|
| 49 |
+
if item.is_dir():
|
| 50 |
+
shutil.rmtree(item)
|
| 51 |
+
else:
|
| 52 |
+
item.unlink()
|
| 53 |
+
except Exception as e:
|
| 54 |
+
raise HTTPException(status_code=500, detail=f"Failed to delete {item}: {e}")
|
| 55 |
+
|
| 56 |
+
return {"status": "ok", "message": "All media files deleted successfully"}
|
| 57 |
+
|
| 58 |
@router.post("/upload_cast_csv/{sha1}", tags=["Media Manager"])
|
| 59 |
async def upload_cast_csv(
|
| 60 |
sha1: str,
|