21 lines
794 B
TypeScript
21 lines
794 B
TypeScript
import { randomUUID } from 'crypto';
|
|
|
|
/** 门店资源上传目录(OSS object key 前缀) */
|
|
const STORE_UPLOAD_DIRS: Record<string, string> = {
|
|
STORE_TITLE: 'store/title',
|
|
STORE_ENV: 'store/env',
|
|
STORE_CONTRACT: 'store/contract',
|
|
};
|
|
|
|
export function resolveOssUploadDir(uploadPrefix: string, bizType: string): string {
|
|
const storeDir = STORE_UPLOAD_DIRS[bizType];
|
|
if (storeDir) return `${storeDir}/`;
|
|
return `${uploadPrefix.replace(/\/$/, '')}/${bizType.toLowerCase()}/`;
|
|
}
|
|
|
|
export function buildOssObjectKey(uploadPrefix: string, bizType: string, fileName: string): string {
|
|
const ext = fileName.includes('.') ? fileName.split('.').pop() : 'bin';
|
|
const dir = resolveOssUploadDir(uploadPrefix, bizType);
|
|
return `${dir}${Date.now()}-${randomUUID().slice(0, 8)}.${ext}`;
|
|
}
|