v0.0.88: 미디어 선택·미리보기 분리, 폴더 모달·삭제 API
This commit is contained in:
@@ -99,6 +99,50 @@ export const createMediaFolder = async (path) => {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 미디어 폴더를 삭제하고 해당 폴더(및 하위 경로)에 묶인 미디어 메타는 미분류로 되돌린다.
|
||||
* @param {string} path - 삭제할 폴더 경로
|
||||
* @returns {Promise<{ ok: boolean, path: string }>} 삭제 결과
|
||||
*/
|
||||
export const deleteMediaFolder = async (path) => {
|
||||
const sql = getPostgresClient()
|
||||
const normalizedPath = normalizeMediaCategory(path)
|
||||
|
||||
if (!sql) {
|
||||
throw new Error('DATABASE_REQUIRED')
|
||||
}
|
||||
|
||||
if (!normalizedPath || normalizedPath === '미분류') {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
message: '이 폴더는 삭제할 수 없습니다.'
|
||||
})
|
||||
}
|
||||
|
||||
const childPrefix = `${normalizedPath}/`
|
||||
|
||||
await sql.begin(async (tx) => {
|
||||
await tx`
|
||||
UPDATE media_metadata
|
||||
SET
|
||||
category = '미분류',
|
||||
updated_at = now()
|
||||
WHERE category = ${normalizedPath}
|
||||
OR category LIKE ${`${childPrefix}%`}
|
||||
`
|
||||
await tx`
|
||||
DELETE FROM media_folders
|
||||
WHERE path = ${normalizedPath}
|
||||
OR path LIKE ${`${childPrefix}%`}
|
||||
`
|
||||
})
|
||||
|
||||
return {
|
||||
ok: true,
|
||||
path: normalizedPath
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 미디어 파일명 조각을 안전하게 정리
|
||||
* @param {string} value - 원본 파일명
|
||||
|
||||
Reference in New Issue
Block a user