Implement local server file browsing and selection to bypass client uploads

This commit is contained in:
2026-07-01 10:53:19 -04:00
parent 377e7df297
commit 969af7284e
3 changed files with 403 additions and 47 deletions
+93 -37
View File
@@ -261,7 +261,8 @@ worker_thread.start()
class StartUpscaleRequest(BaseModel):
file_id: str
file_id: str | None = None
server_file_path: str | None = None
model: str = "realesr-animevideov3"
scale: int = 4
tile_size: int = 256
@@ -290,7 +291,9 @@ class StartUpscaleRequest(BaseModel):
output_dir: str | None = None
class StartBatchUpscaleRequest(BaseModel):
file_ids: List[str]
file_ids: List[str] | None = None
server_file_paths: List[str] | None = None
model: str = "realesr-animevideov3"
scale: int = 4
tile_size: int = 256
@@ -319,7 +322,8 @@ class StartBatchUpscaleRequest(BaseModel):
output_dir: str | None = None
class PreviewRequest(BaseModel):
file_id: str
file_id: str | None = None
server_file_path: str | None = None
timestamp_sec: float = 1.0
model: str = "realesr-animevideov3"
scale: int = 4
@@ -327,6 +331,7 @@ class PreviewRequest(BaseModel):
gpu_ids: str | None = None
# Endpoints
UPLOAD_METADATA_FILE = os.path.join(upscaler.UPLOAD_DIR, "metadata.json")
@@ -467,22 +472,31 @@ def start_upscale(req: StartUpscaleRequest):
"""Queue upscaling task"""
# Find uploaded file
file_path = None
exts = [".mp4", ".mkv", ".avi", ".mov", ".webm"]
for ext in exts:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{req.file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
if req.server_file_path:
if os.path.exists(req.server_file_path) and os.path.isfile(req.server_file_path):
file_path = req.server_file_path
else:
raise HTTPException(status_code=404, detail="Server file path not found.")
else:
if not req.file_id:
raise HTTPException(status_code=400, detail="Either file_id or server_file_path must be provided.")
exts = [".mp4", ".mkv", ".avi", ".mov", ".webm"]
for ext in exts:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{req.file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
if not file_path:
raise HTTPException(status_code=404, detail="Uploaded file not found.")
metadata = load_upload_metadata()
source_filename = None
if req.file_id in metadata:
if req.file_id and req.file_id in metadata:
source_filename = metadata[req.file_id].get("original_filename")
if not source_filename and file_path:
source_filename = os.path.basename(file_path)
settings = load_settings()
output_dir = req.output_dir or settings.get("default_output_dir") or None
@@ -545,17 +559,27 @@ def start_upscale_batch(req: StartBatchUpscaleRequest):
"""Queue multiple upscaling tasks with one set of settings"""
queued_jobs = []
# 1. Validation loop
for file_id in req.file_ids:
file_path = None
exts = [".mp4", ".mkv", ".avi", ".mov", ".webm"]
for ext in exts:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
if not file_path:
raise HTTPException(status_code=404, detail=f"Uploaded file {file_id} not found.")
file_sources = [] # list of (file_id, file_path)
if req.server_file_paths:
for path in req.server_file_paths:
if os.path.exists(path) and os.path.isfile(path):
file_sources.append((None, path))
else:
raise HTTPException(status_code=404, detail=f"Server file {path} not found.")
else:
if not req.file_ids:
raise HTTPException(status_code=400, detail="Either file_ids or server_file_paths must be provided.")
for file_id in req.file_ids:
file_path = None
exts = [".mp4", ".mkv", ".avi", ".mov", ".webm"]
for ext in exts:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
if not file_path:
raise HTTPException(status_code=404, detail=f"Uploaded file {file_id} not found.")
file_sources.append((file_id, file_path))
settings = load_settings()
output_dir = req.output_dir or settings.get("default_output_dir") or None
@@ -563,20 +587,14 @@ def start_upscale_batch(req: StartBatchUpscaleRequest):
output_dir = output_dir.strip()
# 2. Queueing loop
for file_id in req.file_ids:
file_path = None
for ext in [".mp4", ".mkv", ".avi", ".mov", ".webm"]:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
for file_id, file_path in file_sources:
metadata = load_upload_metadata()
source_filename = None
if file_id in metadata:
if file_id and file_id in metadata:
source_filename = metadata[file_id].get("original_filename")
if not source_filename and file_path:
source_filename = os.path.basename(file_path)
job_id = str(uuid.uuid4())
job = upscaler.UpscaleJob(
@@ -674,15 +692,24 @@ def cancel_job(job_id: str):
async def generate_preview(req: PreviewRequest):
"""Generate high quality upscaled single frame preview"""
file_path = None
exts = [".mp4", ".mkv", ".avi", ".mov", ".webm"]
for ext in exts:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{req.file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
if req.server_file_path:
if os.path.exists(req.server_file_path) and os.path.isfile(req.server_file_path):
file_path = req.server_file_path
else:
raise HTTPException(status_code=404, detail="Server file path not found.")
else:
if not req.file_id:
raise HTTPException(status_code=400, detail="Either file_id or server_file_path must be provided.")
exts = [".mp4", ".mkv", ".avi", ".mov", ".webm"]
for ext in exts:
test_path = os.path.join(upscaler.UPLOAD_DIR, f"{req.file_id}{ext}")
if os.path.exists(test_path):
file_path = test_path
break
if not file_path:
raise HTTPException(status_code=404, detail="Video file not found.")
preview_id = str(uuid.uuid4())
preview_temp_dir = os.path.join(upscaler.TEMP_DIR, f"preview_{preview_id}")
@@ -1414,7 +1441,7 @@ class CreateDirRequest(BaseModel):
name: str
@app.get("/api/system/browse-dir")
def browse_dir(path: str = ""):
def browse_dir(path: str = "", show_files: bool = False):
"""Browse directories on the system"""
if not path:
path = os.path.expanduser("~")
@@ -1438,6 +1465,8 @@ def browse_dir(path: str = ""):
"is_dir": True
})
video_extensions = {'.mp4', '.mkv', '.avi', '.mov', '.webm', '.flv', '.m4v', '.wmv', '.mpg', '.mpeg'}
for name in sorted(os.listdir(path)):
full_path = os.path.join(path, name)
try:
@@ -1447,6 +1476,14 @@ def browse_dir(path: str = ""):
"path": full_path,
"is_dir": True
})
elif show_files:
_, ext = os.path.splitext(name.lower())
if ext in video_extensions:
entries.append({
"name": name,
"path": full_path,
"is_dir": False
})
except PermissionError:
continue
@@ -1457,6 +1494,25 @@ def browse_dir(path: str = ""):
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.get("/api/system/file-metadata")
def get_file_metadata(path: str):
"""Get video metadata for a local server file"""
if not os.path.exists(path) or not os.path.isfile(path):
raise HTTPException(status_code=404, detail="File not found.")
info = upscaler.get_video_info(path)
if not info:
raise HTTPException(status_code=400, detail="Could not read video file metadata.")
return {
"original_filename": os.path.basename(path),
"path": path,
"size_bytes": os.path.getsize(path),
"metadata": info
}
@app.post("/api/system/create-dir")
def create_dir(req: CreateDirRequest):
"""Create a new directory"""