diff options
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/cache/abstract-video-static-file-cache.ts | 9 | ||||
-rw-r--r-- | server/lib/cache/videos-caption-cache.ts | 2 | ||||
-rw-r--r-- | server/lib/cache/videos-preview-cache.ts | 2 |
3 files changed, 6 insertions, 7 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 @@ | |||
1 | import * as AsyncLRU from 'async-lru' | 1 | import * as AsyncLRU from 'async-lru' |
2 | import { createWriteStream } from 'fs' | 2 | import { createWriteStream } from 'fs' |
3 | import { join } from 'path' | ||
4 | import { unlinkPromise } from '../../helpers/core-utils' | 3 | import { unlinkPromise } from '../../helpers/core-utils' |
5 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
6 | import { CACHE, CONFIG } from '../../initializers' | ||
7 | import { VideoModel } from '../../models/video/video' | 5 | import { VideoModel } from '../../models/video/video' |
8 | import { fetchRemoteVideoStaticFile } from '../activitypub' | 6 | import { fetchRemoteVideoStaticFile } from '../activitypub' |
9 | import { VideoCaptionModel } from '../../models/video/video-caption' | ||
10 | 7 | ||
11 | export abstract class AbstractVideoStaticFileCache <T> { | 8 | export 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 | ||
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 <GetPathParam> { | |||
42 | if (!video) return undefined | 42 | if (!video) return undefined |
43 | 43 | ||
44 | const remoteStaticPath = videoCaption.getCaptionStaticPath() | 44 | const remoteStaticPath = videoCaption.getCaptionStaticPath() |
45 | const destPath = join(CACHE.DIRECTORIES.VIDEO_CAPTIONS, videoCaption.getCaptionName()) | 45 | const destPath = join(CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) |
46 | 46 | ||
47 | return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) | 47 | return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) |
48 | } | 48 | } |
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 <string> { | |||
31 | if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.') | 31 | if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.') |
32 | 32 | ||
33 | const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) | 33 | const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) |
34 | const destPath = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName()) | 34 | const destPath = join(CACHE.PREVIEWS.DIRECTORY, video.getPreviewName()) |
35 | 35 | ||
36 | return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) | 36 | return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) |
37 | } | 37 | } |