mirror of
https://github.com/alvierahman90/uploadr.git
synced 2025-01-12 02:04:20 +00:00
Formatting.
This commit is contained in:
parent
24d6babc73
commit
16af2b2424
59
uploadr.py
59
uploadr.py
@ -17,15 +17,18 @@ app.config['SECRET_KEY'] = os.urandom(24)
|
||||
encode = urllib.parse.quote
|
||||
decode = urllib.parse.unquote
|
||||
|
||||
|
||||
def check_create(dir):
|
||||
if not os.path.isdir(dir):
|
||||
os.makedirs(dir)
|
||||
|
||||
|
||||
check_create(config.uploads)
|
||||
check_create(config.qrcodes)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@app.route('/upload', methods=['GET','POST'])
|
||||
@app.route('/upload', methods=['GET', 'POST'])
|
||||
def upload_file():
|
||||
if request.method == 'POST':
|
||||
f = request.files['file']
|
||||
@ -34,42 +37,40 @@ def upload_file():
|
||||
file_dir = config.uploads + '/' + filename
|
||||
check_create(file_dir)
|
||||
check_create(file_dir + '/' + time_uploaded)
|
||||
f.save(config.uploads
|
||||
+ '/' + encode(filename)
|
||||
+ '/' + time_uploaded
|
||||
+ '/' + filename)
|
||||
f.save(config.uploads
|
||||
+ '/' + encode(filename)
|
||||
+ '/' + time_uploaded
|
||||
+ '/' + filename)
|
||||
return render_template('upload_success.html',
|
||||
link = filename + '?version=' + time_uploaded,
|
||||
port = config.port,
|
||||
)
|
||||
link=filename + '?version=' + time_uploaded,
|
||||
port=config.port,
|
||||
)
|
||||
else:
|
||||
return render_template('upload.html',
|
||||
port = config.port,
|
||||
)
|
||||
return render_template('upload.html', port=config.port)
|
||||
|
||||
|
||||
@app.route('/qrcodes/<filename>')
|
||||
def qrcodes(filename):
|
||||
link = 'http://{0}:{1}/download/{2}?version={3}'.format(
|
||||
config.domain
|
||||
, config.port
|
||||
, encode(filename)
|
||||
, request.args.get('version')
|
||||
config.domain, config.port, encode(filename),
|
||||
request.args.get('version')
|
||||
)
|
||||
image = qrcode.make(link)
|
||||
with open(config.qrcodes + '/' + filename+ '.png', mode = 'bw+') as file:
|
||||
with open(config.qrcodes + '/' + filename + '.png', mode='bw+') as file:
|
||||
image.save(file)
|
||||
return send_from_directory(config.qrcodes, filename + '.png', as_attachment=True)
|
||||
return send_from_directory(config.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}?version={3}'.format(
|
||||
config.domain
|
||||
, config.port
|
||||
, filename
|
||||
, request.args.get('version')
|
||||
)
|
||||
)
|
||||
return render_template('qr.html', imagesrc='http://{0}:{1}/qrcodes/{2}?'
|
||||
'version={3}'.format(
|
||||
config.domain, config.port, filename,
|
||||
request.args.get('version')
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@app.route('/download/<filename>')
|
||||
def download(filename=None):
|
||||
@ -80,18 +81,22 @@ def download(filename=None):
|
||||
existing_versions = glob.glob(directory_base + '*')
|
||||
existing_versions.sort()
|
||||
latest_version = existing_versions[-1]
|
||||
directory = latest_version
|
||||
directory = latest_version
|
||||
|
||||
return flask.send_from_directory(directory, decode(filename),
|
||||
as_attachment=True)
|
||||
|
||||
return flask.send_from_directory(directory, decode(filename), as_attachment=True)
|
||||
|
||||
@app.route('/css/<filename>')
|
||||
def css(filename=None):
|
||||
return flask.send_from_directory('css', filename)
|
||||
|
||||
|
||||
@app.route('/fonts/<filename>')
|
||||
def fonts(filename=None):
|
||||
return flask.send_from_directory('fonts', filename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.debug = True
|
||||
app.run()
|
||||
|
Loading…
Reference in New Issue
Block a user