|
|
@ -1,6 +1,6 @@ |
|
|
|
import os |
|
|
|
import os, uuid |
|
|
|
from flask import ( |
|
|
|
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 |
|
|
|
from werkzeug.exceptions import abort |
|
|
|
|
|
|
|
|
|
|
@ -17,12 +17,7 @@ bp = Blueprint('index', __name__) |
|
|
|
@login_required |
|
|
|
@login_required |
|
|
|
def index(): |
|
|
|
def index(): |
|
|
|
db = get_db() |
|
|
|
db = get_db() |
|
|
|
loginEvents = db.execute( |
|
|
|
return render_template('index.html') |
|
|
|
'SELECT *' |
|
|
|
|
|
|
|
' FROM loginEvent' |
|
|
|
|
|
|
|
' ORDER BY created DESC' |
|
|
|
|
|
|
|
).fetchall() |
|
|
|
|
|
|
|
return render_template('index.html', loginEvents = loginEvents) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def allowed_file(filename): |
|
|
|
def allowed_file(filename): |
|
|
@ -30,6 +25,7 @@ def allowed_file(filename): |
|
|
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS |
|
|
|
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS |
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/upload', methods=['GET', 'POST']) |
|
|
|
@bp.route('/upload', methods=['GET', 'POST']) |
|
|
|
|
|
|
|
@login_required |
|
|
|
def upload_file(): |
|
|
|
def upload_file(): |
|
|
|
if request.method == 'POST': |
|
|
|
if request.method == 'POST': |
|
|
|
# check if the post request has the file part |
|
|
|
# check if the post request has the file part |
|
|
@ -44,7 +40,11 @@ def upload_file(): |
|
|
|
return redirect(request.url) |
|
|
|
return redirect(request.url) |
|
|
|
if file and allowed_file(file.filename): |
|
|
|
if file and allowed_file(file.filename): |
|
|
|
filename = secure_filename(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 redirect(url_for('index')) |
|
|
|
return ''' |
|
|
|
return ''' |
|
|
|
<!doctype html> |
|
|
|
<!doctype html> |
|
|
@ -55,3 +55,20 @@ def upload_file(): |
|
|
|
<input type=submit value=Upload> |
|
|
|
<input type=submit value=Upload> |
|
|
|
</form> |
|
|
|
</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 |