Spaces:
Sleeping
Sleeping
Commit
·
afc9f44
1
Parent(s):
623e0d6
test patch
Browse files- app/proxy.py +33 -10
- app/templates/index.html +0 -1
app/proxy.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
-
from flask import Blueprint,
|
| 2 |
import os
|
| 3 |
import logging
|
| 4 |
|
| 5 |
logger = logging.getLogger(__name__)
|
| 6 |
proxy_bp = Blueprint('proxy', __name__)
|
| 7 |
|
|
|
|
|
|
|
| 8 |
@proxy_bp.route('/files/<path:filename>')
|
| 9 |
def serve_file(filename):
|
| 10 |
"""Serve files from the encoded directory"""
|
|
@@ -38,16 +40,37 @@ def serve_upload(filename):
|
|
| 38 |
def serve_video(job_id, quality):
|
| 39 |
"""Serve encoded video files"""
|
| 40 |
try:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
return send_from_directory(
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
mimetype='video/mp4'
|
|
|
|
|
|
|
| 48 |
)
|
| 49 |
else:
|
| 50 |
-
return {
|
|
|
|
|
|
|
|
|
|
| 51 |
except Exception as e:
|
| 52 |
-
logger.error(f"
|
| 53 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Blueprint, request, jsonify, current_app, render_template, send_from_directory
|
| 2 |
import os
|
| 3 |
import logging
|
| 4 |
|
| 5 |
logger = logging.getLogger(__name__)
|
| 6 |
proxy_bp = Blueprint('proxy', __name__)
|
| 7 |
|
| 8 |
+
from app.services.encoder_service import encoder_service
|
| 9 |
+
|
| 10 |
@proxy_bp.route('/files/<path:filename>')
|
| 11 |
def serve_file(filename):
|
| 12 |
"""Serve files from the encoded directory"""
|
|
|
|
| 40 |
def serve_video(job_id, quality):
|
| 41 |
"""Serve encoded video files"""
|
| 42 |
try:
|
| 43 |
+
job_info = encoder_service.get_job_info(job_id)
|
| 44 |
+
if not job_info:
|
| 45 |
+
return jsonify({
|
| 46 |
+
'error': True,
|
| 47 |
+
'message': 'Job not found'
|
| 48 |
+
}), 404
|
| 49 |
+
|
| 50 |
+
# Retrieve the video file path based on quality from the job info
|
| 51 |
+
video_file_path = None
|
| 52 |
+
for file in job_info.get('files', []):
|
| 53 |
+
if file['quality'] == quality:
|
| 54 |
+
video_file_path = file['path']
|
| 55 |
+
break
|
| 56 |
+
|
| 57 |
+
if video_file_path and os.path.exists(video_file_path):
|
| 58 |
+
directory, video_filename = os.path.split(video_file_path)
|
| 59 |
return send_from_directory(
|
| 60 |
+
directory,
|
| 61 |
+
video_filename,
|
| 62 |
+
mimetype='video/mp4',
|
| 63 |
+
as_attachment=True,
|
| 64 |
+
download_name=video_filename
|
| 65 |
)
|
| 66 |
else:
|
| 67 |
+
return jsonify({
|
| 68 |
+
'error': True,
|
| 69 |
+
'message': 'Video not found'
|
| 70 |
+
}), 404
|
| 71 |
except Exception as e:
|
| 72 |
+
logger.error(f"Failed to serve video: {str(e)}")
|
| 73 |
+
return jsonify({
|
| 74 |
+
'error': True,
|
| 75 |
+
'message': 'Failed to serve video'
|
| 76 |
+
}), 500
|
app/templates/index.html
CHANGED
|
@@ -227,7 +227,6 @@
|
|
| 227 |
xhr.onload = function() {
|
| 228 |
if (xhr.status === 202) {
|
| 229 |
const response = JSON.parse(xhr.responseText);
|
| 230 |
-
alert('Upload successful! Job ID: ' + response.job_id);
|
| 231 |
uploadForm.reset();
|
| 232 |
fileInfo.classList.add('hidden');
|
| 233 |
fetchJobs();
|
|
|
|
| 227 |
xhr.onload = function() {
|
| 228 |
if (xhr.status === 202) {
|
| 229 |
const response = JSON.parse(xhr.responseText);
|
|
|
|
| 230 |
uploadForm.reset();
|
| 231 |
fileInfo.classList.add('hidden');
|
| 232 |
fetchJobs();
|