]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video/thumbnail.ts
Fix RSS feed when HLS only is enabled
[github/Chocobozzz/PeerTube.git] / server / models / video / thumbnail.ts
index 3b011b1d285de4fb1caf5e44f4f5a2a020b377ed..20c1e5858a13e7d5478499ebaef8e42567429d0a 100644 (file)
@@ -19,6 +19,8 @@ import { CONFIG } from '../../initializers/config'
 import { VideoModel } from './video'
 import { VideoPlaylistModel } from './video-playlist'
 import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
+import { MVideoAccountLight } from '@server/types/models'
+import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
 
 @Table({
   tableName: 'thumbnail',
@@ -90,7 +92,7 @@ export class ThumbnailModel extends Model<ThumbnailModel> {
   @UpdatedAt
   updatedAt: Date
 
-  private static types: { [ id in ThumbnailType ]: { label: string, directory: string, staticPath: string } } = {
+  private static readonly types: { [ id in ThumbnailType ]: { label: string, directory: string, staticPath: string } } = {
     [ThumbnailType.MINIATURE]: {
       label: 'miniature',
       directory: CONFIG.STORAGE.THUMBNAILS_DIR,
@@ -126,11 +128,14 @@ export class ThumbnailModel extends Model<ThumbnailModel> {
     return videoUUID + '.jpg'
   }
 
-  getFileUrl (isLocal: boolean) {
-    if (isLocal === false) return this.fileUrl
+  getFileUrl (video: MVideoAccountLight) {
+    const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
 
-    const staticPath = ThumbnailModel.types[this.type].staticPath
-    return WEBSERVER.URL + staticPath + this.filename
+    if (video.isOwned()) return WEBSERVER.URL + staticPath
+    if (this.fileUrl) return this.fileUrl
+
+    // Fallback if we don't have a file URL
+    return buildRemoteVideoBaseUrl(video, staticPath)
   }
 
   getPath () {