]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/files-cache/abstract-video-static-file-cache.ts
Update translations
[github/Chocobozzz/PeerTube.git] / server / lib / files-cache / abstract-video-static-file-cache.ts
CommitLineData
dc852737 1import { remove } from 'fs-extra'
40e87e9e 2import { logger } from '../../helpers/logger'
41fb13c3 3import memoizee from 'memoizee'
40e87e9e 4
90a8bd30 5type GetFilePathResult = { isOwned: boolean, path: string, downloadName?: string } | undefined
3acc5084 6
40e87e9e
C
7export abstract class AbstractVideoStaticFileCache <T> {
8
3acc5084 9 getFilePath: (params: T) => Promise<GetFilePathResult>
40e87e9e 10
3acc5084 11 abstract getFilePathImpl (params: T): Promise<GetFilePathResult>
40e87e9e
C
12
13 // Load and save the remote file, then return the local path from filesystem
3acc5084 14 protected abstract loadRemoteFile (key: string): Promise<GetFilePathResult>
40e87e9e 15
f4001cf4 16 init (max: number, maxAge: number) {
e8bafea3 17 this.getFilePath = memoizee(this.getFilePathImpl, {
f4001cf4 18 maxAge,
e8bafea3
C
19 max,
20 promise: true,
ec893ae0
C
21 dispose: (result?: GetFilePathResult) => {
22 if (result && result.isOwned !== true) {
3acc5084
C
23 remove(result.path)
24 .then(() => logger.debug('%s removed from %s', result.path, this.constructor.name))
25 .catch(err => logger.error('Cannot remove %s from cache %s.', result.path, this.constructor.name, { err }))
26 }
40e87e9e
C
27 }
28 })
40e87e9e 29 }
40e87e9e 30}