Skip to content

Conversation

rialit
Copy link
Contributor

@rialit rialit commented Sep 5, 2025

Добавил проверку создания временных и неиспользуемых файлов при удаление.

throw new Error(`File ${fileName} not exist`);
}
const stats: Stats = await stat(filePath);
return (stats.birthtime || stats.mtime).getTime();
Copy link
Contributor

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай добавим тут комментарий, где будет пояснено что мы делаем

Comment on lines +57 to +59
fileNameLike?: string,
ignoredTables?: string[],
isEmpty?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему тут и в остальных местах ослаблены типы (параметры сделаны необязательными)?

Comment on lines +212 to +216
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай дефолтные значения вынесем в константы.

Comment on lines +17 to +18
Sentry.captureException(error);
return true;
Copy link
Contributor

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);
                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants