-
Notifications
You must be signed in to change notification settings - Fork 3
#118 feat: add File Lifetime #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
throw new Error(`File ${fileName} not exist`); | ||
} | ||
const stats: Stats = await stat(filePath); | ||
return (stats.birthtime || stats.mtime).getTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему тут birthtime || mtime?
allFilesQb.andWhere('(model.fileSize = 0 OR model.fileSize IS NULL)'); | ||
} | ||
|
||
if (config.unusedFileLifetimeMs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай добавим тут комментарий, где будет пояснено что мы делаем
fileNameLike?: string, | ||
ignoredTables?: string[], | ||
isEmpty?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему тут и в остальных местах ослаблены типы (параметры сделаны необязательными)?
this.justUploadedTempFileLifetimeMs = custom.justUploadedTempFileLifetimeMs | ||
|| parseInt(process.env.JUST_UPLOADED_TEMP_FILE_LIFETIME_S || '10', 10) * 1000; | ||
|
||
this.justUploadedUnusedFileLifetimeMs = custom.justUploadedUnusedFileLifetimeMs | ||
|| parseInt(process.env.JUST_UPLOADED_UNUSED_FILE_LIFETIME_S || String(24 * 60 * 60), 10) * 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай дефолтные значения вынесем в константы.
Sentry.captureException(error); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Думаю что не совсем корректно будет возвращать true если файла, к примеру, не нашлось, или возникли проблемы с определением его лайфтайма.
Как насчет того чтобы бросать ошибку, а вместе использования ловить ошибку:
try {
if (!(await isFileJustCreated(storage, filePath, currentTimeMs, this.fileConfigService.justUploadedTempFileLifetimeMs))) {
await storage.deleteFile(filePath);
}
}
Добавил проверку создания временных и неиспользуемых файлов при удаление.