세션·로그인 제한, ZIP/업로드 스트리밍, CSP 최소 강제와 Report-Only, Playwright 격리 검증을 추가하고 미디어 목록을 reconcile 후 database 모드로 고정한다. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
import { createError, readBody } from 'h3'
|
|
import { requireAdminSession } from '../../../../utils/admin-auth'
|
|
import {
|
|
createPageCoverThumbnailForImageUrl,
|
|
createPostBodyThumbnailForImageUrl,
|
|
createPostThumbnailForImageUrl
|
|
} from '../../../../utils/post-thumbnail-image.js'
|
|
import { invalidateMediaItemsCache } from '../../../../utils/media-library.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', 'pageCover'].includes(body?.kind) ? body.kind : 'card'
|
|
const thumbnailUrl = kind === 'body'
|
|
? await createPostBodyThumbnailForImageUrl(body?.url)
|
|
: kind === 'pageCover'
|
|
? await createPageCoverThumbnailForImageUrl(body?.url)
|
|
: await createPostThumbnailForImageUrl(body?.url)
|
|
|
|
if (!thumbnailUrl) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: kind === 'body'
|
|
? '본문 표시용 이미지를 만들 수 있는 게시물 이미지가 아닙니다.'
|
|
: kind === 'pageCover'
|
|
? '페이지 커버 썸네일을 만들 수 있는 이미지가 아닙니다.'
|
|
: '카드 썸네일을 만들 수 있는 게시물 대표 이미지가 아닙니다.'
|
|
})
|
|
}
|
|
|
|
invalidateMediaItemsCache()
|
|
|
|
return {
|
|
thumbnailUrl
|
|
}
|
|
})
|