37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
import { readBody } from 'h3'
|
|
import { z } from 'zod'
|
|
import { requireAdminSession } from '../../../../utils/admin-auth'
|
|
import {
|
|
createPostExportJob,
|
|
queuePostExportJobRun
|
|
} from '../../../../repositories/post-export-repository'
|
|
|
|
const postExportJobInputSchema = z.object({
|
|
chunkSize: z.number().int().min(1).max(500).optional(),
|
|
retentionDays: z.number().int().min(1).max(100).optional()
|
|
}).default({})
|
|
|
|
/**
|
|
* 관리자 게시물 Export 작업 요청 API
|
|
* @param {import('h3').H3Event} event - 요청 이벤트
|
|
* @returns {Promise<Object>} 생성된 Export 작업
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const adminSession = requireAdminSession(event)
|
|
const input = postExportJobInputSchema.parse(await readBody(event))
|
|
|
|
const job = await createPostExportJob({
|
|
requestedBy: adminSession.userId,
|
|
requestedEmail: adminSession.email,
|
|
scope: 'all',
|
|
chunkSize: input.chunkSize,
|
|
retentionDays: input.retentionDays
|
|
})
|
|
|
|
if (job.status === 'queued') {
|
|
queuePostExportJobRun(job.id)
|
|
}
|
|
|
|
return job
|
|
})
|