From 78c3f44735659ce17322a540f346a1c0656c5ebb Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Tue, 11 Aug 2020 22:01:24 -0700 Subject: [PATCH] Add cache for non-item content --- .gitignore | 3 ++- inquisitor/app.py | 12 ++++++++++-- inquisitor/configs.py | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 887b05f..859bb6e 100644 --- a/.gitignore +++ b/.gitignore @@ -126,6 +126,7 @@ dmypy.json # Praw files praw.ini -# Inquisitor scratch directory +# Inquisitor directories dungeon/ +cache/ diff --git a/inquisitor/app.py b/inquisitor/app.py index e33da13..40d7925 100644 --- a/inquisitor/app.py +++ b/inquisitor/app.py @@ -4,10 +4,10 @@ import os import traceback # Third party imports -from flask import Flask, render_template, request, jsonify +from flask import Flask, render_template, request, jsonify, abort # Application imports -from inquisitor.configs import logger, DUNGEON_PATH +from inquisitor.configs import logger, DUNGEON_PATH, CACHE_PATH from inquisitor import sources, loader, timestamp # Globals @@ -145,3 +145,11 @@ def callback(): logger.error("Bad request params: {}".format(params)) sources.item_callback(params['source'], params['itemid']) return jsonify({}) + +@app.route('/cache/') +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() diff --git a/inquisitor/configs.py b/inquisitor/configs.py index 918d42b..bbb9e91 100644 --- a/inquisitor/configs.py +++ b/inquisitor/configs.py @@ -3,6 +3,7 @@ import logging DUNGEON_PATH = os.path.abspath(os.environ.get("INQUISITOR_DUNGEON") or "./dungeon") 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") handler = logging.StreamHandler()