From 2422c46b27790d94fd29a7092170cee5a1b56008 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Feb 2018 14:46:26 +0100 Subject: Implement support field in video and video channel --- server/models/video/video.ts | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'server/models/video/video.ts') diff --git a/server/models/video/video.ts b/server/models/video/video.ts index ff82fb3b2..d748e81bd 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -40,7 +40,7 @@ import { isVideoLanguageValid, isVideoLicenceValid, isVideoNameValid, - isVideoPrivacyValid + isVideoPrivacyValid, isVideoSupportValid } from '../../helpers/custom-validators/videos' import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' import { logger } from '../../helpers/logger' @@ -299,6 +299,12 @@ export class VideoModel extends Model { @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max)) description: string + @AllowNull(true) + @Default(null) + @Is('VideoSupport', value => throwIfNotValid(value, isVideoSupportValid, 'support')) + @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.SUPPORT.max)) + support: string + @AllowNull(false) @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration')) @Column @@ -841,7 +847,7 @@ export class VideoModel extends Model { return join(STATIC_PATHS.PREVIEWS, this.getPreviewName()) } - toFormattedJSON () { + toFormattedJSON (): Video { let serverHost if (this.VideoChannel.Account.Actor.Server) { @@ -875,10 +881,10 @@ export class VideoModel extends Model { embedPath: this.getEmbedPath(), createdAt: this.createdAt, updatedAt: this.updatedAt - } as Video + } } - toFormattedDetailsJSON () { + toFormattedDetailsJSON (): VideoDetails { const formattedJson = this.toFormattedJSON() // Maybe our server is not up to date and there are new privacy settings since our version @@ -888,6 +894,7 @@ export class VideoModel extends Model { const detailsJson = { privacyLabel, privacy: this.privacy, + support: this.support, descriptionPath: this.getDescriptionPath(), channel: this.VideoChannel.toFormattedJSON(), account: this.VideoChannel.Account.toFormattedJSON(), @@ -917,7 +924,7 @@ export class VideoModel extends Model { return -1 }) - return Object.assign(formattedJson, detailsJson) as VideoDetails + return Object.assign(formattedJson, detailsJson) } toActivityPubObject (): VideoTorrentObject { @@ -957,17 +964,6 @@ export class VideoModel extends Model { let dislikesObject if (Array.isArray(this.AccountVideoRates)) { - const likes: string[] = [] - const dislikes: string[] = [] - - for (const rate of this.AccountVideoRates) { - if (rate.type === 'like') { - likes.push(rate.Account.Actor.url) - } else if (rate.type === 'dislike') { - dislikes.push(rate.Account.Actor.url) - } - } - const res = this.toRatesActivityPubObjects() likesObject = res.likesObject dislikesObject = res.dislikesObject @@ -1032,6 +1028,7 @@ export class VideoModel extends Model { updated: this.updatedAt.toISOString(), mediaType: 'text/markdown', content: this.getTruncatedDescription(), + support: this.support, icon: { type: 'Image', url: this.getThumbnailUrl(baseUrlHttp), -- cgit v1.2.3