X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fthumbnail.ts;h=f33bd31799b302a904591cb2fdcfb7d4cbcae1f6;hb=0c9668f77901e7540e2c7045eb0f2974a4842a69;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..f33bd3179 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 @@ -127,7 +127,7 @@ export class ThumbnailModel extends Model { // Don't block the transaction instance.removeThumbnail() - .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, err)) + .catch(err => logger.error('Cannot remove thumbnail file %s.', instance.filename, { err })) } static loadByFilename (filename: string, thumbnailType: ThumbnailType): Promise { @@ -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 () {