|
@@ -1,4 +1,4 @@
|
|
|
-from flask import Flask, render_template
|
|
|
+from flask import Flask, render_template, make_response
|
|
|
from flask_paginate import Pagination, get_page_parameter, get_page_args
|
|
|
from flask_caching import Cache
|
|
|
from flask import request
|
|
@@ -21,25 +21,41 @@ def format_datetime(value):
|
|
|
# Check Configuring Flask-Caching section for more details
|
|
|
# cache = Cache(app, config={"CACHE_TYPE": "filesystem", "CACHE_DIR": "cache"})
|
|
|
cache = Cache(app, config={"CACHE_TYPE": "redis", "CACHE_REDIS_HOST": "redis"})
|
|
|
+# cache = Cache(app, config={"CACHE_TYPE": "redis", "CACHE_REDIS_HOST": "olympus"})
|
|
|
|
|
|
import jammin
|
|
|
|
|
|
-bases = {"FSX_General": "msgs/fsx_gen", "FSX_BBS": "msgs/fsx_bbs", "FSX_BOT": "msgs/fsx_bot", "FSX_Magicka": "msgs/fsx_mag", "HappyNet": "msgs/hpy_gen"}
|
|
|
+bases = {
|
|
|
+ "FSX_General": "msgs/fsx_gen",
|
|
|
+ "FSX_BBS": "msgs/fsx_bbs",
|
|
|
+ "FSX_BOT": "msgs/fsx_bot",
|
|
|
+ "FSX_Magicka": "msgs/fsx_mag",
|
|
|
+ "HappyNet": "msgs/hpy_gen",
|
|
|
+}
|
|
|
|
|
|
+# bases = {"FSX_BOT": "fsx_bot"}
|
|
|
|
|
|
# @cache.memoize(timeout=5 * 60, key_prefix="messages")
|
|
|
|
|
|
+
|
|
|
@cache.memoize(timeout=5 * 60)
|
|
|
def get_messages(base):
|
|
|
messages = jammin.get_messages(base)
|
|
|
messages.reverse()
|
|
|
return messages
|
|
|
|
|
|
+
|
|
|
@cache.memoize(timeout=60)
|
|
|
def get_message(base, msgno):
|
|
|
message = jammin.read_message(base, msgno)
|
|
|
return message
|
|
|
|
|
|
+
|
|
|
[email protected](404)
|
|
|
+def not_found(e):
|
|
|
+ return render_template("404.html")
|
|
|
+
|
|
|
+
|
|
|
@app.route(base_path + "/list")
|
|
|
def list_bases():
|
|
|
return render_template(
|
|
@@ -86,6 +102,7 @@ def display_messages(area):
|
|
|
)
|
|
|
|
|
|
|
|
|
[email protected](timeout=60)
|
|
|
def ansi_to_png(raw_ansi_bytes, idx):
|
|
|
pid = os.getppid()
|
|
|
ansifile = "{0}-{1}.ans".format(idx, pid)
|
|
@@ -97,9 +114,29 @@ def ansi_to_png(raw_ansi_bytes, idx):
|
|
|
png = fp.read()
|
|
|
os.unlink(ansifile)
|
|
|
os.unlink(pngfile)
|
|
|
+ return png
|
|
|
+
|
|
|
+
|
|
|
+def ansi_to_png64(raw_ansi_bytes, idx):
|
|
|
+ png = ansi_to_png(raw_ansi_bytes, idx)
|
|
|
return base64.b64encode(png).decode("utf-8")
|
|
|
|
|
|
|
|
|
[email protected](base_path + "/image/<area>/<int:msgno>.png")
|
|
|
+def display_ansi(area, msgno):
|
|
|
+ if area not in bases:
|
|
|
+ return "RATS", 404
|
|
|
+ message = get_message(bases[area], msgno)
|
|
|
+ if not message:
|
|
|
+ return "RATS", 404
|
|
|
+ if not "text" in message:
|
|
|
+ return "RATS", 404
|
|
|
+ png = ansi_to_png(message["bytes"].replace(b"\r", b"\n"), msgno)
|
|
|
+ response = make_response(png)
|
|
|
+ response.headers.set("Content-Type", "image/png")
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
# <img alt="My Image" src="data:image/png;base64,
|
|
|
@app.route(base_path + "/read/<area>/<int:msgno>")
|
|
|
def display_message(area, msgno):
|
|
@@ -113,13 +150,19 @@ def display_message(area, msgno):
|
|
|
|
|
|
if not message:
|
|
|
return render_template(
|
|
|
- "missing-message.html", base_path=base_path, area=area, title="Missing Message"
|
|
|
+ "missing-message.html",
|
|
|
+ base_path=base_path,
|
|
|
+ area=area,
|
|
|
+ title="Missing Message",
|
|
|
)
|
|
|
|
|
|
if "text" in message:
|
|
|
if "\x1b" in message["text"]:
|
|
|
# Ok, the message contains ANSI CODES -- Convert
|
|
|
- message["png"] = ansi_to_png(message["bytes"].replace(b"\r", b"\n"), msgno)
|
|
|
+ message["png"] = True
|
|
|
+ # message["png"] = ansi_to_png64(
|
|
|
+ # message["bytes"].replace(b"\r", b"\n"), msgno
|
|
|
+ # )
|
|
|
else:
|
|
|
message["text"] = message["text"].replace("\r", "\n") # <br >\n")
|
|
|
|