|
|
@@ -27,6 +27,7 @@ PORT = 2004
|
|
|
custom_address = None
|
|
|
verbose = False
|
|
|
CHATNAME = "lainchat"
|
|
|
+PRUNE_COUNT = 500
|
|
|
|
|
|
app = Flask(__name__, static_folder="public", static_url_path="")
|
|
|
|
|
|
@@ -207,11 +208,11 @@ def post_message():
|
|
|
c = conn.cursor()
|
|
|
c.execute("INSERT INTO messages (payload) VALUES (?)", (payload,))
|
|
|
|
|
|
- # Prune if over 500
|
|
|
+ # Prune if over prune count
|
|
|
c.execute("SELECT COUNT(*) FROM messages")
|
|
|
count = c.fetchone()[0]
|
|
|
- if count > 500:
|
|
|
- excess = count - 500
|
|
|
+ if count > PRUNE_COUNT:
|
|
|
+ excess = count - PRUNE_COUNT
|
|
|
c.execute(
|
|
|
"DELETE FROM messages WHERE id IN (SELECT id FROM messages ORDER BY id ASC LIMIT ?)",
|
|
|
(excess,),
|
|
|
@@ -235,11 +236,11 @@ def post_message():
|
|
|
@app.route("/api/messages", methods=["GET"])
|
|
|
def get_messages():
|
|
|
is_stream = request.args.get("stream") == "1"
|
|
|
-
|
|
|
+
|
|
|
if not is_stream:
|
|
|
session_id = request.cookies.get("session_id")
|
|
|
with db_lock:
|
|
|
- conn = sqlite3.connect('chat.db', check_same_thread=False)
|
|
|
+ conn = sqlite3.connect("chat.db", check_same_thread=False)
|
|
|
c = conn.cursor()
|
|
|
c.execute("SELECT 1 FROM users WHERE session_id = ?", (session_id,))
|
|
|
if not c.fetchone():
|
|
|
@@ -301,11 +302,11 @@ def download_images():
|
|
|
@app.route("/api/backlog", methods=["GET"])
|
|
|
def get_backlog():
|
|
|
is_stream = request.args.get("stream") == "1"
|
|
|
-
|
|
|
+
|
|
|
if not is_stream:
|
|
|
session_id = request.cookies.get("session_id")
|
|
|
with db_lock:
|
|
|
- conn = sqlite3.connect('chat.db', check_same_thread=False)
|
|
|
+ conn = sqlite3.connect("chat.db", check_same_thread=False)
|
|
|
c = conn.cursor()
|
|
|
c.execute("SELECT 1 FROM users WHERE session_id = ?", (session_id,))
|
|
|
if not c.fetchone():
|