diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-12 19:02:00 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-16 11:50:08 +0200 |
commit | 40e87e9ecc54e3513fb586928330a7855eb192c6 (patch) | |
tree | af1111ecba85f9cd8286811ff332a67cf21be2f6 /server/controllers/static.ts | |
parent | d4557fd3ecc8d4ed4fb0e5c868929bc36c959ed2 (diff) | |
download | PeerTube-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.ts | 21 |
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 '../ | |||
4 | import { VideosPreviewCache } from '../lib/cache' | 4 | import { VideosPreviewCache } from '../lib/cache' |
5 | import { asyncMiddleware, videosGetValidator } from '../middlewares' | 5 | import { asyncMiddleware, videosGetValidator } from '../middlewares' |
6 | import { VideoModel } from '../models/video/video' | 6 | import { VideoModel } from '../models/video/video' |
7 | import { VideosCaptionCache } from '../lib/cache/videos-caption-cache' | ||
7 | 8 | ||
8 | const staticRouter = express.Router() | 9 | const 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 |
53 | staticRouter.use( | 54 | staticRouter.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 | ||
60 | staticRouter.use( | ||
61 | STATIC_PATHS.VIDEO_CAPTIONS + ':videoId-:captionLanguage([a-z]+).vtt', | ||
62 | asyncMiddleware(getVideoCaption) | ||
63 | ) | ||
64 | |||
58 | // robots.txt service | 65 | // robots.txt service |
59 | staticRouter.get('/robots.txt', (req: express.Request, res: express.Response) => { | 66 | staticRouter.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 | ||
72 | async function getPreview (req: express.Request, res: express.Response, next: express.NextFunction) { | 79 | async 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 | |||
86 | async 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 }) |