Separate completed transfers and retain original file extensions

This commit is contained in:
2026-10-14 16:10:59 +09:00
parent 3852c87e2e
commit 69e7449ba7
11 changed files with 736 additions and 31 deletions

View File

@@ -623,7 +623,7 @@ export async function createApp(cfg: Config, options: { mailer?: Mailer } = {})
app.get('/api/access/:id/download', async (req, reply) => {
const accessId = id(req),
g = accessSubject(req, accessId);
const { file, stream } = await service.storage.openDownload(g, accessId);
const { file, stream, access } = await service.storage.openDownload(g, accessId);
const fallback =
file.name.replace(/[^a-zA-Z0-9._ -]/g, '_').replace(/^[. ]+/, '') || 'download';
const encoded = encodeURIComponent(file.name).replace(
@@ -643,6 +643,15 @@ export async function createApp(cfg: Config, options: { mailer?: Mailer } = {})
stream.destroy();
throw error;
}
reply.raw.once('finish', () => {
if (reply.statusCode === 200 && stream.readableEnded && access.role === 'recipient') {
try {
service.storage.layout.downloaded(file.id);
} catch (err) {
req.log.warn({ err }, 'Completed file relocation will be retried');
}
}
});
return reply.send(stream);
});
app.get('/api/access/:id/preview', async (req, reply) =>