Browse Source

Markdown Upload Done

master
Eddie 2 years ago
parent
commit
10713bda91
  1. 1
      app/db.py
  2. 35
      app/index.py
  3. 5
      app/schema.sql

1
app/db.py

@ -29,6 +29,7 @@ def init_db():
db.executescript(f.read().decode('utf8'))
@click.command('init-db')
@with_appcontext
def init_db_command():

35
app/index.py

@ -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

5
app/schema.sql

@ -7,10 +7,11 @@ CREATE TABLE user (
password TEXT NOT NULL
);
CREATE TABLE MarkdownFile (
CREATE TABLE markdownFile (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
body TEXT NOT NULL,
qrCode TEXT NOT NULL,
uuid TEXT NOT NULL
uuid TEXT NOT NULL,
creator INTEGER NOT NULL
);
Loading…
Cancel
Save