fix: 이미지 대체 시 원본 사용자 아이템 정보 보존
This commit is contained in:
@@ -1152,7 +1152,7 @@ function replaceItemSrc(items, fromSrc, toSrc, toLabel = '') {
|
||||
return { changed, items: nextItems }
|
||||
}
|
||||
|
||||
async function replaceUploadSourceReferences({ fromSrc, toSrc, toLabel = '' }) {
|
||||
async function replaceUploadSourceReferences({ fromSrc, toSrc, toLabel = '', updateCustomItemsBySrc = true }) {
|
||||
if (!fromSrc || !toSrc || fromSrc === toSrc) return { updatedRows: 0 }
|
||||
const normalizedLabel = typeof toLabel === 'string' ? toLabel.trim().slice(0, 60) : ''
|
||||
|
||||
@@ -1162,9 +1162,11 @@ async function replaceUploadSourceReferences({ fromSrc, toSrc, toLabel = '' }) {
|
||||
normalizedLabel
|
||||
? query('UPDATE topic_items SET src = ?, label = ? WHERE src = ?', [toSrc, normalizedLabel, fromSrc])
|
||||
: query('UPDATE topic_items SET src = ? WHERE src = ?', [toSrc, fromSrc]),
|
||||
normalizedLabel
|
||||
? query('UPDATE custom_items SET src = ?, label = ? WHERE src = ?', [toSrc, normalizedLabel, fromSrc])
|
||||
: query('UPDATE custom_items SET src = ? WHERE src = ?', [toSrc, fromSrc]),
|
||||
updateCustomItemsBySrc
|
||||
? normalizedLabel
|
||||
? query('UPDATE custom_items SET src = ?, label = ? WHERE src = ?', [toSrc, normalizedLabel, fromSrc])
|
||||
: query('UPDATE custom_items SET src = ? WHERE src = ?', [toSrc, fromSrc])
|
||||
: Promise.resolve({ affectedRows: 0 }),
|
||||
])
|
||||
|
||||
let updatedRows = Number(userResult.affectedRows || 0) + Number(topicResult.affectedRows || 0) + Number(topicItemResult.affectedRows || 0) + Number(customItemResult.affectedRows || 0)
|
||||
|
||||
@@ -835,6 +835,7 @@ router.post('/custom-items/:itemId/replace', requireAdmin, async (req, res) => {
|
||||
fromSrc: sourceItem.src,
|
||||
toSrc: targetItem.src,
|
||||
toLabel: targetItem.label || '',
|
||||
updateCustomItemsBySrc: false,
|
||||
})
|
||||
await markCustomItemReplaced({
|
||||
itemId: sourceItem.id,
|
||||
|
||||
Reference in New Issue
Block a user