diff --git a/main.py b/main.py index cffe852..cd7b95a 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ import uvicorn import ffmpeg from pathlib import Path -from fastapi import FastAPI, UploadFile, Form, File, Header +from fastapi import FastAPI, UploadFile, Form, File, Header, HTTPException from fastapi.responses import StreamingResponse from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles @@ -37,9 +37,14 @@ async def upload_file(file: UploadFile = File(...)): return {'status': 200, 'id': video_name} -@app.get("/fetch/{id}") -async def fetch_file(id: str, range: str = Header(None)) -> StreamingResponse: - video_path = Path(os.path.join(ServerConfig.videos_play_path, id + '.mp4')) +@app.get("/fetch/{id}&location={location}") +async def fetch_file(id: str, location: str, range: str = Header(None)) -> StreamingResponse: + if location == "play": + video_path = Path(os.path.join(ServerConfig.videos_play_path, id + '.mp4')) + elif location == "upload": + video_path = Path(os.path.join(ServerConfig.videos_upload_path, id + '.mp4')) + else: + raise HTTPException(status_code=442, detail=f"location {location} is not defined!") video_size = video_path.stat().st_size start = 0 end = video_size - 1 @@ -135,7 +140,9 @@ async def generate_file(id: str = Form(...)): out.release() cap.release() - ffmpeg.input(target_video_path, format='mp4', vcodec='mpeg4').output(final_video_path, format='mp4', vcodec='h264').run() + ffmpeg.input(target_video_path, format='mp4', vcodec='mpeg4') \ + .output(final_video_path, format='mp4', vcodec='h264') \ + .run(overwrite_output=True) return {'status': 200, 'id': id} diff --git a/static/index.html b/static/index.html index 4fcbeaf..c5d517b 100644 --- a/static/index.html +++ b/static/index.html @@ -37,49 +37,49 @@ - - -