@@ -52,6 +52,12 @@ if (config.forceHttps) {
52
52
// Static files
53
53
app . use ( `${ config . baseUrl } app` , express . static ( path . join ( __dirname , '../public/app' ) ) ) ;
54
54
app . use ( `${ config . baseUrl } assets` , express . static ( path . join ( __dirname , '../public/assets' ) ) ) ;
55
+ // Resolve language
56
+ app . use ( ( req , res , next ) => {
57
+ const lang = req . acceptsLanguages ( ...Object . keys ( config . languages ) ) || config . defaultLanguage ;
58
+ req . translations = config . languages [ lang ] ;
59
+ next ( ) ;
60
+ } ) ;
55
61
56
62
// robots.txt
57
63
app . get ( `${ config . baseUrl } robots.txt` , ( req , res ) => {
@@ -68,20 +74,18 @@ app.get(`${ config.baseUrl }`, (req, res) => {
68
74
if ( config . uploadAppPath !== `${ config . baseUrl } ` ) {
69
75
res . status ( 304 ) . redirect ( config . uploadAppPath ) ;
70
76
} else {
71
- res . send ( uploadPage ( pugVars ) ) ;
77
+ res . send ( uploadPage ( { ... pugVars , lang : req . translations } ) ) ;
72
78
}
73
79
} ) ;
74
80
75
81
app . get ( config . uploadAppPath , ( req , res ) => {
76
- res . send ( uploadPage ( pugVars ) ) ;
82
+ res . send ( uploadPage ( { ... pugVars , lang : req . translations } ) ) ;
77
83
} ) ;
78
84
79
85
// Return translations
80
86
app . get ( `${ config . baseUrl } lang.json` , ( req , res ) => {
81
- const lang = req . acceptsLanguages ( ...Object . keys ( config . languages ) ) ;
82
- const translations = config . languages [ lang ] ;
83
- eventBus . emit ( 'getLang' , translations ) ;
84
- res . json ( translations ) ;
87
+ eventBus . emit ( 'getLang' , req . translations ) ;
88
+ res . json ( req . translations ) ;
85
89
} ) ;
86
90
87
91
// Config
@@ -115,7 +119,7 @@ app.get(`${ config.baseUrl }config.json`, (req, res) => {
115
119
116
120
app . get ( `${ config . baseUrl } admin` , ( req , res , next ) => {
117
121
if ( ! config . adminPass ) return next ( ) ;
118
- res . send ( adminPage ( pugVars ) ) ;
122
+ res . send ( adminPage ( { ... pugVars , lang : req . translations } ) ) ;
119
123
} ) ;
120
124
121
125
app . get ( `${ config . baseUrl } admin/data.json` , ( req , res , next ) => {
@@ -171,7 +175,7 @@ app.get(`${ config.baseUrl }:sid`, (req, res, next) => {
171
175
} ) ;
172
176
} else {
173
177
if ( ! db . get ( req . params . sid ) ) return next ( ) ;
174
- res . send ( downloadPage ( pugVars ) ) ;
178
+ res . send ( downloadPage ( { ... pugVars , lang : req . translations } ) ) ;
175
179
}
176
180
} ) ;
177
181
@@ -188,10 +192,10 @@ app.get(`${ config.baseUrl }files/:fid`, async (req, res, next) => {
188
192
const format = req . params . fid . endsWith ( '.zip' ) ? 'zip' : 'tar.gz' ;
189
193
const bucket = db . get ( sid ) ;
190
194
191
- if ( ! bucket ) return res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : 'Download bucket not found.' } ) ) ;
195
+ if ( ! bucket ) return res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : 'Download bucket not found.' , lang : req . translations } ) ) ;
192
196
193
197
if ( req . params . fid !== sid + '++' + MD5 ( bucket . map ( f => f . key ) . join ( ) ) . toString ( ) + '.' + format ) {
194
- res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : 'Invalid link' } ) ) ;
198
+ res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : 'Invalid link' , lang : req . translations } ) ) ;
195
199
return ;
196
200
}
197
201
debug ( `Download Bucket ${ sid } ` ) ;
@@ -234,7 +238,8 @@ app.get(`${ config.baseUrl }files/:fid`, async (req, res, next) => {
234
238
sid,
235
239
file : filename ,
236
240
metadata : bucket [ 0 ] . metadata ,
237
- bucket
241
+ bucket,
242
+ url : req . protocol + '://' + req . get ( 'host' ) + req . originalUrl ,
238
243
} ) ;
239
244
} ) ;
240
245
}
@@ -262,12 +267,13 @@ app.get(`${ config.baseUrl }files/:fid`, async (req, res, next) => {
262
267
eventBus . emit ( 'fileDownloaded' , {
263
268
sid,
264
269
file : info . metadata . name ,
265
- metadata : info . metadata
270
+ metadata : info . metadata ,
271
+ url : req . protocol + '://' + req . get ( 'host' ) + req . originalUrl ,
266
272
} ) ;
267
273
} ) ;
268
274
}
269
275
catch ( e ) {
270
- res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : e . message } ) ) ;
276
+ res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : e . message , lang : req . translations } ) ) ;
271
277
}
272
278
} ) ;
273
279
@@ -353,7 +359,7 @@ app.use(`${ config.baseUrl }files`,
353
359
) ;
354
360
355
361
app . use ( ( req , res , next ) => {
356
- res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : 'Download bucket not found.' } ) ) ;
362
+ res . status ( 404 ) . send ( errorPage ( { ...pugVars , error : 'Download bucket not found.' , lang : req . translations } ) ) ;
357
363
} ) ;
358
364
359
365
module . exports = app ;
0 commit comments