Eddie
2 years ago
13 changed files with 11106 additions and 142 deletions
@ -0,0 +1,6 @@
|
||||
import qrcode, os |
||||
|
||||
def createQrCode(data, name): |
||||
img = qrcode.make(data) |
||||
type(img) |
||||
img.save(os.getcwd() + '/app/static/uploads/' + str(name) + '.png') |
File diff suppressed because it is too large
Load Diff
After Width: | Height: | Size: 955 B |
@ -1,11 +1,69 @@
|
||||
{% extends 'base.html' %} |
||||
|
||||
{% block header %} |
||||
<h1>{% block title %}Login Events{% endblock %}</h1> |
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> |
||||
<div class="container-fluid"> |
||||
<a href="{{ url_for('index') }}" class="navbar-brand" href="#">Eddsons Markdown Presenter</a> |
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarColor02" aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation"> |
||||
<span class="navbar-toggler-icon"></span> |
||||
</button> |
||||
<div class="collapse navbar-collapse" id="navbarColor02"> |
||||
<ul class="navbar-nav me-auto"> |
||||
|
||||
<li class="nav-item"> |
||||
<a type="button" href="{{ url_for('upload.upload_file') }}" class="btn btn-outline-light">Upload</a> |
||||
</li> |
||||
|
||||
</ul> |
||||
<form class="d-flex"> |
||||
{% if g.user %} |
||||
<a type="button" class="btn btn-outline-light">{{ g.user['username'] }}</a> |
||||
<a class="btn btn-secondary my-2 my-sm-0" href="{{ url_for('auth.logout') }}">Log Out</a> |
||||
{% else %} |
||||
<a class="btn btn-secondary my-2 my-sm-0" href="{{ url_for('auth.register') }}">Register</a> |
||||
<a class="btn btn-secondary my-2 my-sm-0" href="{{ url_for('auth.login') }}">Log In</a> |
||||
{% endif %} |
||||
</form> |
||||
</div> |
||||
</div> |
||||
</nav> |
||||
|
||||
<h1>{% block title %}Markdown Files{% endblock %}</h1> |
||||
|
||||
{% endblock %} |
||||
|
||||
{% block content %} |
||||
|
||||
<a>Hello World</a> |
||||
|
||||
|
||||
<table class="table table-secondary"> |
||||
<thead> |
||||
<tr> |
||||
<th scope="col">ID</th> |
||||
<th scope="col">Title</th> |
||||
<th scope="col">UUID</th> |
||||
<th scope="col">Created</th> |
||||
<th scope="col"></th> |
||||
<th scope="col"></th> |
||||
<th scope="col"></th> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
{% for file in mdFiles %} |
||||
<tr class="table-dark"> |
||||
<td>{{ file['id'] }}</td> |
||||
<td>{{ file['title'] }}</td> |
||||
<td>{{ file['uuid'] }}</td> |
||||
<td>{{ file['created'] }}</td> |
||||
<td><a type="button" href="{{ url_for('index.qrView', uuid=file['uuid']) }}" class="btn btn-primary">QR Code</a></td> |
||||
<td><a type="button" href="{{ url_for('index.viewfile', uuid=file['uuid']) }}" class="btn btn-primary">View</a></td> |
||||
<td><a type="button" href="{{ url_for('index.deletefile', uuid=file['uuid']) }}" class="btn btn-danger">Delete</a></td> |
||||
</tr> |
||||
{% endfor %} |
||||
</tbody> |
||||
</table> |
||||
|
||||
|
||||
|
||||
{% endblock %} |
@ -0,0 +1,8 @@
|
||||
{% extends 'base.html' %} |
||||
|
||||
{% block content %} |
||||
<div class="row row-cols-1 row-cols-md-3 g-4"> |
||||
<div class="col"></div> |
||||
<div class="col">{{ mdFile|markdown }}</div> |
||||
<div class="col"></div> |
||||
{% endblock %} |
@ -0,0 +1,8 @@
|
||||
{% extends 'base.html' %} |
||||
|
||||
{% block content %} |
||||
<div class="row row-cols-1 row-cols-md-3 g-4"> |
||||
<div class="col"></div> |
||||
<div class="col"><img src="{{ qr }}" alt="QR Code"></div> |
||||
<div class="col"></div> |
||||
{% endblock %} |
@ -0,0 +1,17 @@
|
||||
{% extends 'base.html' %} |
||||
|
||||
{% block header %} |
||||
<h1>{% block title %}Markdown Upload{% endblock %}</h1> |
||||
{% endblock %} |
||||
|
||||
{% block content %} |
||||
|
||||
<title>Upload</title> |
||||
<h1>Upload new File</h1> |
||||
<form method=post enctype=multipart/form-data> |
||||
<input type=file name=file> |
||||
<input type=submit value=Upload> |
||||
</form> |
||||
|
||||
|
||||
{% endblock %} |
@ -0,0 +1,66 @@
|
||||
import os, uuid |
||||
from flask import ( |
||||
Blueprint, flash, g, redirect, render_template, request, url_for, session |
||||
) |
||||
from app.auth import login_required |
||||
from app.db import get_db |
||||
from werkzeug.utils import secure_filename |
||||
|
||||
from app.qrCode import createQrCode |
||||
|
||||
|
||||
bp = Blueprint('upload', __name__, url_prefix='/upload') |
||||
|
||||
ALLOWED_EXTENSIONS = {'md'} |
||||
UPLOAD_FOLDER = os.getcwd() + '/app/static/uploads' |
||||
|
||||
@bp.route('/upload', methods=['GET', 'POST']) |
||||
@login_required |
||||
def upload_file(): |
||||
if request.method == 'POST': |
||||
# check if the post request has the file part |
||||
if 'file' not in request.files: |
||||
flash('No file part') |
||||
return redirect(request.url) |
||||
file = request.files['file'] |
||||
# If the user does not select a file, the browser submits an |
||||
# empty file without a filename. |
||||
if file.filename == '': |
||||
flash('No selected file') |
||||
return redirect(request.url) |
||||
if file and allowed_file(file.filename): |
||||
filename = secure_filename(file.filename) |
||||
path = os.path.join(UPLOAD_FOLDER, filename) |
||||
file.save(path) |
||||
createMarkdownEntry(path) |
||||
os.remove(path) |
||||
|
||||
return redirect(url_for('index')) |
||||
return render_template('upload.html') |
||||
|
||||
|
||||
|
||||
|
||||
def allowed_file(filename): |
||||
return '.' in filename and \ |
||||
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS |
||||
|
||||
|
||||
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()) |
||||
base_uri = request.url_root |
||||
qrData = base_uri + 'viewfile/' + uniqueID |
||||
createQrCode(qrData, uniqueID) |
||||
qrCode = qrData |
||||
db.execute( |
||||
'INSERT INTO markdownFile (title, body, qrCode, uuid, creator) VALUES (?, ?, ?, ?, ?)', |
||||
(title[0], data, qrCode, uniqueID, session['user_id']) |
||||
) |
||||
db.commit() |
||||
return |
Loading…
Reference in new issue