Skip to content

Commit 8dfa250

Browse files
author
Artem
authored
Merge pull request #3032 from RedisInsight/be/feature/RI-5394-redis-upload
make static files downloadable with query parameter
2 parents 9f533b9 + 1ee7e88 commit 8dfa250

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

redisinsight/api/src/modules/statics-management/statics-management.module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
22
import { ServeStaticModule } from '@nestjs/serve-static';
33
import { join } from 'path';
44
import config, { Config } from 'src/utils/config';
5+
import { Response } from 'express';
56
import { AutoUpdatedStaticsProvider } from './providers/auto-updated-statics.provider';
67

78
const SERVER_CONFIG = config.get('server') as Config['server'];
@@ -10,20 +11,29 @@ const TUTORIALS_CONFIG = config.get('tutorials') as Config['tutorials'];
1011

1112
const CONTENT_CONFIG = config.get('content');
1213

14+
const downloadableStaticFiles = (res: Response) => {
15+
if (res.req?.query?.download === 'true') {
16+
res.setHeader('Content-Type', 'application/octet-stream');
17+
res.setHeader('Content-Disposition', 'attachment;');
18+
}
19+
};
20+
1321
@Module({
1422
imports: [
1523
ServeStaticModule.forRoot({
1624
serveRoot: SERVER_CONFIG.tutorialsUri,
1725
rootPath: join(PATH_CONFIG.tutorials),
1826
serveStaticOptions: {
1927
fallthrough: false,
28+
setHeaders: downloadableStaticFiles,
2029
},
2130
}),
2231
ServeStaticModule.forRoot({
2332
serveRoot: SERVER_CONFIG.customTutorialsUri,
2433
rootPath: join(PATH_CONFIG.customTutorials),
2534
serveStaticOptions: {
2635
fallthrough: false,
36+
setHeaders: downloadableStaticFiles,
2737
},
2838
}),
2939
ServeStaticModule.forRoot({

0 commit comments

Comments
 (0)