From 48321233c31ece264034f4595849db5f98ebb80b Mon Sep 17 00:00:00 2001 From: ffqq Date: Thu, 13 Jul 2023 00:28:28 +0000 Subject: [PATCH 1/5] feat: current git commit hash shown to visitors --- main | 18 ++++++++++++++++-- static/css/style.css | 22 ++++++++++++++++++++++ templates/main.html | 7 ++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/main b/main index 2491f71..0114a2e 100644 --- a/main +++ b/main @@ -7,6 +7,7 @@ import json import secrets import datetime import socket +import subprocess from itertools import groupby from waitress import serve from werkzeug.utils import secure_filename @@ -126,6 +127,17 @@ def get_session(id): return "error" return post +def get_current_commit(output_format="full"): + if output_format == "short": + length = 8 + else: + length = 40 + + try: + output = subprocess.check_output(["git", "rev-parse", f"--short={length}", "HEAD"]).decode().strip() + return output + except subprocess.CalledProcessError: + return "Error fetching git commit" ALLOWED_EXTENSIONS = {"png", "apng", "jpg", "jpeg", "gif", "svg", "webp"} @@ -139,14 +151,16 @@ def main(): usersession = request.cookies.get("session_DO_NOT_SHARE") conn = get_db_connection() posts = conn.execute("SELECT * FROM posts ORDER BY created DESC;").fetchall() + commit_hash_long = get_current_commit() + commit_hash_short = get_current_commit(output_format="short") conn.close() if usersession: userCookie = get_session(usersession) user = get_user(userCookie["id"]) - return render_template("main.html", userdata=user, posts=posts) + return render_template("main.html", userdata=user, posts=posts, commit_hash_long=commit_hash_long, commit_hash_short=commit_hash_short) else: - return render_template("main.html", posts=posts) + return render_template("main.html", posts=posts, commit_hash_long=commit_hash_long, commit_hash_short=commit_hash_short) @app.route("/chat", methods=("GET", "POST")) def chat(): diff --git a/static/css/style.css b/static/css/style.css index d677f44..7df4fbe 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -19,6 +19,20 @@ body { z-index: 2; } +.bottom { + margin: 0; + border: solid; + border-color: grey; + border-width: 0; + border-bottom-width: 1px; + background-color: white; +} + +.bottom a { + color: lightgrey; + text-decoration: none; +} + .navbar .selected { border: solid; border-color: #f1b739; @@ -332,6 +346,14 @@ body { background-color: var(--gray-800); } + .bottom { + background-color: var(--gray-900); + } + + .bottom a { + color: var(--gray-800) + } + .navbar a, a { color: white; border-size: 0px; diff --git a/templates/main.html b/templates/main.html index 1e1b17a..f75d0c1 100644 --- a/templates/main.html +++ b/templates/main.html @@ -113,7 +113,12 @@ {% endfor %} - +
+ + burgercat + commit hash: {{ commit_hash_short }} + +
From df75e02efc359979d3bcb80b8c5ae11949f75be1 Mon Sep 17 00:00:00 2001 From: ffqq Date: Thu, 13 Jul 2023 02:50:16 +0000 Subject: [PATCH 2/5] fix: wrap links inside of for convenience --- static/js/chat.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/static/js/chat.js b/static/js/chat.js index 52d97c1..92116c2 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -20,7 +20,11 @@ async function updateMessages(id) { const timeParagraph = document.createElement("p"); const { creator, content, id, created } = message; - messageParagraph.appendChild(document.createTextNode(`${creator.username}: ${content}`)); + // Check if the message content contains any links that are not image links + const linkRegex = /(https?:\/\/[^\s]+(?$1"); + + messageParagraph.innerHTML = `${creator.username}: ${messageContent}`; messageParagraph.classList.add("messageParagraph"); messageParagraph.id = `messageParagraph${id}`; messageParagraph.appendChild(timeParagraph); From 69d60208656c95d509a05d3b95b732adf810429a Mon Sep 17 00:00:00 2001 From: ffqq Date: Thu, 13 Jul 2023 03:05:33 +0000 Subject: [PATCH 3/5] fix: made commit hash consistent with the running server --- main | 19 ++++--------------- templates/main.html | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/main b/main index 0114a2e..57a5084 100644 --- a/main +++ b/main @@ -127,17 +127,8 @@ def get_session(id): return "error" return post -def get_current_commit(output_format="full"): - if output_format == "short": - length = 8 - else: - length = 40 - - try: - output = subprocess.check_output(["git", "rev-parse", f"--short={length}", "HEAD"]).decode().strip() - return output - except subprocess.CalledProcessError: - return "Error fetching git commit" +full_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() +short_hash = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"]).decode().strip() ALLOWED_EXTENSIONS = {"png", "apng", "jpg", "jpeg", "gif", "svg", "webp"} @@ -151,16 +142,14 @@ def main(): usersession = request.cookies.get("session_DO_NOT_SHARE") conn = get_db_connection() posts = conn.execute("SELECT * FROM posts ORDER BY created DESC;").fetchall() - commit_hash_long = get_current_commit() - commit_hash_short = get_current_commit(output_format="short") conn.close() if usersession: userCookie = get_session(usersession) user = get_user(userCookie["id"]) - return render_template("main.html", userdata=user, posts=posts, commit_hash_long=commit_hash_long, commit_hash_short=commit_hash_short) + return render_template("main.html", userdata=user, posts=posts, full_hash=full_hash, short_hash=short_hash) else: - return render_template("main.html", posts=posts, commit_hash_long=commit_hash_long, commit_hash_short=commit_hash_short) + return render_template("main.html", posts=posts, full_hash=full_hash, short_hash=short_hash) @app.route("/chat", methods=("GET", "POST")) def chat(): diff --git a/templates/main.html b/templates/main.html index f75d0c1..2a3932f 100644 --- a/templates/main.html +++ b/templates/main.html @@ -116,7 +116,7 @@ From 7b1e636187ad8c3418a831f178e6945ee00ae299 Mon Sep 17 00:00:00 2001 From: ffqq Date: Thu, 13 Jul 2023 03:22:47 +0000 Subject: [PATCH 4/5] feat: hide image links from messages and improve overall handling of links --- static/js/chat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/js/chat.js b/static/js/chat.js index 92116c2..1c7194e 100644 --- a/static/js/chat.js +++ b/static/js/chat.js @@ -20,8 +20,8 @@ async function updateMessages(id) { const timeParagraph = document.createElement("p"); const { creator, content, id, created } = message; - // Check if the message content contains any links that are not image links - const linkRegex = /(https?:\/\/[^\s]+(?$1"); messageParagraph.innerHTML = `${creator.username}: ${messageContent}`; From 40fcc16cc5178b0cc81392dc4c4c6e6f780d7c16 Mon Sep 17 00:00:00 2001 From: ffqq Date: Thu, 13 Jul 2023 05:27:14 +0000 Subject: [PATCH 5/5] fix: inconsistency between dark mode and light mode --- static/css/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/css/style.css b/static/css/style.css index 7df4fbe..7ac1133 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -351,7 +351,7 @@ body { } .bottom a { - color: var(--gray-800) + color: var(--gray-700) } .navbar a, a {