消息列表支持显示图片
This commit is contained in:
@@ -87,6 +87,18 @@ class DashboardServer:
|
||||
@app.route('/static/<path:filename>')
|
||||
def serve_static(filename):
|
||||
return send_from_directory(static_folder, filename)
|
||||
|
||||
# 配置静态文件访问
|
||||
# 获取项目根目录下的static/images目录
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
images_dir = os.path.join(project_root, "static", "images")
|
||||
|
||||
# 确保目录存在
|
||||
os.makedirs(images_dir, exist_ok=True)
|
||||
|
||||
@app.route('/static/images/<path:filename>')
|
||||
def serve_images(filename):
|
||||
return send_from_directory(images_dir, filename)
|
||||
|
||||
# 添加一个路由处理favicon请求
|
||||
@app.route('/favicon.ico')
|
||||
|
||||
@@ -341,8 +341,23 @@
|
||||
// 如果路径为空,返回空字符串
|
||||
if (!imagePath) return '';
|
||||
|
||||
// 提取文件名
|
||||
const fileName = imagePath.split('\\').pop().split('/').pop();
|
||||
// 如果已经是完整URL,直接返回
|
||||
if (imagePath.startsWith('http://') || imagePath.startsWith('https://')) {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
// 提取文件名和路径
|
||||
const pathParts = imagePath.split(/[\/\\]/);
|
||||
const fileName = pathParts[pathParts.length - 1];
|
||||
|
||||
// 如果路径包含群ID(通常是倒数第二个部分)
|
||||
if (pathParts.length >= 2) {
|
||||
const groupId = pathParts[pathParts.length - 2];
|
||||
// 检查是否是群ID格式(通常以@chatroom结尾)
|
||||
if (groupId.includes('@chatroom')) {
|
||||
return `/static/images/${groupId}/${fileName}`;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查路径中是否包含static/images
|
||||
if (imagePath.includes('static/images') || imagePath.includes('static\\images')) {
|
||||
@@ -353,7 +368,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 如果不包含static/images,则直接使用文件名
|
||||
// 如果以上都不匹配,则直接使用文件名
|
||||
return `/static/images/${fileName}`;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user