aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/static.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r--server/controllers/static.ts24
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'
12import { VideosCaptionCache, VideosPreviewCache } from '../lib/files-cache'
13import { cacheRoute } from '../middlewares/cache' 12import { cacheRoute } from '../middlewares/cache'
14import { asyncMiddleware, videosGetValidator } from '../middlewares' 13import { asyncMiddleware, videosGetValidator } from '../middlewares'
15import { VideoModel } from '../models/video/video' 14import { VideoModel } from '../models/video/video'
@@ -19,6 +18,7 @@ import { HttpNodeinfoDiasporaSoftwareNsSchema20 } from '../../shared/models/node
19import { join } from 'path' 18import { join } from 'path'
20import { root } from '../helpers/core-utils' 19import { root } from '../helpers/core-utils'
21import { CONFIG } from '../initializers/config' 20import { CONFIG } from '../initializers/config'
21import { getPreview, getVideoCaption } from './lazy-static'
22 22
23const staticRouter = express.Router() 23const 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
75const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR 76const avatarsPhysicalPath = CONFIG.STORAGE.AVATARS_DIR
76staticRouter.use( 77staticRouter.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
82staticRouter.use( 83staticRouter.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
88staticRouter.use( 89staticRouter.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
180async 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
187async 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
197async function generateNodeinfo (req: express.Request, res: express.Response) { 181async 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()