사이트 설정 로고와 사용자 설정 레이아웃 정리

This commit is contained in:
2026-05-13 15:42:03 +09:00
parent bebf7ee1c9
commit 52f22b4ff1
17 changed files with 372 additions and 395 deletions

View File

@@ -74,6 +74,8 @@ const mapSiteSettingsRow = (row) => ({
description: row.description,
siteUrl: row.site_url,
logoText: row.logo_text,
logoUrl: row.logo_url || '',
faviconUrl: row.favicon_url || '',
copyrightText: row.copyright_text,
updatedAt: row.updated_at.toISOString()
})
@@ -749,6 +751,8 @@ export const updateSiteSettings = async (input) => {
description,
site_url,
logo_text,
logo_url,
favicon_url,
copyright_text,
updated_at
)
@@ -757,7 +761,9 @@ export const updateSiteSettings = async (input) => {
${input.title},
${input.description},
${input.siteUrl},
${input.logoText},
${input.logoText || '井'},
${input.logoUrl || ''},
${input.faviconUrl || ''},
${input.copyrightText},
now()
)
@@ -767,6 +773,8 @@ export const updateSiteSettings = async (input) => {
description = EXCLUDED.description,
site_url = EXCLUDED.site_url,
logo_text = EXCLUDED.logo_text,
logo_url = EXCLUDED.logo_url,
favicon_url = EXCLUDED.favicon_url,
copyright_text = EXCLUDED.copyright_text,
updated_at = now()
RETURNING *
@@ -775,6 +783,42 @@ export const updateSiteSettings = async (input) => {
return mapSiteSettingsRow(rows[0])
}
/**
* 사이트 로고 URL을 수정한다.
* @param {{ logoUrl: string, faviconUrl: string }} input - 로고 URL
* @returns {Promise<Object>} 수정된 사이트 설정
*/
export const updateSiteLogo = async (input) => {
const sql = getPostgresClient()
if (!sql) {
throw new Error('DATABASE_REQUIRED')
}
const rows = await sql`
INSERT INTO site_settings (
id,
logo_url,
favicon_url,
updated_at
)
VALUES (
1,
${input.logoUrl},
${input.faviconUrl},
now()
)
ON CONFLICT (id) DO UPDATE
SET
logo_url = EXCLUDED.logo_url,
favicon_url = EXCLUDED.favicon_url,
updated_at = now()
RETURNING *
`
return mapSiteSettingsRow(rows[0])
}
/**
* 네비게이션 항목 목록 조회
* @param {Object} options - 조회 옵션

View File

@@ -0,0 +1,118 @@
import { mkdir, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { createError, readMultipartFormData } from 'h3'
import sharp from 'sharp'
import { requireAdminSession } from '../../../../utils/admin-auth'
import { updateSiteLogo } from '../../../../repositories/content-repository'
import { upsertMediaMetadataCategory } from '../../../../utils/media-library'
const allowedImageTypes = new Set(['image/jpeg', 'image/png', 'image/webp'])
/**
* 숫자 설정값을 최소/최대 범위로 보정한다.
* @param {number} value - 원본 값
* @param {number} minimum - 최소값
* @param {number} maximum - 최대값
* @returns {number} 보정된 값
*/
const clampNumber = (value, minimum, maximum) => {
if (!Number.isFinite(value)) {
return minimum
}
if (value < minimum) {
return minimum
}
if (value > maximum) {
return maximum
}
return Math.round(value)
}
/**
* 사이트 로고 업로드 API
* @param {import('h3').H3Event} event - 요청 이벤트
* @returns {Promise<Object>} 수정된 사이트 설정
*/
export default defineEventHandler(async (event) => {
requireAdminSession(event)
const config = useRuntimeConfig()
const maxFileSize = Number(config.maxFileSize || 10485760)
const logoSize = clampNumber(Number(config.siteLogoSize || 512), 128, 2048)
const formData = await readMultipartFormData(event)
const file = (formData || []).find((part) => part.name === 'file' && part.filename)
if (!file) {
throw createError({
statusCode: 400,
message: '업로드할 로고 이미지가 없습니다.'
})
}
if (!allowedImageTypes.has(file.type)) {
throw createError({
statusCode: 400,
message: 'JPG, PNG, WebP 이미지만 로고로 사용할 수 있습니다.'
})
}
if (file.data.length > maxFileSize) {
throw createError({
statusCode: 413,
message: '업로드 가능한 파일 크기를 초과했습니다.'
})
}
const metadata = await sharp(file.data).metadata()
if (!metadata.width || !metadata.height) {
throw createError({
statusCode: 400,
message: '이미지 메타데이터를 읽을 수 없습니다.'
})
}
const uploadBaseUrl = String(config.uploadDir || '/uploads').replace(/\/+$/g, '') || '/uploads'
const publicBasePath = uploadBaseUrl.replace(/^\/+/, '')
const directoryPath = join(process.cwd(), 'public', publicBasePath, 'system')
const logoPath = join(directoryPath, 'logo.webp')
const faviconPath = join(directoryPath, 'favicon.png')
const logoUrl = `${uploadBaseUrl}/system/logo.webp`
const faviconUrl = `${uploadBaseUrl}/system/favicon.png`
await mkdir(directoryPath, { recursive: true })
const logoBuffer = await sharp(file.data)
.rotate()
.resize({
width: logoSize,
height: logoSize,
fit: 'cover',
position: 'centre'
})
.webp({ quality: 90 })
.toBuffer()
const faviconBuffer = await sharp(file.data)
.rotate()
.resize({
width: 256,
height: 256,
fit: 'cover',
position: 'centre'
})
.png()
.toBuffer()
await writeFile(logoPath, logoBuffer)
await writeFile(faviconPath, faviconBuffer)
await upsertMediaMetadataCategory(logoUrl, '시스템')
await upsertMediaMetadataCategory(faviconUrl, '시스템')
return updateSiteLogo({
logoUrl,
faviconUrl
})
})

View File

@@ -2,9 +2,11 @@ import { z } from 'zod'
export const adminSiteSettingsInputSchema = z.object({
title: z.string().trim().min(1),
description: z.string().trim().default(''),
description: z.string().trim().min(1),
siteUrl: z.string().trim().url(),
logoText: z.string().trim().min(1).max(8),
logoText: z.string().trim().max(8).optional().default('井'),
logoUrl: z.string().trim().max(500).optional().default(''),
faviconUrl: z.string().trim().max(500).optional().default(''),
copyrightText: z.string().trim().min(1)
})

View File

@@ -11,6 +11,8 @@ export const getDefaultSiteSettings = () => {
description: 'sori.studio 개인 블로그',
siteUrl: config.public.siteUrl || 'https://sori.studio',
logoText: '井',
logoUrl: '',
faviconUrl: '',
copyrightText: `©${new Date().getFullYear()} ${title}`,
updatedAt: null
}