X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fthumbnail.ts;h=05c58cf19cc57b5bd494b9b82f37dffb0a06ad54;hb=dbd9fb44ddd880622265097bd7baf4dd71ea0861;hp=3d885f6544fe0eb1d9899fcea89504d36953ad85;hpb=a35a22797c99f17924347da9a226068c3dbe4787;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts index 3d885f654..05c58cf19 100644 --- a/server/models/video/thumbnail.ts +++ b/server/models/video/thumbnail.ts @@ -15,9 +15,9 @@ import { Table, UpdatedAt } from 'sequelize-typescript' -import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub' import { afterCommitIfTransaction } from '@server/helpers/database-utils' -import { MThumbnail, MThumbnailVideo, MVideoAccountLight } from '@server/types/models' +import { MThumbnail, MThumbnailVideo, MVideo } from '@server/types/models' +import { AttributesOnly } from '@shared/typescript-utils' import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { logger } from '../../helpers/logger' import { CONFIG } from '../../initializers/config' @@ -41,7 +41,7 @@ import { VideoPlaylistModel } from './video-playlist' } ] }) -export class ThumbnailModel extends Model { +export class ThumbnailModel extends Model>> { @AllowNull(false) @Column @@ -158,24 +158,26 @@ export class ThumbnailModel extends Model { return ThumbnailModel.findOne(query) } - getFileUrl (video: MVideoAccountLight) { + static buildPath (type: ThumbnailType, filename: string) { + const directory = ThumbnailModel.types[type].directory + + return join(directory, filename) + } + + getFileUrl (video: MVideo) { const staticPath = ThumbnailModel.types[this.type].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) + return this.fileUrl } getPath () { - const directory = ThumbnailModel.types[this.type].directory - return join(directory, this.filename) + return ThumbnailModel.buildPath(this.type, this.filename) } getPreviousPath () { - const directory = ThumbnailModel.types[this.type].directory - return join(directory, this.previousThumbnailFilename) + return ThumbnailModel.buildPath(this.type, this.previousThumbnailFilename) } removeThumbnail () {