mirror of
https://github.com/alvierahman90/uploadr.git
synced 2025-01-12 02:04:20 +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>
|
||||
<h1>Upload success!</h1>
|
||||
<div class="indent">
|
||||
<p>File located at <a id="file_link" href=""><a>
|
||||
<script>
|
||||
|
||||
file = document.getElementById('file_link');
|
||||
file.setAttribute('href','/download/{{ filename }}');
|
||||
file.innerHTML = '/download/{{ filename }}';
|
||||
|
||||
</script>
|
||||
<p id="downloadLink" >File located at <a id="file_link" href="/download/{{ filename }}">/download/{{ filename }}<a>
|
||||
<p><a href="/qr/{{ filename }}"> QR Code link </a> </p>
|
||||
</div>
|
||||
</body>
|
||||
|
25
uploadr.py
25
uploadr.py
@ -1,11 +1,12 @@
|
||||
import time
|
||||
import flask
|
||||
import config
|
||||
import os
|
||||
import qrcode
|
||||
from flask import Flask
|
||||
from flask import render_template
|
||||
from flask import request
|
||||
from flask import send_from_directory
|
||||
from config import uploadr as config
|
||||
from werkzeug.utils import secure_filename
|
||||
app = Flask(__name__)
|
||||
app.config['SECRET_KEY'] = os.urandom(24)
|
||||
@ -31,6 +32,27 @@ def upload_file():
|
||||
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>')
|
||||
def download(filename=None):
|
||||
if filename != None:
|
||||
@ -38,7 +60,6 @@ def download(filename=None):
|
||||
else:
|
||||
return hello()
|
||||
|
||||
|
||||
@app.route('/css/<filename>')
|
||||
def css(filename=None):
|
||||
return flask.send_from_directory('css', filename)
|
||||
|
Loading…
Reference in New Issue
Block a user