mirror of
https://github.com/chrononeko/chronocat.git
synced 2024-11-22 07:07:53 +00:00
feat(api): add common.generateUploadPath()
This commit is contained in:
parent
73164c4cdc
commit
9dc0177156
@ -177,7 +177,7 @@ async function saveFile(
|
|||||||
},
|
},
|
||||||
fileName: string,
|
fileName: string,
|
||||||
) {
|
) {
|
||||||
const filePath = await generateFilePath(ctx, fileName)
|
const filePath = await commonGenerateUploadPath(ctx, fileName)
|
||||||
await finished(file.pipe(createWriteStream(filePath)))
|
await finished(file.pipe(createWriteStream(filePath)))
|
||||||
return filePath
|
return filePath
|
||||||
}
|
}
|
||||||
@ -187,12 +187,15 @@ async function saveBuffer(
|
|||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
fileName: string,
|
fileName: string,
|
||||||
) {
|
) {
|
||||||
const filePath = await generateFilePath(ctx, fileName)
|
const filePath = await commonGenerateUploadPath(ctx, fileName)
|
||||||
await writeFile(filePath, buffer)
|
await writeFile(filePath, buffer)
|
||||||
return filePath
|
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')
|
const dir = join(ctx.chronocat.baseDir, 'tmp/upload')
|
||||||
await mkdir(dir, {
|
await mkdir(dir, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { commonFile } from './file'
|
import { commonFile, commonGenerateUploadPath } from './file'
|
||||||
import { commonSave } from './save'
|
import { commonSave } from './save'
|
||||||
import { commonSend, commonSendForward } from './send'
|
import { commonSend, commonSendForward } from './send'
|
||||||
|
|
||||||
@ -7,6 +7,7 @@ export const common = {
|
|||||||
sendForward: commonSendForward,
|
sendForward: commonSendForward,
|
||||||
save: commonSave,
|
save: commonSave,
|
||||||
file: commonFile,
|
file: commonFile,
|
||||||
|
generateUploadPath: commonGenerateUploadPath,
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export type Common = typeof common
|
export type Common = typeof common
|
||||||
|
Loading…
Reference in New Issue
Block a user