From f4001cf408a99049d01a356bfb20a62342de06ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 Jul 2018 14:22:16 +0200 Subject: Handle .srt subtitles --- server/lib/cache/abstract-video-static-file-cache.ts | 9 ++++----- server/lib/cache/videos-caption-cache.ts | 2 +- server/lib/cache/videos-preview-cache.ts | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'server/lib') 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 @@ 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 { @@ -17,9 +14,10 @@ export abstract class AbstractVideoStaticFileCache { // Load and save the remote file, then return the local path from filesystem protected abstract loadRemoteFile (key: string): Promise - 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 { }) 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)) }) } diff --git a/server/lib/cache/videos-caption-cache.ts b/server/lib/cache/videos-caption-cache.ts index 1336610b2..380d42b2c 100644 --- a/server/lib/cache/videos-caption-cache.ts +++ b/server/lib/cache/videos-caption-cache.ts @@ -42,7 +42,7 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { if (!video) return undefined const remoteStaticPath = videoCaption.getCaptionStaticPath() - const destPath = join(CACHE.DIRECTORIES.VIDEO_CAPTIONS, videoCaption.getCaptionName()) + const destPath = join(CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) } diff --git a/server/lib/cache/videos-preview-cache.ts b/server/lib/cache/videos-preview-cache.ts index 1c0e7ed9d..22b6d9cb0 100644 --- a/server/lib/cache/videos-preview-cache.ts +++ b/server/lib/cache/videos-preview-cache.ts @@ -31,7 +31,7 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.') const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) - const destPath = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName()) + const destPath = join(CACHE.PREVIEWS.DIRECTORY, video.getPreviewName()) return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) } -- cgit v1.2.3