mirror of
https://github.com/alvierahman90/uploadr.git
synced 2025-05-07 22:36:11 +00:00
Add QR code generator, remove unneccesary javascript from upload_success.html
This commit is contained in:
parent
aed5f9390d
commit
12c2dfb4be
4
templates/qr.html
Normal file
4
templates/qr.html
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<body style="background-color: black">
|
||||||
|
<img src="{{ imagesrc }}" />
|
||||||
|
</body>
|
@ -5,13 +5,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Upload success!</h1>
|
<h1>Upload success!</h1>
|
||||||
<div class="indent">
|
<div class="indent">
|
||||||
<p>File located at <a id="file_link" href=""><a>
|
<p id="downloadLink" >File located at <a id="file_link" href="/download/{{ filename }}">/download/{{ filename }}<a>
|
||||||
<script>
|
<p><a href="/qr/{{ filename }}"> QR Code link </a> </p>
|
||||||
|
|
||||||
file = document.getElementById('file_link');
|
|
||||||
file.setAttribute('href','/download/{{ filename }}');
|
|
||||||
file.innerHTML = '/download/{{ filename }}';
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
25
uploadr.py
25
uploadr.py
@ -1,11 +1,12 @@
|
|||||||
import time
|
import time
|
||||||
import flask
|
import flask
|
||||||
import config
|
|
||||||
import os
|
import os
|
||||||
|
import qrcode
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import send_from_directory
|
from flask import send_from_directory
|
||||||
|
from config import uploadr as config
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SECRET_KEY'] = os.urandom(24)
|
app.config['SECRET_KEY'] = os.urandom(24)
|
||||||
@ -31,6 +32,27 @@ def upload_file():
|
|||||||
port = config.port,
|
port = config.port,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.route('/qrcodes/<filename>')
|
||||||
|
def qrcodes(filename):
|
||||||
|
link = 'http://{0}:{1}/download/{2}'.format(
|
||||||
|
config.domain
|
||||||
|
, config.port
|
||||||
|
, filename
|
||||||
|
)
|
||||||
|
image = qrcode.make(link)
|
||||||
|
with open('qrcodes/' + filename+ '.png', mode = 'bw+') as file:
|
||||||
|
image.save(file)
|
||||||
|
return send_from_directory('qrcodes', filename + '.png', as_attachment=True)
|
||||||
|
|
||||||
|
@app.route('/qr/<filename>')
|
||||||
|
def qr(filename=None):
|
||||||
|
return render_template('qr.html', imagesrc = 'http://{0}:{1}/qrcodes/{2}'.format(
|
||||||
|
config.domain
|
||||||
|
, config.port
|
||||||
|
, filename
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@app.route('/download/<filename>')
|
@app.route('/download/<filename>')
|
||||||
def download(filename=None):
|
def download(filename=None):
|
||||||
if filename != None:
|
if filename != None:
|
||||||
@ -38,7 +60,6 @@ def download(filename=None):
|
|||||||
else:
|
else:
|
||||||
return hello()
|
return hello()
|
||||||
|
|
||||||
|
|
||||||
@app.route('/css/<filename>')
|
@app.route('/css/<filename>')
|
||||||
def css(filename=None):
|
def css(filename=None):
|
||||||
return flask.send_from_directory('css', filename)
|
return flask.send_from_directory('css', filename)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user