세션·로그인 제한, ZIP/업로드 스트리밍, CSP 최소 강제와 Report-Only, Playwright 격리 검증을 추가하고 미디어 목록을 reconcile 후 database 모드로 고정한다. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
import { resolve } from 'node:path'
|
|
|
|
/**
|
|
* 런타임 업로드 파일 루트를 반환한다.
|
|
* Playwright 실행은 명시된 임시 디렉터리만 사용한다.
|
|
* @returns {string} 업로드 파일 절대 경로
|
|
*/
|
|
export const getUploadRoot = () => {
|
|
const testUploadRoot = String(process.env.SORI_TEST_UPLOAD_ROOT || '').trim()
|
|
|
|
if (process.env.PLAYWRIGHT_TEST === '1') {
|
|
if (!testUploadRoot) {
|
|
throw new Error('SORI_TEST_UPLOAD_ROOT_REQUIRED')
|
|
}
|
|
|
|
return resolve(testUploadRoot)
|
|
}
|
|
|
|
return resolve(process.cwd(), 'public', 'uploads')
|
|
}
|
|
|
|
/**
|
|
* 설정된 공개 업로드 경로의 디스크 루트를 반환한다.
|
|
* @param {string} publicBasePath - `uploads` 형태 공개 경로
|
|
* @returns {string} 업로드 디렉터리 절대 경로
|
|
*/
|
|
export const getConfiguredUploadRoot = (publicBasePath = 'uploads') => {
|
|
if (process.env.PLAYWRIGHT_TEST === '1') {
|
|
return getUploadRoot()
|
|
}
|
|
|
|
return resolve(process.cwd(), 'public', publicBasePath)
|
|
}
|
|
|
|
/**
|
|
* `/uploads/...` URL을 현재 실행 환경의 파일 경로로 변환한다.
|
|
* @param {string} uploadUrl - 업로드 공개 URL
|
|
* @returns {string} 파일 절대 경로
|
|
*/
|
|
export const resolveUploadUrlPath = (uploadUrl) => {
|
|
const decodedPath = decodeURIComponent(String(uploadUrl || ''))
|
|
.replace(/^\/+uploads\/?/, '')
|
|
|
|
return resolve(getUploadRoot(), decodedPath)
|
|
}
|