feat: 增加网页comment字段

This commit is contained in:
2025-10-26 10:24:07 +08:00
parent 62de9573ac
commit c8dfec6cf4
2 changed files with 127 additions and 26 deletions

View File

@@ -44,6 +44,7 @@ def init_db():
right_filename TEXT NOT NULL,
timestamp REAL NOT NULL,
metadata TEXT,
comment TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
@@ -89,7 +90,7 @@ def get_images_api():
conn = sqlite3.connect(DATABASE_PATH)
cursor = conn.cursor()
# 按时间倒序排列
cursor.execute("SELECT id, left_filename, right_filename, timestamp, metadata, created_at FROM images ORDER BY timestamp DESC")
cursor.execute("SELECT id, left_filename, right_filename, timestamp, metadata, comment, created_at FROM images ORDER BY timestamp DESC")
rows = cursor.fetchall()
conn.close()
@@ -101,7 +102,8 @@ def get_images_api():
"right_filename": row[2],
"timestamp": row[3],
"metadata": row[4],
"created_at": row[5]
"comment": row[5] or "", # 如果没有comment则显示空字符串
"created_at": row[6]
})
return jsonify(images)
@@ -194,6 +196,7 @@ def upload_images():
left_file = request.files.get('left_image')
right_file = request.files.get('right_image')
metadata_str = request.form.get('metadata') # 如果需要处理元数据
comment = request.form.get('comment', '') # 获取comment字段
if not left_file or not right_file:
logger.warning("Received request without required image files.")
@@ -244,9 +247,9 @@ def upload_images():
conn = sqlite3.connect(DATABASE_PATH)
cursor = conn.cursor()
cursor.execute('''
INSERT INTO images (left_filename, right_filename, timestamp, metadata)
VALUES (?, ?, ?, ?)
''', (left_filename, right_filename, float(timestamp_str), json.dumps(metadata)))
INSERT INTO images (left_filename, right_filename, timestamp, metadata, comment)
VALUES (?, ?, ?, ?, ?)
''', (left_filename, right_filename, float(timestamp_str), json.dumps(metadata), comment))
conn.commit()
image_id = cursor.lastrowid # 获取新插入记录的 ID
conn.close()
@@ -277,7 +280,25 @@ def upload_images():
logger.error(f"Error processing upload: {e}")
return jsonify({"error": str(e)}), 500
# --- 可选:添加一个简单的状态检查路由 ---
@app.route('/api/images/comment', methods=['PUT'])
def update_image_comment():
"""API: 更新图片的comment"""
data = request.json
image_id = data.get('id')
comment = data.get('comment', '')
if not image_id:
return jsonify({"error": "Image ID is required"}), 400
conn = sqlite3.connect(DATABASE_PATH)
cursor = conn.cursor()
# 更新comment字段
cursor.execute("UPDATE images SET comment = ? WHERE id = ?", (comment, image_id))
conn.commit()
conn.close()
return jsonify({"message": f"Comment for image {image_id} updated successfully"})
@app.route('/status')
def status():
with frame_lock: