릴리스: v0.1.9 MariaDB 전용 코드베이스 정리

This commit is contained in:
2026-03-19 15:20:13 +09:00
parent 0c30ae5cb3
commit beaec9326b
18 changed files with 632 additions and 1067 deletions

View File

@@ -1,5 +1,5 @@
<script setup>
import { computed, onMounted, ref } from 'vue'
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { api } from '../lib/api'
import { toApiUrl } from '../lib/runtime'
import { useAuthStore } from '../stores/auth'
@@ -8,8 +8,10 @@ const auth = useAuthStore()
const isAdmin = computed(() => !!auth.user?.isAdmin)
const games = ref([])
const adminMode = ref('existing')
const selectedGameId = ref('')
const selectedGame = ref(null)
const error = ref('')
const success = ref('')
@@ -19,15 +21,22 @@ const newGameName = ref('')
const uploadLabel = ref('')
const uploadFile = ref(null)
const thumbFile = ref(null)
const itemPreviewUrl = ref('')
const thumbPreviewUrl = ref('')
onMounted(async () => {
await auth.refresh()
await refreshGames()
})
onUnmounted(() => {
clearPreviewUrl('item')
clearPreviewUrl('thumb')
})
const hasSelectedGame = computed(() => !!selectedGame.value?.game?.id)
async function refreshGames() {
error.value = ''
success.value = ''
try {
const data = await api.listGames()
games.value = data.games || []
@@ -36,13 +45,43 @@ async function refreshGames() {
}
}
async function loadGame() {
function resetMessages() {
error.value = ''
success.value = ''
}
function setMode(mode) {
resetMessages()
adminMode.value = mode
selectedGameId.value = ''
selectedGame.value = null
newGameId.value = ''
newGameName.value = ''
uploadLabel.value = ''
uploadFile.value = null
thumbFile.value = null
clearPreviewUrl('item')
clearPreviewUrl('thumb')
}
function clearPreviewUrl(type) {
if (type === 'item' && itemPreviewUrl.value) {
URL.revokeObjectURL(itemPreviewUrl.value)
itemPreviewUrl.value = ''
}
if (type === 'thumb' && thumbPreviewUrl.value) {
URL.revokeObjectURL(thumbPreviewUrl.value)
thumbPreviewUrl.value = ''
}
}
async function loadGame() {
resetMessages()
if (!selectedGameId.value) {
selectedGame.value = null
return
}
try {
const data = await api.getGame(selectedGameId.value)
selectedGame.value = data
@@ -52,8 +91,7 @@ async function loadGame() {
}
async function createGame() {
error.value = ''
success.value = ''
resetMessages()
try {
const res = await fetch(toApiUrl('/api/admin/games'), {
method: 'POST',
@@ -62,58 +100,41 @@ async function createGame() {
body: JSON.stringify({ id: newGameId.value, name: newGameName.value }),
})
if (!res.ok) throw new Error('failed')
newGameId.value = ''
newGameName.value = ''
const data = await res.json()
await refreshGames()
selectedGameId.value = ''
selectedGame.value = null
success.value = '게임이 생성됐어요. 목록에서 선택한 뒤 썸네일과 아이템을 등록해주세요.'
adminMode.value = 'existing'
selectedGameId.value = data.game.id
await loadGame()
success.value = '게임이 생성됐어요. 이어서 썸네일과 아이템을 관리할 수 있어요.'
} catch (e) {
error.value = '게임 생성 실패(관리자 권한/중복 ID 확인)'
}
}
async function uploadItem() {
error.value = ''
success.value = ''
if (!uploadFile.value) {
error.value = '아이템 파일을 선택해주세요.'
return
}
try {
const fd = new FormData()
fd.append('label', uploadLabel.value || 'image')
fd.append('image', uploadFile.value)
const res = await fetch(toApiUrl(`/api/admin/games/${encodeURIComponent(selectedGameId.value)}/images`), {
method: 'POST',
credentials: 'include',
body: fd,
})
if (!res.ok) throw new Error('failed')
uploadLabel.value = ''
uploadFile.value = null
await loadGame()
success.value = '아이템이 추가됐어요.'
} catch (e) {
error.value = '아이템 추가 실패(관리자 권한/파일 크기 확인)'
function onThumb(event) {
thumbFile.value = event.target.files && event.target.files[0] ? event.target.files[0] : null
clearPreviewUrl('thumb')
if (thumbFile.value) {
thumbPreviewUrl.value = URL.createObjectURL(thumbFile.value)
}
}
function onFile(e) {
uploadFile.value = e.target.files && e.target.files[0] ? e.target.files[0] : null
}
function onThumb(e) {
thumbFile.value = e.target.files && e.target.files[0] ? e.target.files[0] : null
function onFile(event) {
uploadFile.value = event.target.files && event.target.files[0] ? event.target.files[0] : null
clearPreviewUrl('item')
if (uploadFile.value) {
itemPreviewUrl.value = URL.createObjectURL(uploadFile.value)
}
}
async function uploadThumbnail() {
error.value = ''
success.value = ''
if (!thumbFile.value) {
resetMessages()
if (!thumbFile.value || !selectedGameId.value) {
error.value = '썸네일 파일을 선택해주세요.'
return
}
try {
const fd = new FormData()
fd.append('thumbnail', thumbFile.value)
@@ -123,7 +144,9 @@ async function uploadThumbnail() {
body: fd,
})
if (!res.ok) throw new Error('failed')
thumbFile.value = null
clearPreviewUrl('thumb')
await refreshGames()
await loadGame()
success.value = '썸네일이 반영됐어요.'
@@ -131,69 +154,190 @@ async function uploadThumbnail() {
error.value = '썸네일 업로드 실패(관리자 권한/파일 크기 확인)'
}
}
async function uploadItem() {
resetMessages()
if (!uploadFile.value || !selectedGameId.value) {
error.value = '아이템 파일을 선택해주세요.'
return
}
try {
const fd = new FormData()
fd.append('label', uploadLabel.value || 'item')
fd.append('image', uploadFile.value)
const res = await fetch(toApiUrl(`/api/admin/games/${encodeURIComponent(selectedGameId.value)}/images`), {
method: 'POST',
credentials: 'include',
body: fd,
})
if (!res.ok) throw new Error('failed')
uploadLabel.value = ''
uploadFile.value = null
clearPreviewUrl('item')
await loadGame()
success.value = '아이템이 추가됐어요.'
} catch (e) {
error.value = '아이템 추가 실패(관리자 권한/파일 크기 확인)'
}
}
async function removeItem(itemId) {
resetMessages()
try {
const res = await fetch(
toApiUrl(`/api/admin/games/${encodeURIComponent(selectedGameId.value)}/items/${encodeURIComponent(itemId)}`),
{
method: 'DELETE',
credentials: 'include',
}
)
if (!res.ok) throw new Error('failed')
await loadGame()
success.value = '아이템을 삭제했어요.'
} catch (e) {
error.value = '아이템 삭제에 실패했어요.'
}
}
async function removeGame() {
resetMessages()
if (!selectedGameId.value || !selectedGame.value?.game) return
const ok = window.confirm(`"${selectedGame.value.game.name}" 게임을 삭제할까요? 관련 아이템과 티어표도 함께 삭제됩니다.`)
if (!ok) return
try {
const res = await fetch(toApiUrl(`/api/admin/games/${encodeURIComponent(selectedGameId.value)}`), {
method: 'DELETE',
credentials: 'include',
})
if (!res.ok) throw new Error('failed')
const deletedName = selectedGame.value.game.name
selectedGameId.value = ''
selectedGame.value = null
clearPreviewUrl('item')
clearPreviewUrl('thumb')
await refreshGames()
success.value = `${deletedName} 게임을 삭제했어요.`
} catch (e) {
error.value = '게임 삭제에 실패했어요.'
}
}
const displayThumbnailUrl = computed(() => {
if (thumbPreviewUrl.value) return thumbPreviewUrl.value
if (selectedGame.value?.game?.thumbnailSrc) return toApiUrl(selectedGame.value.game.thumbnailSrc)
return ''
})
</script>
<template>
<section class="wrap">
<h2 class="title">관리자</h2>
<div class="card">
<div class="desc">게임 생성 선택한 게임에만 썸네일과 관리자 아이템을 등록할 있습니다.</div>
<div class="desc">먼저 작업 방식을 고르고, 다음 선택한 게임의 정보만 집중해서 관리합니다.</div>
<div v-if="!auth.user" class="warn">로그인이 필요해요.</div>
<div v-else-if="!isAdmin" class="warn"> 계정은 관리자 권한이 없어요.</div>
<div v-if="error" class="error">{{ error }}</div>
<div v-if="success" class="success">{{ success }}</div>
<div class="grid">
<div class="panel">
<div class="panel__title">게임 선택</div>
<select v-model="selectedGameId" class="select" :disabled="!isAdmin" @change="loadGame">
<option value="">게임을 선택해주세요</option>
<option v-for="g in games" :key="g.id" :value="g.id">{{ g.name }} ({{ g.id }})</option>
</select>
<div class="panel__title" style="margin-top: 14px"> 게임 추가</div>
<input v-model="newGameId" class="input" placeholder="game id (영문/숫자)" :disabled="!isAdmin" />
<input v-model="newGameName" class="input" placeholder="게임 이름" :disabled="!isAdmin" />
<button class="btn" :disabled="!isAdmin" @click="createGame">게임 생성</button>
<template v-else>
<div class="modeTabs">
<button class="modeTab" :class="{ 'modeTab--active': adminMode === 'existing' }" @click="setMode('existing')">
등록된 게임 선택
</button>
<button class="modeTab" :class="{ 'modeTab--active': adminMode === 'new' }" @click="setMode('new')">
게임 추가
</button>
</div>
<div v-if="selectedGame" class="panel">
<div class="panel__title">선택된 게임</div>
<div class="selectedGame">
<div v-if="error" class="error">{{ error }}</div>
<div v-if="success" class="success">{{ success }}</div>
<div class="panel panel--compact">
<template v-if="adminMode === 'existing'">
<div class="panel__title">등록된 게임 선택</div>
<select v-model="selectedGameId" class="select" @change="loadGame">
<option value="">게임을 선택해주세요</option>
<option v-for="game in games" :key="game.id" :value="game.id">{{ game.name }} ({{ game.id }})</option>
</select>
<div class="hint">게임을 고르면 아래에서 썸네일, 아이템 목록, 삭제 작업을 관리할 있어요.</div>
</template>
<template v-else>
<div class="panel__title"> 게임 정보 입력</div>
<input v-model="newGameId" class="input" placeholder="game id (영문/숫자)" />
<input v-model="newGameName" class="input" placeholder="게임 이름" />
<button class="btn btn--primary" @click="createGame">게임 생성</button>
</template>
</div>
<div v-if="hasSelectedGame" class="panel panel--detail">
<div class="detailHead">
<div>
<div class="panel__title">선택된 게임 정보</div>
<div class="selectedGame__name">{{ selectedGame.game.name }}</div>
<div class="selectedGame__id">{{ selectedGame.game.id }}</div>
</div>
<img
v-if="selectedGame.game.thumbnailSrc"
class="selectedThumb"
:src="toApiUrl(selectedGame.game.thumbnailSrc)"
:alt="selectedGame.game.name"
/>
<div class="detailHead__actions">
<button class="btn btn--danger" @click="removeGame">게임 삭제</button>
</div>
</div>
<div class="panel__title" style="margin-top: 14px">게임 썸네일 업로드</div>
<div class="hint"> 화면의 게임 카드에 바로 반영되는 대표 이미지입니다.</div>
<input type="file" accept="image/*" class="inputFile" :disabled="!isAdmin" @change="onThumb" />
<button class="btn" :disabled="!isAdmin" @click="uploadThumbnail">썸네일 업로드</button>
<div class="section">
<div class="section__title">썸네일</div>
<div class="uploadPreviewCard uploadPreviewCard--wide">
<img
v-if="displayThumbnailUrl"
class="selectedThumb"
:src="displayThumbnailUrl"
:alt="selectedGame.game.name"
/>
<div v-else class="selectedThumb selectedThumb--empty">16:9 미리보기</div>
<div class="uploadPreviewMeta">
<div class="uploadPreviewTitle">대표 썸네일</div>
<div class="uploadPreviewDesc">
파일을 선택하면 먼저 미리보기로 확인되고, 업로드 버튼을 눌렀을 실제 저장됩니다.
</div>
</div>
</div>
<input type="file" accept="image/*" class="inputFile" @change="onThumb" />
<button class="btn" @click="uploadThumbnail">썸네일 업로드</button>
</div>
<div class="panel__title" style="margin-top: 14px">아이템 추가</div>
<div class="hint">관리자가 지정한 아이템 목록에 포함됩니다.</div>
<input v-model="uploadLabel" class="input" placeholder="아이템 이름" :disabled="!isAdmin" />
<input type="file" accept="image/*" class="inputFile" :disabled="!isAdmin" @change="onFile" />
<button class="btn" :disabled="!isAdmin" @click="uploadItem">아이템 추가</button>
<div class="section">
<div class="section__title">아이템 추가</div>
<div class="itemComposer">
<div class="itemComposer__form">
<input v-model="uploadLabel" class="input" placeholder="아이템 이름" />
<input type="file" accept="image/*" class="inputFile" @change="onFile" />
<button class="btn" @click="uploadItem">아이템 추가</button>
</div>
<div class="itemPreviewCard">
<div class="itemPreviewFrame">
<img v-if="itemPreviewUrl" class="itemPreviewImage" :src="itemPreviewUrl" alt="item preview" />
<div v-else class="itemPreviewEmpty">1:1 미리보기</div>
</div>
<div class="thumbLabel thumbLabel--preview">{{ uploadLabel || '아이템 이름 미리보기' }}</div>
</div>
</div>
</div>
<div class="panel__title" style="margin-top: 14px">현재 아이템 목록</div>
<div v-if="!selectedGame?.items?.length" class="hint">아직 등록된 아이템 없어요.</div>
<div v-else class="thumbGrid">
<div v-for="img in selectedGame.items" :key="img.id" class="thumbCard">
<img class="thumb" :src="toApiUrl(img.src)" :alt="img.label" />
<div class="thumbLabel">{{ img.label }}</div>
<div class="section">
<div class="section__title">현재 아이템 목록</div>
<div v-if="!selectedGame?.items?.length" class="hint">아직 등록된 아이템이 없어요.</div>
<div v-else class="thumbGrid">
<div v-for="item in selectedGame.items" :key="item.id" class="thumbCard">
<img class="thumb" :src="toApiUrl(item.src)" :alt="item.label" />
<div class="thumbLabel">{{ item.label }}</div>
<button class="btn btn--danger btn--small" @click="removeItem(item.id)">아이템 삭제</button>
</div>
</div>
</div>
</div>
</div>
</template>
</div>
</section>
</template>
@@ -217,47 +361,81 @@ async function uploadThumbnail() {
opacity: 0.82;
line-height: 1.5;
}
.warn {
margin-top: 10px;
padding: 10px 12px;
border-radius: 12px;
border: 1px solid rgba(245, 158, 11, 0.35);
background: rgba(245, 158, 11, 0.14);
}
.error {
margin-top: 10px;
padding: 10px 12px;
border-radius: 12px;
border: 1px solid rgba(239, 68, 68, 0.3);
background: rgba(239, 68, 68, 0.12);
}
.warn,
.error,
.success {
margin-top: 10px;
padding: 10px 12px;
border-radius: 12px;
}
.warn {
border: 1px solid rgba(245, 158, 11, 0.35);
background: rgba(245, 158, 11, 0.14);
}
.error {
border: 1px solid rgba(239, 68, 68, 0.3);
background: rgba(239, 68, 68, 0.12);
}
.success {
border: 1px solid rgba(52, 211, 153, 0.32);
background: rgba(52, 211, 153, 0.14);
}
.grid {
margin-top: 12px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
.modeTabs {
margin-top: 14px;
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.modeTab {
padding: 10px 14px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.14);
background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.92);
cursor: pointer;
font-weight: 800;
}
.modeTab--active {
background: rgba(96, 165, 250, 0.2);
}
.panel {
margin-top: 14px;
border: 1px solid rgba(255, 255, 255, 0.12);
background: rgba(0, 0, 0, 0.12);
border-radius: 16px;
padding: 12px;
padding: 14px;
}
.panel__title {
.panel--compact {
max-width: 640px;
}
.panel__title,
.section__title {
font-weight: 900;
margin-bottom: 8px;
}
.hint {
opacity: 0.78;
font-size: 13px;
margin-bottom: 10px;
.section {
margin-top: 18px;
padding-top: 18px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.uploadPreviewCard {
margin-top: 10px;
display: grid;
gap: 12px;
align-items: start;
}
.uploadPreviewCard--wide {
grid-template-columns: minmax(256px, 256px) minmax(0, 1fr);
}
.uploadPreviewMeta {
display: grid;
gap: 8px;
}
.uploadPreviewTitle {
font-weight: 900;
}
.uploadPreviewDesc {
opacity: 0.76;
line-height: 1.5;
}
.select,
.input {
@@ -269,11 +447,16 @@ async function uploadThumbnail() {
background: rgba(0, 0, 0, 0.18);
color: rgba(255, 255, 255, 0.92);
outline: none;
margin-bottom: 10px;
margin-top: 10px;
}
.hint {
margin-top: 10px;
opacity: 0.78;
font-size: 13px;
}
.inputFile {
width: 100%;
margin-bottom: 10px;
margin-top: 12px;
}
.btn {
margin-top: 12px;
@@ -285,25 +468,26 @@ async function uploadThumbnail() {
cursor: pointer;
font-weight: 800;
}
.btn:hover {
background: rgba(255, 255, 255, 0.08);
.btn--primary {
background: rgba(96, 165, 250, 0.2);
}
.thumbGrid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
.btn--danger {
background: rgba(239, 68, 68, 0.14);
border-color: rgba(239, 68, 68, 0.28);
}
.selectedGame {
.btn--small {
width: 100%;
}
.detailHead {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px;
border-radius: 14px;
border: 1px solid rgba(255, 255, 255, 0.12);
background: rgba(255, 255, 255, 0.04);
justify-content: space-between;
align-items: flex-start;
flex-wrap: wrap;
}
.selectedGame__name {
margin-top: 8px;
font-size: 22px;
font-weight: 900;
}
.selectedGame__id {
@@ -311,13 +495,68 @@ async function uploadThumbnail() {
opacity: 0.72;
word-break: break-all;
}
.detailHead__actions {
display: flex;
gap: 8px;
}
.thumbnailRow {
margin-top: 10px;
}
.selectedThumb {
width: 90px;
height: 90px;
width: 256px;
aspect-ratio: 16 / 9;
object-fit: cover;
border-radius: 16px;
border: 1px solid rgba(255, 255, 255, 0.12);
background: rgba(255, 255, 255, 0.04);
}
.selectedThumb--empty {
display: grid;
place-items: center;
color: rgba(255, 255, 255, 0.62);
}
.itemComposer {
margin-top: 10px;
display: grid;
grid-template-columns: minmax(0, 1fr) 180px;
gap: 16px;
align-items: start;
}
.itemComposer__form {
min-width: 0;
}
.itemPreviewCard {
padding: 10px;
border-radius: 14px;
border: 1px solid rgba(255, 255, 255, 0.12);
flex: none;
background: rgba(255, 255, 255, 0.04);
}
.itemPreviewFrame {
width: 100%;
aspect-ratio: 1 / 1;
border-radius: 12px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.12);
background: rgba(0, 0, 0, 0.18);
}
.itemPreviewImage {
width: 100%;
height: 100%;
object-fit: cover;
}
.itemPreviewEmpty {
width: 100%;
height: 100%;
display: grid;
place-items: center;
color: rgba(255, 255, 255, 0.62);
font-size: 13px;
}
.thumbGrid {
margin-top: 12px;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 12px;
}
.thumbCard {
border: 1px solid rgba(255, 255, 255, 0.12);
@@ -328,7 +567,7 @@ async function uploadThumbnail() {
}
.thumb {
width: 100%;
height: 92px;
aspect-ratio: 1 / 1;
object-fit: cover;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.12);
@@ -340,8 +579,22 @@ async function uploadThumbnail() {
opacity: 0.9;
word-break: break-word;
}
.thumbLabel--preview {
text-align: center;
}
@media (max-width: 980px) {
.grid {
.uploadPreviewCard--wide {
grid-template-columns: 1fr;
}
.itemComposer {
grid-template-columns: 1fr;
}
}
@media (max-width: 640px) {
.selectedThumb {
width: 100%;
}
.thumbGrid {
grid-template-columns: 1fr;
}
}