mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-12-15 21:21:56 +01:00
Add entry deletion, footer
This commit is contained in:
30
main.py
30
main.py
@@ -1,12 +1,22 @@
|
||||
from flask import Flask, render_template, Response, abort, request
|
||||
from flask import Flask, render_template, Response, abort, request, redirect
|
||||
import helpers
|
||||
import database
|
||||
import os, errno
|
||||
import json
|
||||
from flask_basicauth import BasicAuth
|
||||
app = Flask(__name__, static_url_path='/static')
|
||||
|
||||
app.config['BASIC_AUTH_USERNAME'] = 'admin'
|
||||
app.config['BASIC_AUTH_PASSWORD'] = 'Karaoke2019blubb'
|
||||
|
||||
basic_auth = BasicAuth(app)
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return render_template('main.html', list=database.get_list())
|
||||
if basic_auth.authenticate():
|
||||
return render_template('main_admin.html', list=database.get_list(), auth=basic_auth.authenticate())
|
||||
else:
|
||||
return render_template('main.html', list=database.get_list(), auth=basic_auth.authenticate())
|
||||
|
||||
@app.route('/api/enqueue', methods=['POST'])
|
||||
def enqueue():
|
||||
@@ -20,7 +30,7 @@ def enqueue():
|
||||
|
||||
@app.route("/list")
|
||||
def songlist():
|
||||
return render_template('songlist.html', list=database.get_song_list())
|
||||
return render_template('songlist.html', list=database.get_song_list(), auth=basic_auth.authenticate())
|
||||
|
||||
@app.route("/api/songs")
|
||||
def songs():
|
||||
@@ -33,6 +43,20 @@ def get_song_completions(input_string):
|
||||
list = database.get_song_completions(input_string=input_string)
|
||||
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
||||
|
||||
|
||||
@app.route("/api/entries/delete/<entry_id>")
|
||||
@basic_auth.required
|
||||
def delete_entry(entry_id):
|
||||
if database.delete_entry(entry_id):
|
||||
return Response({"status": "OK"}, mimetype='text/json')
|
||||
else:
|
||||
return Response({"status": "FAIL"}, mimetype='text/json')
|
||||
|
||||
@app.route("/login")
|
||||
@basic_auth.required
|
||||
def admin():
|
||||
return redirect("/")
|
||||
|
||||
if __name__ == "__main__":
|
||||
"""try:
|
||||
os.remove("test.db")
|
||||
|
||||
Reference in New Issue
Block a user