aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/lib/cache/videos-preview-cache.ts11
-rw-r--r--server/models/video/video.ts12
2 files changed, 20 insertions, 3 deletions
diff --git a/server/lib/cache/videos-preview-cache.ts b/server/lib/cache/videos-preview-cache.ts
index c5bda8dd8..28908b186 100644
--- a/server/lib/cache/videos-preview-cache.ts
+++ b/server/lib/cache/videos-preview-cache.ts
@@ -33,7 +33,12 @@ class VideosPreviewCache {
33 }) 33 })
34 } 34 }
35 35
36 getPreviewPath (key: string) { 36 async getPreviewPath (key: string) {
37 const video = await VideoModel.loadByUUID(key)
38 if (!video) return undefined
39
40 if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName())
41
37 return new Promise<string>((res, rej) => { 42 return new Promise<string>((res, rej) => {
38 this.lru.get(key, (err, value) => { 43 this.lru.get(key, (err, value) => {
39 err ? rej(err) : res(value) 44 err ? rej(err) : res(value)
@@ -42,10 +47,10 @@ class VideosPreviewCache {
42 } 47 }
43 48
44 private async loadPreviews (key: string) { 49 private async loadPreviews (key: string) {
45 const video = await VideoModel.loadByUUIDAndPopulateAccountAndServerAndTags(key) 50 const video = await VideoModel.loadByUUID(key)
46 if (!video) return undefined 51 if (!video) return undefined
47 52
48 if (video.isOwned()) return join(CONFIG.STORAGE.PREVIEWS_DIR, video.getPreviewName()) 53 if (video.isOwned()) throw new Error('Cannot load preview of owned video.')
49 54
50 const res = await this.saveRemotePreviewAndReturnPath(video) 55 const res = await this.saveRemotePreviewAndReturnPath(video)
51 56
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 97fdbc8ef..8c49bc3af 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -528,6 +528,18 @@ export class VideoModel extends Model<VideoModel> {
528 .findById(id, options) 528 .findById(id, options)
529 } 529 }
530 530
531 static loadByUUID (uuid: string) {
532 const options = {
533 where: {
534 uuid
535 }
536 }
537
538 return VideoModel
539 .scope([ ScopeNames.WITH_FILES ])
540 .findOne(options)
541 }
542
531 static loadByUUIDAndPopulateAccountAndServerAndTags (uuid: string) { 543 static loadByUUIDAndPopulateAccountAndServerAndTags (uuid: string) {
532 const options = { 544 const options = {
533 order: [ [ 'Tags', 'name', 'ASC' ] ], 545 order: [ [ 'Tags', 'name', 'ASC' ] ],