aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/cache/abstract-video-static-file-cache.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-07-16 14:22:16 +0200
committerChocobozzz <me@florianbigard.com>2018-07-16 14:31:40 +0200
commitf4001cf408a99049d01a356bfb20a62342de06ea (patch)
tree421776dfe64335dca2725ac3ac5f3b3e6b7564c6 /server/lib/cache/abstract-video-static-file-cache.ts
parent16f7022b06fb76c0b00c23c970bc8df605b0ec63 (diff)
downloadPeerTube-f4001cf408a99049d01a356bfb20a62342de06ea.tar.gz
PeerTube-f4001cf408a99049d01a356bfb20a62342de06ea.tar.zst
PeerTube-f4001cf408a99049d01a356bfb20a62342de06ea.zip
Handle .srt subtitles
Diffstat (limited to 'server/lib/cache/abstract-video-static-file-cache.ts')
-rw-r--r--server/lib/cache/abstract-video-static-file-cache.ts9
1 files changed, 4 insertions, 5 deletions
diff --git a/server/lib/cache/abstract-video-static-file-cache.ts b/server/lib/cache/abstract-video-static-file-cache.ts
index 7eeeb6b3a..8e895cc82 100644
--- a/server/lib/cache/abstract-video-static-file-cache.ts
+++ b/server/lib/cache/abstract-video-static-file-cache.ts
@@ -1,12 +1,9 @@
1import * as AsyncLRU from 'async-lru' 1import * as AsyncLRU from 'async-lru'
2import { createWriteStream } from 'fs' 2import { createWriteStream } from 'fs'
3import { join } from 'path'
4import { unlinkPromise } from '../../helpers/core-utils' 3import { unlinkPromise } from '../../helpers/core-utils'
5import { logger } from '../../helpers/logger' 4import { logger } from '../../helpers/logger'
6import { CACHE, CONFIG } from '../../initializers'
7import { VideoModel } from '../../models/video/video' 5import { VideoModel } from '../../models/video/video'
8import { fetchRemoteVideoStaticFile } from '../activitypub' 6import { fetchRemoteVideoStaticFile } from '../activitypub'
9import { VideoCaptionModel } from '../../models/video/video-caption'
10 7
11export abstract class AbstractVideoStaticFileCache <T> { 8export abstract class AbstractVideoStaticFileCache <T> {
12 9
@@ -17,9 +14,10 @@ export abstract class AbstractVideoStaticFileCache <T> {
17 // Load and save the remote file, then return the local path from filesystem 14 // Load and save the remote file, then return the local path from filesystem
18 protected abstract loadRemoteFile (key: string): Promise<string> 15 protected abstract loadRemoteFile (key: string): Promise<string>
19 16
20 init (max: number) { 17 init (max: number, maxAge: number) {
21 this.lru = new AsyncLRU({ 18 this.lru = new AsyncLRU({
22 max, 19 max,
20 maxAge,
23 load: (key, cb) => { 21 load: (key, cb) => {
24 this.loadRemoteFile(key) 22 this.loadRemoteFile(key)
25 .then(res => cb(null, res)) 23 .then(res => cb(null, res))
@@ -28,7 +26,8 @@ export abstract class AbstractVideoStaticFileCache <T> {
28 }) 26 })
29 27
30 this.lru.on('evict', (obj: { key: string, value: string }) => { 28 this.lru.on('evict', (obj: { key: string, value: string }) => {
31 unlinkPromise(obj.value).then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name)) 29 unlinkPromise(obj.value)
30 .then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name))
32 }) 31 })
33 } 32 }
34 33