mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: auto delete file when call get_file
This commit is contained in:
parent
57ef8ed3e4
commit
4aadd81e60
@ -19,6 +19,7 @@ export interface GetFileResponse{
|
||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse>{
|
||||
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
|
||||
const cache = fileCache.get(payload.file)
|
||||
const {autoDeleteFile, enableLocalFile2Url, autoDeleteFileSecond} = getConfigUtil().getConfig()
|
||||
if (!cache) {
|
||||
throw new Error('file not found')
|
||||
}
|
||||
@ -31,11 +32,16 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse>{
|
||||
file_size: cache.fileSize,
|
||||
file_name: cache.fileName
|
||||
}
|
||||
if (getConfigUtil().getConfig().enableLocalFile2Url) {
|
||||
if (enableLocalFile2Url) {
|
||||
if (!cache.url) {
|
||||
res.base64 = await fs.readFile(cache.filePath, 'base64')
|
||||
}
|
||||
}
|
||||
if (autoDeleteFile) {
|
||||
setTimeout(() => {
|
||||
fs.unlink(cache.filePath)
|
||||
}, autoDeleteFileSecond * 1000)
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user