feat: migrate app routes and business modules
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { createRequestError } from './request-client.js'
|
||||
import {
|
||||
normalizeOptionalNonnegativeInteger,
|
||||
normalizeOptionalNumericId
|
||||
} from './response-normalizers.js'
|
||||
|
||||
export const normalizeResourceCapabilities = (value, label, code) => {
|
||||
const capabilities = {}
|
||||
for (const field of ['canEdit', 'canDelete']) {
|
||||
if (value[field] !== undefined && typeof value[field] !== 'boolean') {
|
||||
throw createRequestError(`${label}权限字段 ${field} 无效`, code)
|
||||
}
|
||||
capabilities[field] = value[field] === true
|
||||
}
|
||||
return capabilities
|
||||
}
|
||||
|
||||
export const normalizeContentProtectionCapabilities = (value, label, code) => {
|
||||
const capabilities = {}
|
||||
for (const field of ['contentProtected', 'contentUnlocked', 'canManageProtection']) {
|
||||
if (value[field] !== undefined && typeof value[field] !== 'boolean') {
|
||||
throw createRequestError(`${label}内容保护字段 ${field} 无效`, code)
|
||||
}
|
||||
capabilities[field] = value[field] === true
|
||||
}
|
||||
return capabilities
|
||||
}
|
||||
|
||||
export const normalizeBusinessFileAccess = (value, label, code, { required = false } = {}) => {
|
||||
if (value === undefined || value === null) {
|
||||
if (required) throw createRequestError(`${label}缺失`, code)
|
||||
return null
|
||||
}
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
||||
throw createRequestError(`${label}无效`, code)
|
||||
}
|
||||
const fileId = normalizeOptionalNumericId(value.fileId, `${label}文件标识`, code)
|
||||
const ossId = normalizeOptionalNumericId(value.ossId, `${label}存储标识`, code)
|
||||
if (!fileId || !ossId) throw createRequestError(`${label}缺少文件标识`, code)
|
||||
const normalizeText = (field) => {
|
||||
const fieldValue = value[field]
|
||||
if (fieldValue === undefined || fieldValue === null) return ''
|
||||
if (typeof fieldValue !== 'string') throw createRequestError(`${label}${field}无效`, code)
|
||||
return fieldValue.trim()
|
||||
}
|
||||
const accessUrl = normalizeText('accessUrl')
|
||||
if (required && !accessUrl) throw createRequestError(`${label}缺少授权访问地址`, code)
|
||||
return {
|
||||
fileId,
|
||||
ossId,
|
||||
fileName: normalizeText('fileName'),
|
||||
mediaType: normalizeText('mediaType'),
|
||||
fileSize: normalizeOptionalNonnegativeInteger(value.fileSize, `${label}文件大小`, code),
|
||||
accessUrl,
|
||||
expiresAt: normalizeText('expiresAt')
|
||||
}
|
||||
}
|
||||
|
||||
export const normalizeBusinessFileAccessRows = (value, label, code) => {
|
||||
if (value === undefined || value === null) return []
|
||||
if (!Array.isArray(value)) throw createRequestError(`${label}不是列表`, code)
|
||||
return value.map((item) => normalizeBusinessFileAccess(item, label, code, { required: true }))
|
||||
}
|
||||
Reference in New Issue
Block a user