Add cache for non-item content

This commit is contained in:
Tim Van Baak 2020-08-11 22:01:24 -07:00
parent 814de5f094
commit 78c3f44735
3 changed files with 13 additions and 3 deletions

3
.gitignore vendored
View File

@ -126,6 +126,7 @@ dmypy.json
# Praw files # Praw files
praw.ini praw.ini
# Inquisitor scratch directory # Inquisitor directories
dungeon/ dungeon/
cache/

View File

@ -4,10 +4,10 @@ import os
import traceback import traceback
# Third party imports # Third party imports
from flask import Flask, render_template, request, jsonify from flask import Flask, render_template, request, jsonify, abort
# Application imports # Application imports
from inquisitor.configs import logger, DUNGEON_PATH from inquisitor.configs import logger, DUNGEON_PATH, CACHE_PATH
from inquisitor import sources, loader, timestamp from inquisitor import sources, loader, timestamp
# Globals # Globals
@ -145,3 +145,11 @@ def callback():
logger.error("Bad request params: {}".format(params)) logger.error("Bad request params: {}".format(params))
sources.item_callback(params['source'], params['itemid']) sources.item_callback(params['source'], params['itemid'])
return jsonify({}) return jsonify({})
@app.route('/cache/<path:cache_path>')
def cache(cache_path):
path = os.path.join(CACHE_PATH, cache_path)
if not os.path.isfile(path):
return abort(404)
with open(path, 'rb') as f:
return f.read()

View File

@ -3,6 +3,7 @@ import logging
DUNGEON_PATH = os.path.abspath(os.environ.get("INQUISITOR_DUNGEON") or "./dungeon") DUNGEON_PATH = os.path.abspath(os.environ.get("INQUISITOR_DUNGEON") or "./dungeon")
SOURCES_PATH = os.path.abspath(os.environ.get("INQUISITOR_SOURCES") or "./sources") SOURCES_PATH = os.path.abspath(os.environ.get("INQUISITOR_SOURCES") or "./sources")
CACHE_PATH = os.path.abspath(os.environ.get("INQUISITOR_CACHE") or "./cache")
logger = logging.getLogger("inquisitor") logger = logging.getLogger("inquisitor")
handler = logging.StreamHandler() handler = logging.StreamHandler()