diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/lazy-static.ts | 17 | ||||
-rw-r--r-- | server/controllers/static.ts | 18 |
2 files changed, 12 insertions, 23 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts index 0cab5dcd0..b082e41f6 100644 --- a/server/controllers/lazy-static.ts +++ b/server/controllers/lazy-static.ts | |||
@@ -7,7 +7,7 @@ import { logger } from '../helpers/logger' | |||
7 | import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' | 7 | import { ACTOR_IMAGES_SIZE, LAZY_STATIC_PATHS, STATIC_MAX_AGE } from '../initializers/constants' |
8 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | 8 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' |
9 | import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor' | 9 | import { actorImagePathUnsafeCache, downloadActorImageFromWorker } from '../lib/local-actor' |
10 | import { asyncMiddleware } from '../middlewares' | 10 | import { asyncMiddleware, handleStaticError } from '../middlewares' |
11 | import { ActorImageModel } from '../models/actor/actor-image' | 11 | import { ActorImageModel } from '../models/actor/actor-image' |
12 | 12 | ||
13 | const lazyStaticRouter = express.Router() | 13 | const lazyStaticRouter = express.Router() |
@@ -16,27 +16,32 @@ lazyStaticRouter.use(cors()) | |||
16 | 16 | ||
17 | lazyStaticRouter.use( | 17 | lazyStaticRouter.use( |
18 | LAZY_STATIC_PATHS.AVATARS + ':filename', | 18 | LAZY_STATIC_PATHS.AVATARS + ':filename', |
19 | asyncMiddleware(getActorImage) | 19 | asyncMiddleware(getActorImage), |
20 | handleStaticError | ||
20 | ) | 21 | ) |
21 | 22 | ||
22 | lazyStaticRouter.use( | 23 | lazyStaticRouter.use( |
23 | LAZY_STATIC_PATHS.BANNERS + ':filename', | 24 | LAZY_STATIC_PATHS.BANNERS + ':filename', |
24 | asyncMiddleware(getActorImage) | 25 | asyncMiddleware(getActorImage), |
26 | handleStaticError | ||
25 | ) | 27 | ) |
26 | 28 | ||
27 | lazyStaticRouter.use( | 29 | lazyStaticRouter.use( |
28 | LAZY_STATIC_PATHS.PREVIEWS + ':filename', | 30 | LAZY_STATIC_PATHS.PREVIEWS + ':filename', |
29 | asyncMiddleware(getPreview) | 31 | asyncMiddleware(getPreview), |
32 | handleStaticError | ||
30 | ) | 33 | ) |
31 | 34 | ||
32 | lazyStaticRouter.use( | 35 | lazyStaticRouter.use( |
33 | LAZY_STATIC_PATHS.VIDEO_CAPTIONS + ':filename', | 36 | LAZY_STATIC_PATHS.VIDEO_CAPTIONS + ':filename', |
34 | asyncMiddleware(getVideoCaption) | 37 | asyncMiddleware(getVideoCaption), |
38 | handleStaticError | ||
35 | ) | 39 | ) |
36 | 40 | ||
37 | lazyStaticRouter.use( | 41 | lazyStaticRouter.use( |
38 | LAZY_STATIC_PATHS.TORRENTS + ':filename', | 42 | LAZY_STATIC_PATHS.TORRENTS + ':filename', |
39 | asyncMiddleware(getTorrent) | 43 | asyncMiddleware(getTorrent), |
44 | handleStaticError | ||
40 | ) | 45 | ) |
41 | 46 | ||
42 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 0b5c12b76..33c429eb1 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { HttpStatusCode } from '@shared/models' | ||
2 | import cors from 'cors' | 1 | import cors from 'cors' |
3 | import express from 'express' | 2 | import express from 'express' |
3 | import { handleStaticError } from '@server/middlewares' | ||
4 | import { CONFIG } from '../initializers/config' | 4 | import { CONFIG } from '../initializers/config' |
5 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' | 5 | import { HLS_STREAMING_PLAYLIST_DIRECTORY, STATIC_MAX_AGE, STATIC_PATHS } from '../initializers/constants' |
6 | 6 | ||
@@ -41,19 +41,3 @@ staticRouter.use( | |||
41 | export { | 41 | export { |
42 | staticRouter | 42 | staticRouter |
43 | } | 43 | } |
44 | |||
45 | // --------------------------------------------------------------------------- | ||
46 | |||
47 | function handleStaticError (err: any, req: express.Request, res: express.Response, next: express.NextFunction) { | ||
48 | const message = err.message || '' | ||
49 | |||
50 | if (message.includes('ENOENT')) { | ||
51 | return res.fail({ | ||
52 | status: err.status || HttpStatusCode.INTERNAL_SERVER_ERROR_500, | ||
53 | message: err.message, | ||
54 | type: err.name | ||
55 | }) | ||
56 | } | ||
57 | |||
58 | return next(err) | ||
59 | } | ||