瀏覽代碼

html: video ready

Nikola Kotur 10 年之前
父節點
當前提交
b6c7495645
共有 3 個文件被更改,包括 26 次插入4 次删除
  1. 1 1
      conf/development.cfg
  2. 17 2
      phosic/routes.py
  3. 8 1
      templates/job-ready.html

+ 1 - 1
conf/development.cfg

@@ -33,5 +33,5 @@ CELERYBEAT_SCHEDULE = {
     },
 }
 
-PHOSIC_TASK_DELAY = 1
+PHOSIC_TASK_DELAY = 30
 PHOSIC_TASK_MAX_EXECUTION_TIME = 360

+ 17 - 2
phosic/routes.py

@@ -2,7 +2,7 @@ import os
 import datetime
 import logging
 
-from flask import render_template, redirect, url_for
+from flask import render_template, redirect, url_for, send_from_directory, abort
 from werkzeug import secure_filename
 
 from flask_app import app, db, models
@@ -54,7 +54,8 @@ def home():
 
     return render_template('home.html', form=form)
 
-@app.route('/jobs/<job_id>')
+@app.route('/jobs/<job_id>/')
+@app.route('/jobs/<job_id>/view')
 def jobs(job_id):
     """Render job page."""
     job = models.Job.query.filter_by(uniqid=job_id).first_or_404()
@@ -69,6 +70,20 @@ def jobs(job_id):
 
     return render_template('job-pending.html', job=job, started=True if job.state == models.JOB_STARTED else False)
 
+@app.route('/jobs/<job_id>/download')
+def download_file(job_id):
+    if '.' in job_id or job_id.startswith('/'):
+        abort(404)
+    job = models.Job.query.filter_by(uniqid=job_id).first_or_404()
+
+    if job.state != models.JOB_FINISHED:
+        abort(404)
+
+    video_file = job_id + "/" + job_id + ".mkv"
+    return send_from_directory(app.config['UPLOAD_FOLDER'], video_file,
+                               attachment_filename="phosic-video.mkv",
+                               as_attachment=True, mimetype='video/x-matroska')
+
 @app.route('/about/')
 def about():
     """Render about page."""

+ 8 - 1
templates/job-ready.html

@@ -4,7 +4,14 @@
 {% endblock %}
 
 {% block main %}
-job ready
+
+<p>Your video is ready!</p>
+
+<p>
+  <a href="{{ url_for('download_file', job_id=job.uniqid) }}" class="btn btn-lg btn-success">
+    <span class="glyphicon glyphicon-download"></span> Download video
+  </a>
+</p>
 
 {% if config["DEBUG"] %}
 {% include 'job-info.html' %}