페이지 커버 썸네일 최적화

This commit is contained in:
2026-07-02 10:09:39 +09:00
parent b26ae271d2
commit 3a4e39332a
20 changed files with 463 additions and 25 deletions

View File

@@ -1,12 +1,13 @@
import { createError, readBody } from 'h3'
import { requireAdminSession } from '../../../../utils/admin-auth'
import {
createPageCoverThumbnailForImageUrl,
createPostBodyThumbnailForImageUrl,
createPostThumbnailForImageUrl
} from '../../../../utils/post-thumbnail-image.js'
/**
* 게시물 이미지 파생 파일 재생성 API
* 이미지 파생 파일 재생성 API
* @param {import('h3').H3Event} event - 요청 이벤트
* @returns {Promise<{ thumbnailUrl: string }>} 생성된 썸네일 URL
*/
@@ -14,17 +15,21 @@ export default defineEventHandler(async (event) => {
requireAdminSession(event)
const body = await readBody(event)
const kind = body?.kind === 'body' ? 'body' : 'card'
const kind = ['body', 'pageCover'].includes(body?.kind) ? body.kind : 'card'
const thumbnailUrl = kind === 'body'
? await createPostBodyThumbnailForImageUrl(body?.url)
: await createPostThumbnailForImageUrl(body?.url)
: kind === 'pageCover'
? await createPageCoverThumbnailForImageUrl(body?.url)
: await createPostThumbnailForImageUrl(body?.url)
if (!thumbnailUrl) {
throw createError({
statusCode: 400,
message: kind === 'body'
? '본문 표시용 이미지를 만들 수 있는 게시물 이미지가 아닙니다.'
: '카드 썸네일을 만들 수 있는 게시물 대표 이미지가 아닙니다.'
: kind === 'pageCover'
? '페이지 커버 썸네일을 만들 수 있는 이미지가 아닙니다.'
: '카드 썸네일을 만들 수 있는 게시물 대표 이미지가 아닙니다.'
})
}