diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-09 11:32:40 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-09 11:32:40 +0200 |
commit | 557b13ae24019d9ab214bbea7eaa0f892c8f4b05 (patch) | |
tree | aa32396531acf93e3dfdb29880177813039ed77f /server/controllers/static.ts | |
parent | c5407d7046168abb4098df1408e7aa84519cb61a (diff) | |
download | PeerTube-557b13ae24019d9ab214bbea7eaa0f892c8f4b05.tar.gz PeerTube-557b13ae24019d9ab214bbea7eaa0f892c8f4b05.tar.zst PeerTube-557b13ae24019d9ab214bbea7eaa0f892c8f4b05.zip |
Lazy load avatars
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r-- | server/controllers/static.ts | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts index 110d25031..8979ef5f3 100644 --- a/server/controllers/static.ts +++ b/server/controllers/static.ts | |||
@@ -9,7 +9,6 @@ import { | |||
9 | STATIC_PATHS, | 9 | STATIC_PATHS, |
10 | WEBSERVER | 10 | WEBSERVER |
11 | } from '../initializers/constants' | 11 | } from '../initializers/constants' |
12 | import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache' | ||
13 | import { cacheRoute } from '../middlewares/cache' | 12 | import { cacheRoute } from '../middlewares/cache' |
14 | import { asyncMiddleware, videosGetValidator } from '../middlewares' | 13 | import { asyncMiddleware, videosGetValidator } from '../middlewares' |
15 | import { VideoModel } from '../models/video/video' | 14 | import { VideoModel } from '../models/video/video' |
@@ -19,6 +18,7 @@ import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/node | |||
19 | import { join } from 'path' | 18 | import { join } from 'path' |
20 | import { root } from '../helpers/core-utils' | 19 | import { root } from '../helpers/core-utils' |
21 | import { CONFIG } from '../initializers/config' | 20 | import { CONFIG } from '../initializers/config' |
21 | import { getPreview, getVideoCaption } from './lazy-static' | ||
22 | 22 | ||
23 | const staticRouter = express.Router() | 23 | const staticRouter = express.Router() |
24 | 24 | ||
@@ -72,19 +72,20 @@ staticRouter.use( | |||
72 | express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist | 72 | express.static(thumbnailsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist |
73 | ) | 73 | ) |
74 | 74 | ||
75 | // DEPRECATED: use lazy-static route instead | ||
75 | const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR | 76 | const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR |
76 | staticRouter.use( | 77 | staticRouter.use( |
77 | STATIC_PATHS.AVATARS, | 78 | STATIC_PATHS.AVATARS, |
78 | express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist | 79 | express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE.SERVER, fallthrough: false }) // 404 if the file does not exist |
79 | ) | 80 | ) |
80 | 81 | ||
81 | // We don't have video previews, fetch them from the origin instance | 82 | // DEPRECATED: use lazy-static route instead |
82 | staticRouter.use( | 83 | staticRouter.use( |
83 | STATIC_PATHS.PREVIEWS + ':uuid.jpg', | 84 | STATIC_PATHS.PREVIEWS + ':uuid.jpg', |
84 | asyncMiddleware(getPreview) | 85 | asyncMiddleware(getPreview) |
85 | ) | 86 | ) |
86 | 87 | ||
87 | // We don't have video captions, fetch them from the origin instance | 88 | // DEPRECATED: use lazy-static route instead |
88 | staticRouter.use( | 89 | staticRouter.use( |
89 | STATIC_PATHS.VIDEO_CAPTIONS + ':videoId-:captionLanguage([a-z]+).vtt', | 90 | STATIC_PATHS.VIDEO_CAPTIONS + ':videoId-:captionLanguage([a-z]+).vtt', |
90 | asyncMiddleware(getVideoCaption) | 91 | asyncMiddleware(getVideoCaption) |
@@ -177,23 +178,6 @@ export { | |||
177 | 178 | ||
178 | // --------------------------------------------------------------------------- | 179 | // --------------------------------------------------------------------------- |
179 | 180 | ||
180 | async function getPreview (req: express.Request, res: express.Response) { | ||
181 | const result = await VideosPreviewCache.Instance.getFilePath(req.params.uuid) | ||
182 | if (!result) return res.sendStatus(404) | ||
183 | |||
184 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) | ||
185 | } | ||
186 | |||
187 | async function getVideoCaption (req: express.Request, res: express.Response) { | ||
188 | const result = await VideosCaptionCache.Instance.getFilePath({ | ||
189 | videoId: req.params.videoId, | ||
190 | language: req.params.captionLanguage | ||
191 | }) | ||
192 | if (!result) return res.sendStatus(404) | ||
193 | |||
194 | return res.sendFile(result.path, { maxAge: STATIC_MAX_AGE }) | ||
195 | } | ||
196 | |||
197 | async function generateNodeinfo (req: express.Request, res: express.Response) { | 181 | async function generateNodeinfo (req: express.Request, res: express.Response) { |
198 | const { totalVideos } = await VideoModel.getStats() | 182 | const { totalVideos } = await VideoModel.getStats() |
199 | const { totalLocalVideoComments } = await VideoCommentModel.getStats() | 183 | const { totalLocalVideoComments } = await VideoCommentModel.getStats() |