fix: 批量改标签只发送tags字段,不发送整个recipe
修复因ingredients格式不匹配(oil vs oil_name)导致PUT请求失败 标签修改实际未保存到数据库的问题 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -601,15 +601,22 @@ async function applyBatchTags() {
|
|||||||
for (const id of pubIds) {
|
for (const id of pubIds) {
|
||||||
const recipe = recipeStore.recipes.find(r => r._id === id)
|
const recipe = recipeStore.recipes.find(r => r._id === id)
|
||||||
if (!recipe) continue
|
if (!recipe) continue
|
||||||
|
let newTags = [...recipe.tags]
|
||||||
let changed = false
|
let changed = false
|
||||||
for (const t of tagsToAdd) {
|
for (const t of tagsToAdd) {
|
||||||
if (!recipe.tags.includes(t)) { recipe.tags.push(t); changed = true }
|
if (!newTags.includes(t)) { newTags.push(t); changed = true }
|
||||||
}
|
}
|
||||||
for (const t of tagsToRemove) {
|
for (const t of tagsToRemove) {
|
||||||
const idx = recipe.tags.indexOf(t)
|
const idx = newTags.indexOf(t)
|
||||||
if (idx >= 0) { recipe.tags.splice(idx, 1); changed = true }
|
if (idx >= 0) { newTags.splice(idx, 1); changed = true }
|
||||||
|
}
|
||||||
|
if (changed) {
|
||||||
|
await api(`/api/recipes/${recipe._id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ tags: newTags }),
|
||||||
|
})
|
||||||
|
recipe.tags = newTags
|
||||||
}
|
}
|
||||||
if (changed) await recipeStore.saveRecipe(recipe)
|
|
||||||
}
|
}
|
||||||
for (const id of diaryIds) {
|
for (const id of diaryIds) {
|
||||||
const d = diaryStore.userDiary.find(r => r.id === id)
|
const d = diaryStore.userDiary.find(r => r.id === id)
|
||||||
|
|||||||
Reference in New Issue
Block a user