fix(ui): 修复图片路径与缩略显示;审核页展示图+介绍+用户

This commit is contained in:
2025-12-07 11:17:57 +08:00
parent b5da02cffc
commit b497fe97f3
7 changed files with 40 additions and 17 deletions

View File

@@ -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("投稿已提交,待审核")

View File

@@ -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/<path:filename>")
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)

View File

@@ -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("作品已提交")