사이트 로고 캐시 갱신 보강
This commit is contained in:
@@ -31,6 +31,14 @@ const clampNumber = (value, minimum, maximum) => {
|
||||
return Math.round(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* 시스템 로고 파일명에 사용할 짧은 고유 접미사를 만든다.
|
||||
* @returns {string} 파일명 접미사
|
||||
*/
|
||||
const createSystemAssetSuffix = () => `${new Date().toISOString()
|
||||
.replace(/[-:]/g, '')
|
||||
.replace(/\.\d{3}Z$/g, '')}-${Math.random().toString(36).slice(2, 8)}`
|
||||
|
||||
/**
|
||||
* 사이트 로고 업로드 API
|
||||
* @param {import('h3').H3Event} event - 요청 이벤트
|
||||
@@ -77,10 +85,13 @@ export default defineEventHandler(async (event) => {
|
||||
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`
|
||||
const assetSuffix = createSystemAssetSuffix()
|
||||
const logoFileName = `logo-${assetSuffix}.webp`
|
||||
const faviconFileName = `favicon-${assetSuffix}.png`
|
||||
const logoPath = join(directoryPath, logoFileName)
|
||||
const faviconPath = join(directoryPath, faviconFileName)
|
||||
const logoUrl = `${uploadBaseUrl}/system/${logoFileName}`
|
||||
const faviconUrl = `${uploadBaseUrl}/system/${faviconFileName}`
|
||||
|
||||
await mkdir(directoryPath, { recursive: true })
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { readdir, rename, rm, stat } from 'node:fs/promises'
|
||||
import { basename, dirname, extname, join, relative } from 'node:path'
|
||||
import { createError } from 'h3'
|
||||
import { listAdminPosts, listPages } from '../repositories/content-repository'
|
||||
import { getSiteSettings, listAdminPosts, listPages } from '../repositories/content-repository'
|
||||
import { getPostgresClient } from '../repositories/postgres-client'
|
||||
|
||||
const uploadRoot = join(process.cwd(), 'public', 'uploads')
|
||||
@@ -478,6 +478,46 @@ const getMediaUsage = (url, posts, pages) => {
|
||||
return [...postUsages, ...pageUsages]
|
||||
}
|
||||
|
||||
/**
|
||||
* 사이트 설정에서 미디어 URL 사용처 조회
|
||||
* @param {string} url - 미디어 URL
|
||||
* @param {Object} siteSettings - 사이트 설정
|
||||
* @returns {Array<Object>} 사용처 목록
|
||||
*/
|
||||
const getSiteSettingsMediaUsage = (url, siteSettings) => {
|
||||
const usages = []
|
||||
|
||||
if (siteSettings.logoUrl === url) {
|
||||
usages.push({
|
||||
type: 'settings',
|
||||
typeLabel: '사이트 설정',
|
||||
id: 'site-logo',
|
||||
title: '사이트 로고',
|
||||
adminUrl: '/admin/settings',
|
||||
publicUrl: '/',
|
||||
status: 'system',
|
||||
location: 'logoUrl',
|
||||
label: '사이트 로고'
|
||||
})
|
||||
}
|
||||
|
||||
if (siteSettings.faviconUrl === url) {
|
||||
usages.push({
|
||||
type: 'settings',
|
||||
typeLabel: '사이트 설정',
|
||||
id: 'site-favicon',
|
||||
title: '파비콘',
|
||||
adminUrl: '/admin/settings',
|
||||
publicUrl: '/',
|
||||
status: 'system',
|
||||
location: 'faviconUrl',
|
||||
label: '파비콘'
|
||||
})
|
||||
}
|
||||
|
||||
return usages
|
||||
}
|
||||
|
||||
/**
|
||||
* 미디어 목록 조회
|
||||
* @returns {Promise<Array<Object>>} 미디어 항목 목록
|
||||
@@ -485,9 +525,10 @@ const getMediaUsage = (url, posts, pages) => {
|
||||
export const listMediaItems = async () => {
|
||||
const items = await readMediaDirectory(uploadRoot)
|
||||
const metadataMap = await getMediaMetadataMap()
|
||||
const [posts, pages] = await Promise.all([
|
||||
const [posts, pages, siteSettings] = await Promise.all([
|
||||
listAdminPosts(),
|
||||
listPages()
|
||||
listPages(),
|
||||
getSiteSettings()
|
||||
])
|
||||
const avatarOwnerByUrl = await getAvatarOwnersByUrls(items.map((item) => item.url))
|
||||
const itemsWithUsage = items.map((item) => {
|
||||
@@ -498,7 +539,10 @@ export const listMediaItems = async () => {
|
||||
return {
|
||||
...item,
|
||||
category,
|
||||
usage: getMediaUsage(item.url, posts, pages),
|
||||
usage: [
|
||||
...getMediaUsage(item.url, posts, pages),
|
||||
...getSiteSettingsMediaUsage(item.url, siteSettings)
|
||||
],
|
||||
avatarOwner
|
||||
}
|
||||
})
|
||||
@@ -615,11 +659,15 @@ export const updateMediaCategories = async (urls, category) => {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export const deleteMediaItem = async (url) => {
|
||||
const [posts, pages] = await Promise.all([
|
||||
const [posts, pages, siteSettings] = await Promise.all([
|
||||
listAdminPosts(),
|
||||
listPages()
|
||||
listPages(),
|
||||
getSiteSettings()
|
||||
])
|
||||
const usage = getMediaUsage(url, posts, pages)
|
||||
const usage = [
|
||||
...getMediaUsage(url, posts, pages),
|
||||
...getSiteSettingsMediaUsage(url, siteSettings)
|
||||
]
|
||||
|
||||
if (usage.length) {
|
||||
throw createError({
|
||||
@@ -646,11 +694,15 @@ export const deleteMediaItem = async (url) => {
|
||||
* @returns {Promise<Object>} 변경된 미디어 항목
|
||||
*/
|
||||
export const renameMediaItem = async (url, name) => {
|
||||
const [posts, pages] = await Promise.all([
|
||||
const [posts, pages, siteSettings] = await Promise.all([
|
||||
listAdminPosts(),
|
||||
listPages()
|
||||
listPages(),
|
||||
getSiteSettings()
|
||||
])
|
||||
const usage = getMediaUsage(url, posts, pages)
|
||||
const usage = [
|
||||
...getMediaUsage(url, posts, pages),
|
||||
...getSiteSettingsMediaUsage(url, siteSettings)
|
||||
]
|
||||
|
||||
if (usage.length) {
|
||||
throw createError({
|
||||
|
||||
Reference in New Issue
Block a user