1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Handle .srt subtitles

This commit is contained in:
Chocobozzz 2018-07-16 14:22:16 +02:00
parent 16f7022b06
commit f4001cf408
No known key found for this signature in database
GPG key ID: 583A612D890159BE
20 changed files with 336 additions and 53 deletions

View file

@ -1,12 +1,9 @@
import * as AsyncLRU from 'async-lru'
import { createWriteStream } from 'fs'
import { join } from 'path'
import { unlinkPromise } from '../../helpers/core-utils'
import { logger } from '../../helpers/logger'
import { CACHE, CONFIG } from '../../initializers'
import { VideoModel } from '../../models/video/video'
import { fetchRemoteVideoStaticFile } from '../activitypub'
import { VideoCaptionModel } from '../../models/video/video-caption'
export abstract class AbstractVideoStaticFileCache <T> {
@ -17,9 +14,10 @@ export abstract class AbstractVideoStaticFileCache <T> {
// Load and save the remote file, then return the local path from filesystem
protected abstract loadRemoteFile (key: string): Promise<string>
init (max: number) {
init (max: number, maxAge: number) {
this.lru = new AsyncLRU({
max,
maxAge,
load: (key, cb) => {
this.loadRemoteFile(key)
.then(res => cb(null, res))
@ -28,7 +26,8 @@ export abstract class AbstractVideoStaticFileCache <T> {
})
this.lru.on('evict', (obj: { key: string, value: string }) => {
unlinkPromise(obj.value).then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name))
unlinkPromise(obj.value)
.then(() => logger.debug('%s evicted from %s', obj.value, this.constructor.name))
})
}