릴리스: v1.3.60 관리자 공개 토글과 인증 새로고침 안정화
This commit is contained in:
@@ -73,6 +73,7 @@ function mapGameRow(row) {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
thumbnailSrc: row.thumbnail_src || '',
|
||||
isPublic: row.is_public == null ? true : !!row.is_public,
|
||||
displayRank: row.display_rank == null ? null : Number(row.display_rank),
|
||||
createdAt: Number(row.created_at),
|
||||
}
|
||||
@@ -256,11 +257,18 @@ async function ensureSchema() {
|
||||
id VARCHAR(120) PRIMARY KEY,
|
||||
name VARCHAR(120) NOT NULL,
|
||||
thumbnail_src VARCHAR(255) NOT NULL DEFAULT '',
|
||||
is_public TINYINT(1) NOT NULL DEFAULT 1,
|
||||
display_rank INT NULL DEFAULT NULL,
|
||||
created_at BIGINT NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
`)
|
||||
|
||||
const gameIsPublicColumns = await query("SHOW COLUMNS FROM games LIKE 'is_public'")
|
||||
if (!gameIsPublicColumns.length) {
|
||||
await query('ALTER TABLE games ADD COLUMN is_public TINYINT(1) NOT NULL DEFAULT 1 AFTER thumbnail_src')
|
||||
await query('UPDATE games SET is_public = 1 WHERE is_public IS NULL')
|
||||
}
|
||||
|
||||
const displayRankColumns = await query("SHOW COLUMNS FROM games LIKE 'display_rank'")
|
||||
if (!displayRankColumns.length) {
|
||||
await query('ALTER TABLE games ADD COLUMN display_rank INT NULL DEFAULT NULL AFTER thumbnail_src')
|
||||
@@ -643,12 +651,14 @@ async function adminDeleteUser(id) {
|
||||
await query('DELETE FROM users WHERE id = ?', [id])
|
||||
}
|
||||
|
||||
async function listGames(currentUserId = '') {
|
||||
async function listGames(currentUserId = '', options = {}) {
|
||||
const includePrivate = !!options.includePrivate
|
||||
const rows = await query(
|
||||
`
|
||||
SELECT id, name, thumbnail_src, display_rank, created_at
|
||||
SELECT id, name, thumbnail_src, is_public, display_rank, created_at
|
||||
FROM games
|
||||
WHERE id <> ?
|
||||
${includePrivate ? '' : 'AND is_public = 1'}
|
||||
ORDER BY
|
||||
CASE WHEN display_rank IS NULL THEN 1 ELSE 0 END ASC,
|
||||
display_rank ASC,
|
||||
@@ -669,7 +679,7 @@ async function listGames(currentUserId = '') {
|
||||
}
|
||||
|
||||
async function findGameById(id) {
|
||||
const rows = await query('SELECT id, name, thumbnail_src, display_rank, created_at FROM games WHERE id = ? LIMIT 1', [id])
|
||||
const rows = await query('SELECT id, name, thumbnail_src, is_public, display_rank, created_at FROM games WHERE id = ? LIMIT 1', [id])
|
||||
return mapGameRow(rows[0])
|
||||
}
|
||||
|
||||
@@ -702,11 +712,12 @@ async function getGameDetail(gameId) {
|
||||
return { game, items }
|
||||
}
|
||||
|
||||
async function createGame({ id, name }) {
|
||||
await query('INSERT INTO games (id, name, thumbnail_src, display_rank, created_at) VALUES (?, ?, ?, ?, ?)', [
|
||||
async function createGame({ id, name, isPublic = true }) {
|
||||
await query('INSERT INTO games (id, name, thumbnail_src, is_public, display_rank, created_at) VALUES (?, ?, ?, ?, ?, ?)', [
|
||||
id,
|
||||
name,
|
||||
'',
|
||||
isPublic ? 1 : 0,
|
||||
null,
|
||||
now(),
|
||||
])
|
||||
@@ -718,6 +729,11 @@ async function updateGameThumbnail(gameId, thumbnailSrc) {
|
||||
return findGameById(gameId)
|
||||
}
|
||||
|
||||
async function updateGameVisibility(gameId, isPublic) {
|
||||
await query('UPDATE games SET is_public = ? WHERE id = ?', [isPublic ? 1 : 0, gameId])
|
||||
return findGameById(gameId)
|
||||
}
|
||||
|
||||
async function findImageAssetByHash(contentHash) {
|
||||
const rows = await query(
|
||||
'SELECT id, content_hash, src, label_override, mime_type, byte_size, original_byte_size, width, height, created_at FROM image_assets WHERE content_hash = ? LIMIT 1',
|
||||
@@ -2144,6 +2160,7 @@ module.exports = {
|
||||
getGameDetail,
|
||||
createGame,
|
||||
updateGameThumbnail,
|
||||
updateGameVisibility,
|
||||
findImageAssetByHash,
|
||||
findImageAssetBySrc,
|
||||
findImageAssetById,
|
||||
|
||||
@@ -14,6 +14,7 @@ const {
|
||||
createGame,
|
||||
listGames,
|
||||
updateGameThumbnail,
|
||||
updateGameVisibility,
|
||||
createGameItem,
|
||||
updateGameItemLabel,
|
||||
updateGameItemDisplayOrder,
|
||||
@@ -109,13 +110,14 @@ router.post('/games', requireAdmin, async (req, res) => {
|
||||
const schema = z.object({
|
||||
id: z.string().min(1),
|
||||
name: z.string().min(1).max(60),
|
||||
isPublic: z.boolean().optional().default(false),
|
||||
thumbnailSrc: z.string().max(255).optional().default(''),
|
||||
})
|
||||
const parsed = schema.safeParse(req.body)
|
||||
if (!parsed.success) return res.status(400).json({ error: 'bad_request' })
|
||||
const exists = await findGameById(parsed.data.id)
|
||||
if (exists) return res.status(409).json({ error: 'game_id_taken' })
|
||||
const game = await createGame({ id: parsed.data.id, name: parsed.data.name })
|
||||
const game = await createGame({ id: parsed.data.id, name: parsed.data.name, isPublic: parsed.data.isPublic })
|
||||
if (parsed.data.thumbnailSrc) {
|
||||
const copiedThumb = await copyUploadIntoGameAsset(parsed.data.thumbnailSrc)
|
||||
await updateGameThumbnail(game.id, copiedThumb)
|
||||
@@ -123,6 +125,20 @@ router.post('/games', requireAdmin, async (req, res) => {
|
||||
res.json({ game: await findGameById(game.id) })
|
||||
})
|
||||
|
||||
router.patch('/games/:gameId', requireAdmin, async (req, res) => {
|
||||
const schema = z.object({
|
||||
isPublic: z.boolean(),
|
||||
})
|
||||
const parsed = schema.safeParse(req.body)
|
||||
if (!parsed.success) return res.status(400).json({ error: 'bad_request' })
|
||||
|
||||
const game = await findGameById(req.params.gameId)
|
||||
if (!game) return res.status(404).json({ error: 'not_found' })
|
||||
|
||||
const updated = await updateGameVisibility(game.id, parsed.data.isPublic)
|
||||
res.json({ game: updated })
|
||||
})
|
||||
|
||||
router.patch('/games/display-order', requireAdmin, async (req, res) => {
|
||||
const schema = z.object({
|
||||
gameIds: z.array(z.string().min(1)).max(50),
|
||||
@@ -130,7 +146,7 @@ router.patch('/games/display-order', requireAdmin, async (req, res) => {
|
||||
const parsed = schema.safeParse(req.body)
|
||||
if (!parsed.success) return res.status(400).json({ error: 'bad_request' })
|
||||
|
||||
const games = await listGames()
|
||||
const games = await listGames('', { includePrivate: true })
|
||||
const validGameIds = new Set(games.map((game) => game.id))
|
||||
const filteredIds = parsed.data.gameIds.filter((gameId) => validGameIds.has(gameId))
|
||||
const updatedGames = await updateGameDisplayOrder(filteredIds)
|
||||
@@ -516,7 +532,7 @@ function pickTemplateRequestItems(templateRequest, itemIds = [], itemLabels = {}
|
||||
}
|
||||
|
||||
async function createGameTemplateFromTierList({ tierList, gameId, gameName }) {
|
||||
await createGame({ id: gameId, name: gameName })
|
||||
await createGame({ id: gameId, name: gameName, isPublic: false })
|
||||
if (tierList.thumbnailSrc) {
|
||||
const copiedThumb = await copyUploadIntoGameAsset(tierList.thumbnailSrc)
|
||||
await updateGameThumbnail(gameId, copiedThumb)
|
||||
@@ -539,7 +555,7 @@ async function createGameTemplateFromTierList({ tierList, gameId, gameName }) {
|
||||
}
|
||||
|
||||
async function createGameTemplateFromRequest({ templateRequest, gameId, gameName }) {
|
||||
await createGame({ id: gameId, name: gameName })
|
||||
await createGame({ id: gameId, name: gameName, isPublic: false })
|
||||
|
||||
if (templateRequest.thumbnailSrc) {
|
||||
const copiedThumb = await copyUploadIntoGameAsset(templateRequest.thumbnailSrc)
|
||||
@@ -697,12 +713,19 @@ router.post('/template-requests/:requestId/approve', requireAdmin, async (req, r
|
||||
})
|
||||
|
||||
router.post('/template-requests/:requestId/review', requireAdmin, async (req, res) => {
|
||||
const templateRequest = await findTemplateRequestById(req.params.requestId)
|
||||
let templateRequest = await findTemplateRequestById(req.params.requestId)
|
||||
if (!templateRequest) return res.status(404).json({ error: 'not_found' })
|
||||
if (templateRequest.status === 'completed' || templateRequest.status === 'rejected' || templateRequest.status === 'approved') {
|
||||
return res.status(409).json({ error: 'request_already_handled' })
|
||||
}
|
||||
|
||||
if (templateRequest.type === 'create' && templateRequest.targetGameId && !templateRequest.targetGameName) {
|
||||
templateRequest = await updateTemplateRequestTargetGame({
|
||||
id: templateRequest.id,
|
||||
targetGameId: '',
|
||||
})
|
||||
}
|
||||
|
||||
if (templateRequest.status === 'reviewing') {
|
||||
return res.json({ request: templateRequest })
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const { requireAuth } = require('../middleware/auth')
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
const games = await listGames(req.session?.userId || '')
|
||||
const games = await listGames(req.session?.userId || '', { includePrivate: !!req.session?.isAdmin })
|
||||
res.json({ games })
|
||||
})
|
||||
|
||||
@@ -30,6 +30,7 @@ router.delete('/:gameId/favorite', requireAuth, async (req, res) => {
|
||||
router.get('/:gameId', async (req, res) => {
|
||||
const detail = await getGameDetail(req.params.gameId)
|
||||
if (!detail) return res.status(404).json({ error: 'not_found' })
|
||||
if (!detail.game.isPublic && !req.session?.isAdmin) return res.status(404).json({ error: 'not_found' })
|
||||
res.json({ game: detail.game, items: detail.items })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user