Skip to content

Commit 007dc2b

Browse files
committed
feat: enhanced file name
1 parent 2bd1751 commit 007dc2b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

apps/backend/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ async function bootstrap() {
1313
app.enableCors({
1414
credentials: true,
1515
origin: configService.get("cors.origin"),
16+
exposedHeaders: ["Content-Disposition"],
1617
});
1718
app.enableShutdownHooks();
1819
app.useGlobalPipes(new ValidationPipe());

apps/backend/src/system/export/export.controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ export class ExportController {
2020
headers: {
2121
"Content-Disposition": {
2222
description: "Attachment dump.sql",
23-
schema: { type: "string", example: "attachment; filename=dump.sql" },
23+
schema: { type: "string", example: 'attachment; filename="quassel-database-dump.sql"' },
2424
},
2525
},
2626
})
2727
async get(@Response() res: FastifyReply) {
2828
try {
2929
const data = await this.exportService.fullDatabaseDump();
3030
const buffer = Buffer.from(data, "utf-8");
31-
res.header("Content-Disposition", "attachment; filename=dump.sql");
31+
const dateTime = new Date().toISOString().replace(/:/g, "-").replace("T", "_").replace(/\..+/, "");
32+
res.header("Content-Disposition", `attachment; filename="quassel-database-dump-${dateTime}.sql"`);
3233
res.header("Content-Type", "text/sql");
3334
res.header("Content-Length", buffer.byteLength.toString());
3435
res.send(buffer);

apps/frontend/src/hooks/useDownload.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ export const useDownload = (fileUrl: string, fileName: string, response?: () =>
8282
setProgress(null);
8383

8484
try {
85-
const res = response ? response() : fetch(fileUrl);
86-
const url = await handleResponse(await res);
85+
const res = response ? await response() : await fetch(fileUrl);
86+
const url = await handleResponse(res);
8787

88-
handleDownload(fileName, url);
88+
const headerFileName = res.headers.get("content-disposition")?.match(/filename="(.+)"/)?.[1];
89+
90+
handleDownload(headerFileName || fileName, url);
8991
} catch (error) {
9092
setError(error);
9193
} finally {

0 commit comments

Comments
 (0)