feat(api): add common.generateUploadPath()

This commit is contained in:
Il Harper 2024-09-07 14:57:54 +08:00
parent 73164c4cdc
commit 9dc0177156
No known key found for this signature in database
GPG Key ID: 4B71FCA698E7E8EC
2 changed files with 8 additions and 4 deletions

View File

@ -177,7 +177,7 @@ async function saveFile(
},
fileName: string,
) {
const filePath = await generateFilePath(ctx, fileName)
const filePath = await commonGenerateUploadPath(ctx, fileName)
await finished(file.pipe(createWriteStream(filePath)))
return filePath
}
@ -187,12 +187,15 @@ async function saveBuffer(
buffer: Buffer,
fileName: string,
) {
const filePath = await generateFilePath(ctx, fileName)
const filePath = await commonGenerateUploadPath(ctx, fileName)
await writeFile(filePath, buffer)
return filePath
}
async function generateFilePath(ctx: ChronocatContext, fileName: string) {
export async function commonGenerateUploadPath(
ctx: ChronocatContext,
fileName: string,
) {
const dir = join(ctx.chronocat.baseDir, 'tmp/upload')
await mkdir(dir, {
recursive: true,

View File

@ -1,4 +1,4 @@
import { commonFile } from './file'
import { commonFile, commonGenerateUploadPath } from './file'
import { commonSave } from './save'
import { commonSend, commonSendForward } from './send'
@ -7,6 +7,7 @@ export const common = {
sendForward: commonSendForward,
save: commonSave,
file: commonFile,
generateUploadPath: commonGenerateUploadPath,
} as const
export type Common = typeof common