릴리스: v1.3.34 관리자 아이템 라이브러리 정리
This commit is contained in:
@@ -8,6 +8,7 @@ const { nanoid } = require('nanoid')
|
||||
const {
|
||||
findUserById,
|
||||
findGameById,
|
||||
findGameItemById,
|
||||
createGame,
|
||||
listGames,
|
||||
updateGameThumbnail,
|
||||
@@ -322,12 +323,12 @@ async function removeCustomItemFiles(items) {
|
||||
)
|
||||
}
|
||||
|
||||
async function promoteCustomItemToGameItem({ customItem, gameId }) {
|
||||
async function promoteLibraryItemToGameItem({ item, gameId }) {
|
||||
return createGameItem({
|
||||
id: nanoid(),
|
||||
gameId,
|
||||
src: customItem.src || '',
|
||||
label: customItem.label,
|
||||
src: item.src || '',
|
||||
label: item.label,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -428,6 +429,8 @@ router.delete('/custom-items/:itemId', requireAdmin, async (req, res) => {
|
||||
const result = await listCustomItems({ page: 1, limit: 200, orphanOnly: false })
|
||||
const target = result.items.find((item) => item.id === req.params.itemId)
|
||||
if (!target) return res.status(404).json({ error: 'not_found' })
|
||||
if (!target.canDelete) return res.status(409).json({ error: 'item_locked' })
|
||||
if (target.linkedGames.length > 0) return res.status(409).json({ error: 'item_linked' })
|
||||
if (target.usageCount > 0) return res.status(409).json({ error: 'item_in_use' })
|
||||
|
||||
const items = await findCustomItemsByIds([target.id])
|
||||
@@ -447,9 +450,11 @@ router.post('/custom-items/:itemId/promote', requireAdmin, async (req, res) => {
|
||||
if (!game) return res.status(404).json({ error: 'game_not_found' })
|
||||
|
||||
const customItem = await findCustomItemById(req.params.itemId)
|
||||
if (!customItem) return res.status(404).json({ error: 'not_found' })
|
||||
const gameItem = customItem ? null : await findGameItemById(req.params.itemId)
|
||||
const sourceItem = customItem || gameItem
|
||||
if (!sourceItem) return res.status(404).json({ error: 'not_found' })
|
||||
|
||||
const item = await promoteCustomItemToGameItem({ customItem, gameId: game.id })
|
||||
const item = await promoteLibraryItemToGameItem({ item: sourceItem, gameId: game.id })
|
||||
res.json({ item })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user