aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/static.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-12 19:02:00 +0200
committerChocobozzz <me@florianbigard.com>2018-07-16 11:50:08 +0200
commit40e87e9ecc54e3513fb586928330a7855eb192c6 (patch)
treeaf1111ecba85f9cd8286811ff332a67cf21be2f6 /server/controllers/static.ts
parentd4557fd3ecc8d4ed4fb0e5c868929bc36c959ed2 (diff)
downloadPeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.gz
PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.tar.zst
PeerTube-40e87e9ecc54e3513fb586928330a7855eb192c6.zip
Implement captions/subtitles
Diffstat (limited to 'server/controllers/static.ts')
-rw-r--r--server/controllers/static.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/server/controllers/static.ts b/server/controllers/static.ts
index 139ba67cc..679999859 100644
--- a/server/controllers/static.ts
+++ b/server/controllers/static.ts
@@ -4,6 +4,7 @@ import { CONFIG, STATIC_DOWNLOAD_PATHS, STATIC_MAX_AGE, STATIC_PATHS } from '../
4import { VideosPreviewCache } from '../lib/cache' 4import { VideosPreviewCache } from '../lib/cache'
5import { asyncMiddleware, videosGetValidator } from '../middlewares' 5import { asyncMiddleware, videosGetValidator } from '../middlewares'
6import { VideoModel } from '../models/video/video' 6import { VideoModel } from '../models/video/video'
7import { VideosCaptionCache } from '../lib/cache/videos-caption-cache'
7 8
8const staticRouter = express.Router() 9const staticRouter = express.Router()
9 10
@@ -49,12 +50,18 @@ staticRouter.use(
49 express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE }) 50 express.static(avatarsPhysicalPath, { maxAge: STATIC_MAX_AGE })
50) 51)
51 52
52// Video previews path for express 53// We don't have video previews, fetch them from the origin instance
53staticRouter.use( 54staticRouter.use(
54 STATIC_PATHS.PREVIEWS + ':uuid.jpg', 55 STATIC_PATHS.PREVIEWS + ':uuid.jpg',
55 asyncMiddleware(getPreview) 56 asyncMiddleware(getPreview)
56) 57)
57 58
59// We don't have video captions, fetch them from the origin instance
60staticRouter.use(
61 STATIC_PATHS.VIDEO_CAPTIONS + ':videoId-:captionLanguage([a-z]+).vtt',
62 asyncMiddleware(getVideoCaption)
63)
64
58// robots.txt service 65// robots.txt service
59staticRouter.get('/robots.txt', (req: express.Request, res: express.Response) => { 66staticRouter.get('/robots.txt', (req: express.Request, res: express.Response) => {
60 res.type('text/plain') 67 res.type('text/plain')
@@ -70,7 +77,17 @@ export {
70// --------------------------------------------------------------------------- 77// ---------------------------------------------------------------------------
71 78
72async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { 79async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) {
73 const path = await VideosPreviewCache.Instance.getPreviewPath(req.params.uuid) 80 const path = await VideosPreviewCache.Instance.getFilePath(req.params.uuid)
81 if (!path) return res.sendStatus(404)
82
83 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })
84}
85
86async function getVideoCaption (req: express.Request, res: express.Response) {
87 const path = await VideosCaptionCache.Instance.getFilePath({
88 videoId: req.params.videoId,
89 language: req.params.captionLanguage
90 })
74 if (!path) return res.sendStatus(404) 91 if (!path) return res.sendStatus(404)
75 92
76 return res.sendFile(path, { maxAge: STATIC_MAX_AGE }) 93 return res.sendFile(path, { maxAge: STATIC_MAX_AGE })