|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import os |
|
|
|
|
import os, uuid |
|
|
|
|
from flask import ( |
|
|
|
|
Blueprint, flash, g, redirect, render_template, request, url_for |
|
|
|
|
Blueprint, flash, g, redirect, render_template, request, url_for, session |
|
|
|
|
) |
|
|
|
|
from werkzeug.exceptions import abort |
|
|
|
|
|
|
|
|
@ -17,12 +17,7 @@ bp = Blueprint('index', __name__)
|
|
|
|
|
@login_required |
|
|
|
|
def index(): |
|
|
|
|
db = get_db() |
|
|
|
|
loginEvents = db.execute( |
|
|
|
|
'SELECT *' |
|
|
|
|
' FROM loginEvent' |
|
|
|
|
' ORDER BY created DESC' |
|
|
|
|
).fetchall() |
|
|
|
|
return render_template('index.html', loginEvents = loginEvents) |
|
|
|
|
return render_template('index.html') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def allowed_file(filename): |
|
|
|
@ -30,6 +25,7 @@ def allowed_file(filename):
|
|
|
|
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS |
|
|
|
|
|
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST']) |
|
|
|
|
@login_required |
|
|
|
|
def upload_file(): |
|
|
|
|
if request.method == 'POST': |
|
|
|
|
# check if the post request has the file part |
|
|
|
@ -44,7 +40,11 @@ def upload_file():
|
|
|
|
|
return redirect(request.url) |
|
|
|
|
if file and allowed_file(file.filename): |
|
|
|
|
filename = secure_filename(file.filename) |
|
|
|
|
file.save(os.path.join(UPLOAD_FOLDER, filename)) |
|
|
|
|
path = os.path.join(UPLOAD_FOLDER, filename) |
|
|
|
|
file.save(path) |
|
|
|
|
createMarkdownEntry(path) |
|
|
|
|
os.remove(path) |
|
|
|
|
|
|
|
|
|
return redirect(url_for('index')) |
|
|
|
|
return ''' |
|
|
|
|
<!doctype html> |
|
|
|
@ -55,3 +55,20 @@ def upload_file():
|
|
|
|
|
<input type=submit value=Upload> |
|
|
|
|
</form> |
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createMarkdownEntry(path): |
|
|
|
|
db = get_db() |
|
|
|
|
title = os.path.basename(path) |
|
|
|
|
title = title.split('.') |
|
|
|
|
file = open(path) |
|
|
|
|
data = file.read() |
|
|
|
|
file.close() |
|
|
|
|
uniqueID = str(uuid.uuid4()) |
|
|
|
|
qrCode = 'QR' |
|
|
|
|
db.execute( |
|
|
|
|
'INSERT INTO markdownFile (title, body, qrCode, uuid, creator) VALUES (?, ?, ?, ?, ?)', |
|
|
|
|
(title[0], data, qrCode, uniqueID, session['user_id']) |
|
|
|
|
) |
|
|
|
|
db.commit() |
|
|
|
|
return |