From 2e8bfea26254b975248ad0bf900d307b43e2ebe6 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sat, 23 May 2026 12:01:45 +0800 Subject: [PATCH] =?UTF-8?q?v2.1:=20=E6=A0=87=E7=AD=BE=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E3=80=81=E5=88=86=E7=B1=BB=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- app.py | 24 +++++++ templates/index.html | 158 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 181 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5cd78fa..a3fc7fc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - 主题管理:创建、编辑、删除文章主题 - 分类系统:多级分类,每个主题可归属多个分类 -- 标签系统:灵活标签,每个主题支持多个标签,支持新建标签 +- 标签系统:灵活标签,每个主题支持多个标签,支持增删改 - 素材收集:支持文本素材和图片素材(含Ctrl+V粘贴截图) - Prompt编辑:每个主题可自定义生成提示词,支持历史记录 - 大模型生成:调用 LLM 根据素材自动生成文章 @@ -82,6 +82,7 @@ article-writer/ ### 标签 - `GET /api/tags` - 标签列表(含主题计数) - `POST /api/tags` - 创建标签 +- `PUT /api/tags/` - 更新标签 - `DELETE /api/tags/` - 删除标签 ### 主题 diff --git a/app.py b/app.py index cfce41e..9a4a0a8 100644 --- a/app.py +++ b/app.py @@ -390,6 +390,30 @@ def create_tag(): return jsonify(dict(tag)) +@app.route('/api/tags/', methods=['PUT']) +def update_tag(tag_id): + data = request.get_json(force=True) + conn = get_db() + tag = conn.execute('SELECT * FROM tags WHERE id=?', (tag_id,)).fetchone() + if not tag: + conn.close() + return jsonify({'error': '标签不存在'}), 404 + name = data.get('name', '').strip() + if not name: + conn.close() + return jsonify({'error': '标签名不能为空'}), 400 + # 检查重名(排除自身) + existing = conn.execute('SELECT id FROM tags WHERE name=? AND id!=?', (name, tag_id)).fetchone() + if existing: + conn.close() + return jsonify({'error': '标签名已存在'}), 400 + conn.execute('UPDATE tags SET name=? WHERE id=?', (name, tag_id)) + conn.commit() + tag = conn.execute('SELECT * FROM tags WHERE id=?', (tag_id,)).fetchone() + conn.close() + return jsonify(dict(tag)) + + @app.route('/api/tags/', methods=['DELETE']) def delete_tag(tag_id): conn = get_db() diff --git a/templates/index.html b/templates/index.html index c410028..8d1fe26 100644 --- a/templates/index.html +++ b/templates/index.html @@ -79,6 +79,9 @@ + @@ -244,6 +247,27 @@ + + +