X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fthumbnail.ts;h=e396784d29124f7f43af55c855c561b5d9506ce2;hb=3d527ba173a37bd61ec8ad742642bb320d12995c;hp=e68a6711fe637aa996cc6f512fae174a0c0cb0fb;hpb=2735a154dc77316e584bc784c65e904df791067f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index e68a6711f..e396784d2 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts @@ -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/typings/models' +import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' @Table({ tableName: 'thumbnail', @@ -90,7 +92,7 @@ export class ThumbnailModel extends Model { @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 { return videoUUID + '.jpg' } - getFileUrl () { + getFileUrl (video: MVideoAccountLight) { + const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename + + if (video.isOwned()) return WEBSERVER.URL + staticPath if (this.fileUrl) return this.fileUrl - const staticPath = ThumbnailModel.types[this.type].staticPath - return WEBSERVER.URL + staticPath + this.filename + // Fallback if we don't have a file URL + return buildRemoteVideoBaseUrl(video, staticPath) } getPath () {