]>
Commit | Line | Data |
---|---|---|
3fd3ab2d | 1 | import { join } from 'path' |
40e87e9e | 2 | import { CACHE, CONFIG, STATIC_PATHS } from '../../initializers' |
3fd3ab2d | 3 | import { VideoModel } from '../../models/video/video' |
40e87e9e | 4 | import { AbstractVideoStaticFileCache } from './abstract-video-static-file-cache' |
f981dae8 | 5 | |
40e87e9e | 6 | class VideosPreviewCache extends AbstractVideoStaticFileCache <string> { |
f981dae8 C |
7 | |
8 | private static instance: VideosPreviewCache | |
9 | ||
40e87e9e C |
10 | private constructor () { |
11 | super() | |
12 | } | |
f981dae8 C |
13 | |
14 | static get Instance () { | |
15 | return this.instance || (this.instance = new this()) | |
16 | } | |
17 | ||
40e87e9e C |
18 | async getFilePath (videoUUID: string) { |
19 | const video = await VideoModel.loadByUUID(videoUUID) | |
8fa5653a C |
20 | if (!video) return undefined |
21 | ||
22 | if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName()) | |
23 | ||
40e87e9e | 24 | return this.loadFromLRU(videoUUID) |
f981dae8 C |
25 | } |
26 | ||
40e87e9e | 27 | protected async loadRemoteFile (key: string) { |
5f0805d3 | 28 | const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(key) |
f5028693 | 29 | if (!video) return undefined |
f981dae8 | 30 | |
40e87e9e | 31 | if (video.isOwned()) throw new Error('Cannot load remote preview of owned video.') |
f981dae8 | 32 | |
40e87e9e C |
33 | const remoteStaticPath = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) |
34 | const destPath = join(CACHE.DIRECTORIES.PREVIEWS, video.getPreviewName()) | |
f981dae8 | 35 | |
40e87e9e | 36 | return this.saveRemoteVideoFileAndReturnPath(video, remoteStaticPath, destPath) |
f981dae8 C |
37 | } |
38 | } | |
39 | ||
40 | export { | |
41 | VideosPreviewCache | |
42 | } |