From b497fe97f3324cc0be5547daaff582e4f83388b9 Mon Sep 17 00:00:00 2001 From: AnthonyDuan Date: Sun, 7 Dec 2025 11:17:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8E=E7=BC=A9=E7=95=A5=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=EF=BC=9B=E5=AE=A1=E6=A0=B8=E9=A1=B5=E5=B1=95=E7=A4=BA=E5=9B=BE?= =?UTF-8?q?+=E4=BB=8B=E7=BB=8D+=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/blueprints/activities.py | 8 +++++++- app/blueprints/main.py | 11 +++++++++-- app/blueprints/posts.py | 9 ++++++++- app/templates/admin/reviews_posts.html | 23 +++++++++++++---------- app/templates/feed/discover.html | 2 +- app/templates/feed/following.html | 2 +- app/templates/posts/detail.html | 2 +- 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/app/blueprints/activities.py b/app/blueprints/activities.py index 9421def..884ee93 100644 --- a/app/blueprints/activities.py +++ b/app/blueprints/activities.py @@ -29,7 +29,13 @@ def submit(act_id): upload_dir = os.path.join(current_app.config["UPLOAD_FOLDER"], "activities") for idx, f in enumerate(files): original, web, thumb, exif = save_image(f, upload_dir) - img = SubmissionImage(submission_id=sub.id, original_path=original, web_path=web, thumb_path=thumb, exif_json=exif, order_index=idx) + root = current_app.config["UPLOAD_FOLDER"] + def rel(p): + try: + return os.path.relpath(p, root) + except Exception: + return p + img = SubmissionImage(submission_id=sub.id, original_path=rel(original), web_path=rel(web), thumb_path=rel(thumb), exif_json=exif, order_index=idx) db.session.add(img) db.session.commit() flash("投稿已提交,待审核") diff --git a/app/blueprints/main.py b/app/blueprints/main.py index 33a691a..57b65bc 100644 --- a/app/blueprints/main.py +++ b/app/blueprints/main.py @@ -1,4 +1,5 @@ -from flask import Blueprint, redirect, url_for, current_app, send_from_directory +import os +from flask import Blueprint, redirect, url_for, current_app, send_file, abort bp = Blueprint("main", __name__) @@ -8,4 +9,10 @@ def index(): @bp.route("/uploads/") def uploads(filename): - return send_from_directory(current_app.config["UPLOAD_FOLDER"], filename) + root = os.path.abspath(current_app.config["UPLOAD_FOLDER"]) + path = filename + if not os.path.isabs(path): + path = os.path.abspath(os.path.join(root, filename)) + if not path.startswith(root): + abort(404) + return send_file(path) diff --git a/app/blueprints/posts.py b/app/blueprints/posts.py index 61ac635..afa6514 100644 --- a/app/blueprints/posts.py +++ b/app/blueprints/posts.py @@ -31,7 +31,14 @@ def create(): upload_dir = os.path.join(current_app.config["UPLOAD_FOLDER"], "posts") for idx, f in enumerate(files): original, web, thumb, exif = save_image(f, upload_dir) - img = PostImage(post_id=post.id, original_path=original, web_path=web, thumb_path=thumb, exif_json=exif, order_index=idx) + # 存储相对路径,兼容已有绝对路径 + root = current_app.config["UPLOAD_FOLDER"] + def rel(p): + try: + return os.path.relpath(p, root) + except Exception: + return p + img = PostImage(post_id=post.id, original_path=rel(original), web_path=rel(web), thumb_path=rel(thumb), exif_json=exif, order_index=idx) db.session.add(img) db.session.commit() flash("作品已提交") diff --git a/app/templates/admin/reviews_posts.html b/app/templates/admin/reviews_posts.html index 2e107bb..4b95652 100644 --- a/app/templates/admin/reviews_posts.html +++ b/app/templates/admin/reviews_posts.html @@ -1,14 +1,17 @@ {% extends 'base.html' %} {% block title %}作品审核{% endblock %} {% block content %} -

作品审核

- - +

作品审核

+
{% for p in posts %} -
- - - - + + {% endfor %} -
标题作者操作
{{ p.title }}{{ p.user.username }} +
+ {% set first = p.images[0] if p.images %} + {% if first %} + {{ p.title }} + {% endif %} +
+
{{ p.title }} · {{ p.user.username }}
+ {% if p.description %}
{{ p.description }}
{% endif %}
@@ -17,8 +20,8 @@
-
+ {% endblock %} diff --git a/app/templates/feed/discover.html b/app/templates/feed/discover.html index f09ebd1..652ab0d 100644 --- a/app/templates/feed/discover.html +++ b/app/templates/feed/discover.html @@ -8,7 +8,7 @@ {% set first = p.images[0] if p.images %} {% if first %} - {{ p.title }} + {{ p.title }} {% endif %}
diff --git a/app/templates/feed/following.html b/app/templates/feed/following.html index db024a9..108653c 100644 --- a/app/templates/feed/following.html +++ b/app/templates/feed/following.html @@ -8,7 +8,7 @@ {% set first = p.images[0] if p.images %} {% if first %} - {{ p.title }} + {{ p.title }} {% endif %}
diff --git a/app/templates/posts/detail.html b/app/templates/posts/detail.html index bfa8424..17a03d2 100644 --- a/app/templates/posts/detail.html +++ b/app/templates/posts/detail.html @@ -11,7 +11,7 @@
{% for img in post.images %}
- +
{% endfor %}