feat: 重写新增配方+共享审核完整流程
新增配方:
- 修复保存失败(oil→oil_name字段转换)
- 智能识别支持多条配方同时解析
- 识别结果逐条预览,可修改/放弃/保存单条/全部保存
- 编辑器加成分表格(单价/滴、小计、总成本)
- 保存到个人配方(diary)
共享审核:
- 新增 /api/recipes/{id}/reject 端点(带原因通知提交者)
- 采纳配方时通知提交者"配方已采纳"
- 拒绝时管理员输入原因
- 贡献统计含被采纳的配方数
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -260,3 +260,65 @@ export function parseSingleBlock(raw, oilNames) {
|
||||
notFound
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse multi-recipe text. Each time an unrecognized non-number token
|
||||
* appears after some oils have been found, it starts a new recipe.
|
||||
*/
|
||||
export function parseMultiRecipes(raw, oilNames) {
|
||||
const parts = raw.split(/[,,、\n\r]+/).map(s => s.trim()).filter(s => s)
|
||||
|
||||
const recipes = []
|
||||
let current = { nameParts: [], ingredientParts: [], foundOil: false }
|
||||
|
||||
for (const part of parts) {
|
||||
const hasNumber = /\d/.test(part)
|
||||
const hasOil = oilNames.some(oil => part.includes(oil)) ||
|
||||
Object.keys(OIL_HOMOPHONES).some(alias => part.includes(alias))
|
||||
// Also check fuzzy: 3+ char parts
|
||||
const fuzzyOil = !hasOil && part.replace(/\d+\.?\d*/g, '').length >= 2 &&
|
||||
findOil(part.replace(/\d+\.?\d*/g, '').trim(), oilNames)
|
||||
|
||||
if (current.foundOil && !hasOil && !fuzzyOil && !hasNumber && part.length >= 2) {
|
||||
// New recipe starts
|
||||
recipes.push(current)
|
||||
current = { nameParts: [], ingredientParts: [], foundOil: false }
|
||||
current.nameParts.push(part)
|
||||
} else if (!current.foundOil && !hasOil && !fuzzyOil && !hasNumber) {
|
||||
current.nameParts.push(part)
|
||||
} else {
|
||||
current.foundOil = true
|
||||
current.ingredientParts.push(part)
|
||||
}
|
||||
}
|
||||
recipes.push(current)
|
||||
|
||||
// Convert each block to parsed recipe
|
||||
return recipes.filter(r => r.ingredientParts.length > 0 || r.nameParts.length > 0).map(r => {
|
||||
const allIngs = []
|
||||
const notFound = []
|
||||
for (const p of r.ingredientParts) {
|
||||
const parsed = parseOilChunk(p, oilNames)
|
||||
for (const item of parsed) {
|
||||
if (item.notFound) notFound.push(item.oil)
|
||||
else allIngs.push(item)
|
||||
}
|
||||
}
|
||||
// Deduplicate
|
||||
const deduped = []
|
||||
const seen = {}
|
||||
for (const item of allIngs) {
|
||||
if (seen[item.oil] !== undefined) {
|
||||
deduped[seen[item.oil]].drops += item.drops
|
||||
} else {
|
||||
seen[item.oil] = deduped.length
|
||||
deduped.push({ ...item })
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: r.nameParts.join(' ') || '未命名配方',
|
||||
ingredients: deduped,
|
||||
notFound,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user