aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/lazy-static.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/controllers/lazy-static.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/controllers/lazy-static.ts')
-rw-r--r--server/controllers/lazy-static.ts11
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'
6import { AvatarModel } from '../models/avatar/avatar' 6import { AvatarModel } from '../models/avatar/avatar'
7import { logger } from '../helpers/logger' 7import { logger } from '../helpers/logger'
8import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar' 8import { avatarPathUnsafeCache, pushAvatarProcessInQueue } from '../lib/avatar'
9import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
9 10
10const lazyStaticRouter = express.Router() 11const 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
72async function getPreview (req: express.Request, res: express.Response) { 73async 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}