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