Separate completed transfers and retain original file extensions
This commit is contained in:
@@ -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) =>
|
||||
|
||||
Reference in New Issue
Block a user