From 3acc50844047a37698f0618fa235c138e386a053 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Apr 2019 09:50:57 +0200 Subject: Upgrade sequelize --- .../files-cache/abstract-video-static-file-cache.ts | 18 +++++++++++------- server/lib/files-cache/videos-caption-cache.ts | 9 +++++++-- server/lib/files-cache/videos-preview-cache.ts | 6 ++++-- 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'server/lib/files-cache') 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' import { fetchRemoteVideoStaticFile } from '../activitypub' import * as memoizee from 'memoizee' +type GetFilePathResult = { isOwned: boolean, path: string } | undefined + export abstract class AbstractVideoStaticFileCache { - getFilePath: (params: T) => Promise + getFilePath: (params: T) => Promise - abstract getFilePathImpl (params: T): Promise + abstract getFilePathImpl (params: T): Promise // Load and save the remote file, then return the local path from filesystem - protected abstract loadRemoteFile (key: string): Promise + protected abstract loadRemoteFile (key: string): Promise 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 })) + } } }) } diff --git a/server/lib/files-cache/videos-caption-cache.ts b/server/lib/files-cache/videos-caption-cache.ts index d4a0a3345..305e39c35 100644 --- a/server/lib/files-cache/videos-caption-cache.ts +++ b/server/lib/files-cache/videos-caption-cache.ts @@ -4,6 +4,7 @@ import { VideoModel } from '../../models/video/video' import { VideoCaptionModel } from '../../models/video/video-caption' import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' import { CONFIG } from '../../initializers/config' +import { logger } from '../../helpers/logger' type GetPathParam = { videoId: string, language: string } @@ -24,13 +25,15 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(params.videoId, params.language) if (!videoCaption) return undefined - if (videoCaption.isOwned()) return join(CONFIG.STORAGE.CAPTIONS_DIR, videoCaption.getCaptionName()) + if (videoCaption.isOwned()) return { isOwned: true, path: join(CONFIG.STORAGE.CAPTIONS_DIR, videoCaption.getCaptionName()) } const key = params.videoId + VideosCaptionCache.KEY_DELIMITER + params.language return this.loadRemoteFile(key) } protected async loadRemoteFile (key: string) { + logger.debug('Loading remote caption file %s.', key) + const [ videoId, language ] = key.split(VideosCaptionCache.KEY_DELIMITER) const videoCaption = await VideoCaptionModel.loadByVideoIdAndLanguage(videoId, language) @@ -46,7 +49,9 @@ class VideosCaptionCache extends AbstractVideoStaticFileCache { const remoteStaticPath = videoCaption.getCaptionStaticPath() const destPath = join(FILES_CACHE.VIDEO_CAPTIONS.DIRECTORY, videoCaption.getCaptionName()) - return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) + const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) + + return { isOwned: false, path } } } diff --git a/server/lib/files-cache/videos-preview-cache.ts b/server/lib/files-cache/videos-preview-cache.ts index fc0d92c78..c117ae426 100644 --- a/server/lib/files-cache/videos-preview-cache.ts +++ b/server/lib/files-cache/videos-preview-cache.ts @@ -20,7 +20,7 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { const video = await VideoModel.loadByUUIDWithFile(videoUUID) if (!video) return undefined - if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreview().filename) + if (video.isOwned()) return { isOwned: true, path: join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreview().filename) } return this.loadRemoteFile(videoUUID) } @@ -35,7 +35,9 @@ class VideosPreviewCache extends AbstractVideoStaticFileCache { const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreview().filename) const destPath = join(FILES_CACHE.PREVIEWS.DIRECTORY, video.getPreview().filename) - return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) + const path = await this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) + + return { isOwned: false, path } } } -- cgit v1.2.3