@@ -2,6 +2,7 @@ import { Module } from '@nestjs/common';
2
2
import { ServeStaticModule } from '@nestjs/serve-static' ;
3
3
import { join } from 'path' ;
4
4
import config , { Config } from 'src/utils/config' ;
5
+ import { Response } from 'express' ;
5
6
import { AutoUpdatedStaticsProvider } from './providers/auto-updated-statics.provider' ;
6
7
7
8
const SERVER_CONFIG = config . get ( 'server' ) as Config [ 'server' ] ;
@@ -10,20 +11,29 @@ const TUTORIALS_CONFIG = config.get('tutorials') as Config['tutorials'];
10
11
11
12
const CONTENT_CONFIG = config . get ( 'content' ) ;
12
13
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
+
13
21
@Module ( {
14
22
imports : [
15
23
ServeStaticModule . forRoot ( {
16
24
serveRoot : SERVER_CONFIG . tutorialsUri ,
17
25
rootPath : join ( PATH_CONFIG . tutorials ) ,
18
26
serveStaticOptions : {
19
27
fallthrough : false ,
28
+ setHeaders : downloadableStaticFiles ,
20
29
} ,
21
30
} ) ,
22
31
ServeStaticModule . forRoot ( {
23
32
serveRoot : SERVER_CONFIG . customTutorialsUri ,
24
33
rootPath : join ( PATH_CONFIG . customTutorials ) ,
25
34
serveStaticOptions : {
26
35
fallthrough : false ,
36
+ setHeaders : downloadableStaticFiles ,
27
37
} ,
28
38
} ) ,
29
39
ServeStaticModule . forRoot ( {
0 commit comments