mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Upgrade sequelize
This commit is contained in:
parent
1735c82572
commit
3acc508440
48 changed files with 457 additions and 466 deletions
|
@ -4,24 +4,28 @@ import { VideoModel } from '../../models/video/video'
|
|||
import { fetchRemoteVideoStaticFile } from '../activitypub'
|
||||
import * as memoizee from 'memoizee'
|
||||
|
||||
type GetFilePathResult = { isOwned: boolean, path: string } | undefined
|
||||
|
||||
export abstract class AbstractVideoStaticFileCache <T> {
|
||||
|
||||
getFilePath: (params: T) => Promise<string>
|
||||
getFilePath: (params: T) => Promise<GetFilePathResult>
|
||||
|
||||
abstract getFilePathImpl (params: T): Promise<string>
|
||||
abstract getFilePathImpl (params: T): Promise<GetFilePathResult>
|
||||
|
||||
// Load and save the remote file, then return the local path from filesystem
|
||||
protected abstract loadRemoteFile (key: string): Promise<string>
|
||||
protected abstract loadRemoteFile (key: string): Promise<GetFilePathResult>
|
||||
|
||||
init (max: number, maxAge: number) {
|
||||
this.getFilePath = memoizee(this.getFilePathImpl, {
|
||||
maxAge,
|
||||
max,
|
||||
promise: true,
|
||||
dispose: (value: string) => {
|
||||
remove(value)
|
||||
.then(() => logger.debug('%s evicted from %s', value, this.constructor.name))
|
||||
.catch(err => logger.error('Cannot remove %s from cache %s.', value, this.constructor.name, { err }))
|
||||
dispose: (result: GetFilePathResult) => {
|
||||
if (result.isOwned !== true) {
|
||||
remove(result.path)
|
||||
.then(() => logger.debug('%s removed from %s', result.path, this.constructor.name))
|
||||
.catch(err => logger.error('Cannot remove %s from cache %s.', result.path, this.constructor.name, { err }))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue