diff options
Diffstat (limited to 'server/lib/files-cache/abstract-video-static-file-cache.ts')
-rw-r--r-- | server/lib/files-cache/abstract-video-static-file-cache.ts | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/server/lib/files-cache/abstract-video-static-file-cache.ts b/server/lib/files-cache/abstract-video-static-file-cache.ts index 61837e0f8..84ed74c98 100644 --- a/server/lib/files-cache/abstract-video-static-file-cache.ts +++ b/server/lib/files-cache/abstract-video-static-file-cache.ts | |||
@@ -4,24 +4,28 @@ import { VideoModel } from '../../models/video/video' | |||
4 | import { fetchRemoteVideoStaticFile } from '../activitypub' | 4 | import { fetchRemoteVideoStaticFile } from '../activitypub' |
5 | import * as memoizee from 'memoizee' | 5 | import * as memoizee from 'memoizee' |
6 | 6 | ||
7 | type GetFilePathResult = { isOwned: boolean, path: string } | undefined | ||
8 | |||
7 | export abstract class AbstractVideoStaticFileCache <T> { | 9 | export abstract class AbstractVideoStaticFileCache <T> { |
8 | 10 | ||
9 | getFilePath: (params: T) => Promise<string> | 11 | getFilePath: (params: T) => Promise<GetFilePathResult> |
10 | 12 | ||
11 | abstract getFilePathImpl (params: T): Promise<string> | 13 | abstract getFilePathImpl (params: T): Promise<GetFilePathResult> |
12 | 14 | ||
13 | // Load and save the remote file, then return the local path from filesystem | 15 | // Load and save the remote file, then return the local path from filesystem |
14 | protected abstract loadRemoteFile (key: string): Promise<string> | 16 | protected abstract loadRemoteFile (key: string): Promise<GetFilePathResult> |
15 | 17 | ||
16 | init (max: number, maxAge: number) { | 18 | init (max: number, maxAge: number) { |
17 | this.getFilePath = memoizee(this.getFilePathImpl, { | 19 | this.getFilePath = memoizee(this.getFilePathImpl, { |
18 | maxAge, | 20 | maxAge, |
19 | max, | 21 | max, |
20 | promise: true, | 22 | promise: true, |
21 | dispose: (value: string) => { | 23 | dispose: (result: GetFilePathResult) => { |
22 | remove(value) | 24 | if (result.isOwned !== true) { |
23 | .then(() => logger.debug('%s evicted from %s', value, this.constructor.name)) | 25 | remove(result.path) |
24 | .catch(err => logger.error('Cannot remove %s from cache %s.', value, this.constructor.name, { err })) | 26 | .then(() => logger.debug('%s removed from %s', result.path, this.constructor.name)) |
27 | .catch(err => logger.error('Cannot remove %s from cache %s.', result.path, this.constructor.name, { err })) | ||
28 | } | ||
25 | } | 29 | } |
26 | }) | 30 | }) |
27 | } | 31 | } |