mirror of
https://github.com/PhoenixTwoFive/karaoqueue.git
synced 2025-05-19 11:01:47 +02:00
Fix overly agressive caching
This commit is contained in:
parent
013dcecba9
commit
65635f57a8
@ -3,6 +3,9 @@ from bs4 import BeautifulSoup
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
from flask import make_response
|
||||||
|
from functools import wraps, update_wrapper
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
data_directory = "data"
|
data_directory = "data"
|
||||||
config_file = data_directory+"/config.json"
|
config_file = data_directory+"/config.json"
|
||||||
@ -57,4 +60,18 @@ def setup_config(app):
|
|||||||
app.config['BASIC_AUTH_USERNAME'] = config['username']
|
app.config['BASIC_AUTH_USERNAME'] = config['username']
|
||||||
app.config['BASIC_AUTH_PASSWORD'] = config['password']
|
app.config['BASIC_AUTH_PASSWORD'] = config['password']
|
||||||
app.config['ENTRY_QUOTA'] = config['entryquota']
|
app.config['ENTRY_QUOTA'] = config['entryquota']
|
||||||
app.config['MAX_QUEUE'] = config['maxqueue']
|
app.config['MAX_QUEUE'] = config['maxqueue']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def nocache(view):
|
||||||
|
@wraps(view)
|
||||||
|
def no_cache(*args, **kwargs):
|
||||||
|
response = make_response(view(*args, **kwargs))
|
||||||
|
response.headers['Last-Modified'] = datetime.now()
|
||||||
|
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
|
||||||
|
response.headers['Pragma'] = 'no-cache'
|
||||||
|
response.headers['Expires'] = '-1'
|
||||||
|
return response
|
||||||
|
|
||||||
|
return update_wrapper(no_cache, view)
|
@ -3,15 +3,14 @@ import helpers
|
|||||||
import database
|
import database
|
||||||
import data_adapters
|
import data_adapters
|
||||||
import os
|
import os
|
||||||
import errno
|
|
||||||
import json
|
import json
|
||||||
from flask_basicauth import BasicAuth
|
from flask_basicauth import BasicAuth
|
||||||
|
from helpers import nocache
|
||||||
app = Flask(__name__, static_url_path='/static')
|
app = Flask(__name__, static_url_path='/static')
|
||||||
|
|
||||||
basic_auth = BasicAuth(app)
|
basic_auth = BasicAuth(app)
|
||||||
accept_entries = False
|
accept_entries = False
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def home():
|
def home():
|
||||||
if basic_auth.authenticate():
|
if basic_auth.authenticate():
|
||||||
@ -27,6 +26,7 @@ def favicon():
|
|||||||
|
|
||||||
|
|
||||||
@app.route('/api/enqueue', methods=['POST'])
|
@app.route('/api/enqueue', methods=['POST'])
|
||||||
|
@nocache
|
||||||
def enqueue():
|
def enqueue():
|
||||||
if not request.json:
|
if not request.json:
|
||||||
print(request.data)
|
print(request.data)
|
||||||
@ -69,12 +69,14 @@ def songlist():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/settings")
|
@app.route("/settings")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def settings():
|
def settings():
|
||||||
return render_template('settings.html', app=app, auth=basic_auth.authenticate())
|
return render_template('settings.html', app=app, auth=basic_auth.authenticate())
|
||||||
|
|
||||||
|
|
||||||
@app.route("/settings", methods=['POST'])
|
@app.route("/settings", methods=['POST'])
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def settings_post():
|
def settings_post():
|
||||||
entryquota = request.form.get("entryquota")
|
entryquota = request.form.get("entryquota")
|
||||||
@ -92,24 +94,28 @@ def settings_post():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/queue")
|
@app.route("/api/queue")
|
||||||
|
@nocache
|
||||||
def queue_json():
|
def queue_json():
|
||||||
list = data_adapters.dict_from_rows(database.get_list())
|
list = data_adapters.dict_from_rows(database.get_list())
|
||||||
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/plays")
|
@app.route("/plays")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def played_list():
|
def played_list():
|
||||||
return render_template('played_list.html', list=database.get_played_list(), auth=basic_auth.authenticate())
|
return render_template('played_list.html', list=database.get_played_list(), auth=basic_auth.authenticate())
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/songs")
|
@app.route("/api/songs")
|
||||||
|
@nocache
|
||||||
def songs():
|
def songs():
|
||||||
list = database.get_song_list()
|
list = database.get_song_list()
|
||||||
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
return Response(json.dumps(list, ensure_ascii=False).encode('utf-8'), mimetype='text/json')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/songs/update")
|
@app.route("/api/songs/update")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def update_songs():
|
def update_songs():
|
||||||
database.delete_all_entries()
|
database.delete_all_entries()
|
||||||
@ -120,6 +126,7 @@ def update_songs():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/songs/compl")
|
@app.route("/api/songs/compl")
|
||||||
|
@nocache
|
||||||
def get_song_completions(input_string=""):
|
def get_song_completions(input_string=""):
|
||||||
input_string = request.args.get('search', input_string)
|
input_string = request.args.get('search', input_string)
|
||||||
if input_string != "":
|
if input_string != "":
|
||||||
@ -132,6 +139,7 @@ def get_song_completions(input_string=""):
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/entries/delete/<entry_id>")
|
@app.route("/api/entries/delete/<entry_id>")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def delete_entry(entry_id):
|
def delete_entry(entry_id):
|
||||||
if database.delete_entry(entry_id):
|
if database.delete_entry(entry_id):
|
||||||
@ -141,6 +149,7 @@ def delete_entry(entry_id):
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/entries/delete", methods=['POST'])
|
@app.route("/api/entries/delete", methods=['POST'])
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def delete_entries():
|
def delete_entries():
|
||||||
if not request.json:
|
if not request.json:
|
||||||
@ -155,6 +164,7 @@ def delete_entries():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/entries/mark_sung/<entry_id>")
|
@app.route("/api/entries/mark_sung/<entry_id>")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def mark_sung(entry_id):
|
def mark_sung(entry_id):
|
||||||
if database.add_sung_song(entry_id):
|
if database.add_sung_song(entry_id):
|
||||||
@ -164,6 +174,7 @@ def mark_sung(entry_id):
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/entries/accept/<value>")
|
@app.route("/api/entries/accept/<value>")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def set_accept_entries(value):
|
def set_accept_entries(value):
|
||||||
global accept_entries
|
global accept_entries
|
||||||
@ -175,12 +186,14 @@ def set_accept_entries(value):
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/entries/accept")
|
@app.route("/api/entries/accept")
|
||||||
|
@nocache
|
||||||
def get_accept_entries():
|
def get_accept_entries():
|
||||||
global accept_entries
|
global accept_entries
|
||||||
return Response('{"status": "OK", "value": '+str(int(accept_entries))+'}', mimetype='text/json')
|
return Response('{"status": "OK", "value": '+str(int(accept_entries))+'}', mimetype='text/json')
|
||||||
|
|
||||||
|
|
||||||
@app.route("/api/played/clear")
|
@app.route("/api/played/clear")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def clear_played_songs():
|
def clear_played_songs():
|
||||||
if database.clear_played_songs():
|
if database.clear_played_songs():
|
||||||
@ -190,6 +203,7 @@ def clear_played_songs():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/api/entries/delete_all")
|
@app.route("/api/entries/delete_all")
|
||||||
|
@nocache
|
||||||
@basic_auth.required
|
@basic_auth.required
|
||||||
def delete_all_entries():
|
def delete_all_entries():
|
||||||
if database.delete_all_entries():
|
if database.delete_all_entries():
|
||||||
@ -223,7 +237,8 @@ def add_header(response):
|
|||||||
Add headers to both force latest IE rendering engine or Chrome Frame,
|
Add headers to both force latest IE rendering engine or Chrome Frame,
|
||||||
and also to cache the rendered page for 10 minutes.
|
and also to cache the rendered page for 10 minutes.
|
||||||
"""
|
"""
|
||||||
response.headers['Cache-Control'] = 'private, max-age=600'
|
if not 'Cache-Control' in response.headers:
|
||||||
|
response.headers['Cache-Control'] = 'private, max-age=600'
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user