세션·로그인 제한, ZIP/업로드 스트리밍, CSP 최소 강제와 Report-Only, Playwright 격리 검증을 추가하고 미디어 목록을 reconcile 후 database 모드로 고정한다. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import { getQuery } from 'h3'
|
|
import { listPosts } from '../repositories/content-repository'
|
|
import { canAccessMembershipContent } from '../repositories/member-repository'
|
|
import { getVerifiedMemberSession } from '../utils/member-auth'
|
|
import {
|
|
DEFAULT_POST_LIST_PAGE_SIZE,
|
|
normalizeDisplayCount,
|
|
normalizeListPage
|
|
} from '../../lib/display-count-settings.js'
|
|
|
|
/**
|
|
* 공개 게시물 목록 API
|
|
* @param {import('h3').H3Event} event - 요청 이벤트
|
|
* @returns {Promise<Array>} 게시물 목록
|
|
*/
|
|
export default defineEventHandler(async (event) => {
|
|
const session = await getVerifiedMemberSession(event)
|
|
const includeMembership = await canAccessMembershipContent(session?.userId)
|
|
const query = getQuery(event)
|
|
const page = normalizeListPage(query.page)
|
|
const limit = normalizeDisplayCount(query.limit, DEFAULT_POST_LIST_PAGE_SIZE)
|
|
const offset = (page - 1) * limit
|
|
const paginated = query.paginated === '1'
|
|
|
|
const result = await listPosts({
|
|
includeMembership,
|
|
limit,
|
|
offset,
|
|
tagSlug: String(query.tag || '').trim(),
|
|
featuredOnly: query.featured === '1',
|
|
includeTotal: paginated
|
|
})
|
|
|
|
if (!paginated) {
|
|
return result
|
|
}
|
|
|
|
const total = Number(result.total || 0)
|
|
const pageSize = limit
|
|
|
|
return {
|
|
items: result.items,
|
|
pagination: {
|
|
page,
|
|
limit: pageSize,
|
|
total,
|
|
totalPages: Math.max(1, Math.ceil(total / pageSize))
|
|
}
|
|
}
|
|
})
|