diff options
Diffstat (limited to 'server/controllers/lazy-static.ts')
-rw-r--r-- | server/controllers/lazy-static.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/server/controllers/lazy-static.ts b/server/controllers/lazy-static.ts index 1ff99e90c..5c6369c9e 100644 --- a/server/controllers/lazy-static.ts +++ b/server/controllers/lazy-static.ts | |||
@@ -6,6 +6,7 @@ import { asyncMiddleware } from '../middlewares' | |||
6 | import { AvatarModel } from '../models/avatar/avatar' | 6 | import { AvatarModel } from '../models/avatar/avatar' |
7 | import { logger } from '../helpers/logger' | 7 | import { logger } from '../helpers/logger' |
8 | import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' | 8 | import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' |
9 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
9 | 10 | ||
10 | const lazyStaticRouter = express.Router() | 11 | const lazyStaticRouter = express.Router() |
11 | 12 | ||
@@ -44,10 +45,10 @@ async function getAvatar (req: express.Request, res: express.Response) { | |||
44 | } | 45 | } |
45 | 46 | ||
46 | const avatar = await AvatarModel.loadByName(filename) | 47 | const avatar = await AvatarModel.loadByName(filename) |
47 | if (!avatar) return res.sendStatus(404) | 48 | if (!avatar) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
48 | 49 | ||
49 | if (avatar.onDisk === false) { | 50 | if (avatar.onDisk === false) { |
50 | if (!avatar.fileUrl) return res.sendStatus(404) | 51 | if (!avatar.fileUrl) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
51 | 52 | ||
52 | logger.info('Lazy serve remote avatar image %s.', avatar.fileUrl) | 53 | logger.info('Lazy serve remote avatar image %s.', avatar.fileUrl) |
53 | 54 | ||
@@ -55,7 +56,7 @@ async function getAvatar (req: express.Request, res: express.Response) { | |||
55 | await pushAvatarProcessInQueue({ filename: avatar.filename, fileUrl: avatar.fileUrl }) | 56 | await pushAvatarProcessInQueue({ filename: avatar.filename, fileUrl: avatar.fileUrl }) |
56 | } catch (err) { | 57 | } catch (err) { |
57 | logger.warn('Cannot process remote avatar %s.', avatar.fileUrl, { err }) | 58 | logger.warn('Cannot process remote avatar %s.', avatar.fileUrl, { err }) |
58 | return res.sendStatus(404) | 59 | return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
59 | } | 60 | } |
60 | 61 | ||
61 | avatar.onDisk = true | 62 | avatar.onDisk = true |
@@ -71,7 +72,7 @@ async function getAvatar (req: express.Request, res: express.Response) { | |||
71 | 72 | ||
72 | async function getPreview (req: express.Request, res: express.Response) { | 73 | async function getPreview (req: express.Request, res: express.Response) { |
73 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) | 74 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) |
74 | if (!result) return res.sendStatus(404) | 75 | if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
75 | 76 | ||
76 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) | 77 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) |
77 | } | 78 | } |
@@ -81,7 +82,7 @@ async function getVideoCaption (req: express.Request, res: express.Response) { | |||
81 | videoId: req.params.videoId, | 82 | videoId: req.params.videoId, |
82 | language: req.params.captionLanguage | 83 | language: req.params.captionLanguage |
83 | }) | 84 | }) |
84 | if (!result) return res.sendStatus(404) | 85 | if (!result) return res.sendStatus(HttpStatusCode.NOT_FOUND_404) |
85 | 86 | ||
86 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) | 87 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE.SERVER }) |
87 | } | 88 | } |