릴리스: v1.3.13 템플릿 요청 스냅샷과 저장 분리
This commit is contained in:
@@ -154,7 +154,7 @@ function mapTemplateRequestRow(row) {
|
||||
requesterName: getUserDisplayName(row),
|
||||
requesterAccountName: getUserAccountName(row),
|
||||
requesterAvatarSrc: row.requester_avatar_src || '',
|
||||
sourceTierListId: row.source_tierlist_id,
|
||||
sourceTierListId: row.source_tierlist_id || '',
|
||||
sourceGameId: row.source_game_id,
|
||||
sourceGameName: row.source_game_name || '',
|
||||
sourceTierListTitle: row.title_snapshot || '',
|
||||
@@ -164,6 +164,9 @@ function mapTemplateRequestRow(row) {
|
||||
targetGameName: row.target_game_name || '',
|
||||
status: row.status,
|
||||
items: parseJson(row.items_json, []),
|
||||
snapshotGroups: parseJson(row.groups_json, []),
|
||||
snapshotItems: parseJson(row.board_items_json, []),
|
||||
snapshotShowCharacterNames: !!row.show_character_names_snapshot,
|
||||
createdAt: Number(row.created_at),
|
||||
updatedAt: Number(row.updated_at),
|
||||
}
|
||||
@@ -389,6 +392,23 @@ async function ensureSchema() {
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
`)
|
||||
|
||||
const templateRequestSourceTierListColumns = await query("SHOW COLUMNS FROM template_requests LIKE 'source_tierlist_id'")
|
||||
if (templateRequestSourceTierListColumns[0]?.Null !== 'YES') {
|
||||
await query('ALTER TABLE template_requests MODIFY source_tierlist_id VARCHAR(64) NULL')
|
||||
}
|
||||
const templateRequestGroupsColumns = await query("SHOW COLUMNS FROM template_requests LIKE 'groups_json'")
|
||||
if (!templateRequestGroupsColumns.length) {
|
||||
await query("ALTER TABLE template_requests ADD COLUMN groups_json LONGTEXT NOT NULL AFTER items_json")
|
||||
}
|
||||
const templateRequestBoardItemsColumns = await query("SHOW COLUMNS FROM template_requests LIKE 'board_items_json'")
|
||||
if (!templateRequestBoardItemsColumns.length) {
|
||||
await query("ALTER TABLE template_requests ADD COLUMN board_items_json LONGTEXT NOT NULL AFTER groups_json")
|
||||
}
|
||||
const templateRequestShowNamesColumns = await query("SHOW COLUMNS FROM template_requests LIKE 'show_character_names_snapshot'")
|
||||
if (!templateRequestShowNamesColumns.length) {
|
||||
await query("ALTER TABLE template_requests ADD COLUMN show_character_names_snapshot TINYINT(1) NOT NULL DEFAULT 0 AFTER board_items_json")
|
||||
}
|
||||
|
||||
const tierListThumbnailColumns = await query("SHOW COLUMNS FROM tierlists LIKE 'thumbnail_src'")
|
||||
if (!tierListThumbnailColumns.length) {
|
||||
await query("ALTER TABLE tierlists ADD COLUMN thumbnail_src VARCHAR(255) NOT NULL DEFAULT '' AFTER title")
|
||||
@@ -754,7 +774,7 @@ async function listUnusedImageAssets({ limit = 100, minAgeHours = 24 } = {}) {
|
||||
query("SELECT src FROM game_items WHERE src <> ''"),
|
||||
query("SELECT src FROM custom_items WHERE src <> ''"),
|
||||
query("SELECT thumbnail_src, pool_json FROM tierlists"),
|
||||
query("SELECT thumbnail_src_snapshot, items_json FROM template_requests"),
|
||||
query("SELECT thumbnail_src_snapshot, items_json, board_items_json FROM template_requests"),
|
||||
])
|
||||
|
||||
for (const row of userRows) if (row.avatar_src) referencedSrcs.add(row.avatar_src)
|
||||
@@ -770,6 +790,7 @@ async function listUnusedImageAssets({ limit = 100, minAgeHours = 24 } = {}) {
|
||||
for (const row of templateRequestRows) {
|
||||
if (row.thumbnail_src_snapshot) referencedSrcs.add(row.thumbnail_src_snapshot)
|
||||
collectUploadSrcsFromItems(parseJson(row.items_json, []), referencedSrcs)
|
||||
collectUploadSrcsFromItems(parseJson(row.board_items_json, []), referencedSrcs)
|
||||
}
|
||||
|
||||
return assets.filter((asset) => !referencedSrcs.has(asset.src))
|
||||
@@ -806,7 +827,7 @@ async function listReferencedUploadUsage() {
|
||||
query("SELECT src FROM game_items WHERE src <> ''"),
|
||||
query("SELECT src FROM custom_items WHERE src <> ''"),
|
||||
query("SELECT id, thumbnail_src, pool_json FROM tierlists"),
|
||||
query("SELECT id, thumbnail_src_snapshot, items_json FROM template_requests"),
|
||||
query("SELECT id, thumbnail_src_snapshot, items_json, board_items_json FROM template_requests"),
|
||||
])
|
||||
|
||||
for (const row of userRows) addUsage(row.avatar_src, 'avatar')
|
||||
@@ -822,6 +843,7 @@ async function listReferencedUploadUsage() {
|
||||
for (const row of templateRequestRows) {
|
||||
addUsage(row.thumbnail_src_snapshot, 'template-thumbnail')
|
||||
for (const item of parseJson(row.items_json, [])) addUsage(item?.src, 'template-item')
|
||||
for (const item of parseJson(row.board_items_json, [])) addUsage(item?.src, 'template-board-item')
|
||||
}
|
||||
|
||||
return Array.from(usageMap.entries())
|
||||
@@ -874,7 +896,7 @@ async function replaceUploadSourceReferences({ fromSrc, toSrc }) {
|
||||
}
|
||||
}
|
||||
|
||||
const requestRows = await query('SELECT id, thumbnail_src_snapshot, items_json FROM template_requests')
|
||||
const requestRows = await query('SELECT id, thumbnail_src_snapshot, items_json, board_items_json FROM template_requests')
|
||||
for (const row of requestRows) {
|
||||
let nextThumbnail = row.thumbnail_src_snapshot
|
||||
let changed = false
|
||||
@@ -884,12 +906,14 @@ async function replaceUploadSourceReferences({ fromSrc, toSrc }) {
|
||||
}
|
||||
|
||||
const replacedItems = replaceItemSrc(parseJson(row.items_json, []), fromSrc, toSrc)
|
||||
if (replacedItems.changed) changed = true
|
||||
const replacedBoardItems = replaceItemSrc(parseJson(row.board_items_json, []), fromSrc, toSrc)
|
||||
if (replacedItems.changed || replacedBoardItems.changed) changed = true
|
||||
|
||||
if (changed) {
|
||||
await query('UPDATE template_requests SET thumbnail_src_snapshot = ?, items_json = ?, updated_at = ? WHERE id = ?', [
|
||||
await query('UPDATE template_requests SET thumbnail_src_snapshot = ?, items_json = ?, board_items_json = ?, updated_at = ? WHERE id = ?', [
|
||||
nextThumbnail || '',
|
||||
serializeJson(replacedItems.items),
|
||||
serializeJson(replacedBoardItems.items),
|
||||
now(),
|
||||
row.id,
|
||||
])
|
||||
@@ -1636,19 +1660,24 @@ async function createTemplateRequest({
|
||||
id,
|
||||
type,
|
||||
requesterId,
|
||||
sourceTierListId,
|
||||
sourceTierListId = '',
|
||||
sourceGameId,
|
||||
targetGameId = '',
|
||||
title,
|
||||
description = '',
|
||||
thumbnailSrc = '',
|
||||
items = [],
|
||||
groups = [],
|
||||
boardItems = [],
|
||||
showCharacterNames = false,
|
||||
}) {
|
||||
const existing = await findPendingTemplateRequestByTierList({ sourceTierListId, type })
|
||||
if (existing) {
|
||||
const err = new Error('template_request_exists')
|
||||
err.code = 'TEMPLATE_REQUEST_EXISTS'
|
||||
throw err
|
||||
if (sourceTierListId) {
|
||||
const existing = await findPendingTemplateRequestByTierList({ sourceTierListId, type })
|
||||
if (existing) {
|
||||
const err = new Error('template_request_exists')
|
||||
err.code = 'TEMPLATE_REQUEST_EXISTS'
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
const createdAt = now()
|
||||
@@ -1666,22 +1695,28 @@ async function createTemplateRequest({
|
||||
description_snapshot,
|
||||
thumbnail_src_snapshot,
|
||||
items_json,
|
||||
groups_json,
|
||||
board_items_json,
|
||||
show_character_names_snapshot,
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`,
|
||||
[
|
||||
id,
|
||||
type,
|
||||
requesterId,
|
||||
sourceTierListId,
|
||||
sourceTierListId || null,
|
||||
sourceGameId,
|
||||
targetGameId,
|
||||
title,
|
||||
description,
|
||||
thumbnailSrc,
|
||||
serializeJson(items),
|
||||
serializeJson(groups),
|
||||
serializeJson(boardItems),
|
||||
showCharacterNames ? 1 : 0,
|
||||
createdAt,
|
||||
createdAt,
|
||||
]
|
||||
@@ -1704,6 +1739,9 @@ async function findTemplateRequestById(id) {
|
||||
tr.description_snapshot,
|
||||
tr.thumbnail_src_snapshot,
|
||||
tr.items_json,
|
||||
tr.groups_json,
|
||||
tr.board_items_json,
|
||||
tr.show_character_names_snapshot,
|
||||
tr.created_at,
|
||||
tr.updated_at,
|
||||
u.nickname,
|
||||
@@ -1739,6 +1777,9 @@ async function listAdminTemplateRequests({ status = 'pending' } = {}) {
|
||||
tr.description_snapshot,
|
||||
tr.thumbnail_src_snapshot,
|
||||
tr.items_json,
|
||||
tr.groups_json,
|
||||
tr.board_items_json,
|
||||
tr.show_character_names_snapshot,
|
||||
tr.created_at,
|
||||
tr.updated_at,
|
||||
u.nickname,
|
||||
|
||||
Reference in New Issue
Block a user