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/account/account.ts | 29 ++++++++++++++++++++++++++--- server/models/activitypub/actor.ts | 23 ++++++++++++++++++++--- server/models/video/video-channel.ts | 19 ++++++++++++++++--- server/models/video/video-share.ts | 28 +++++++++++++++++++++++++++- server/models/video/video.ts | 29 +++++++++++++---------------- 5 files changed, 102 insertions(+), 26 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account.ts b/server/models/account/account.ts index 20724ae0c..d8f305c37 100644 --- a/server/models/account/account.ts +++ b/server/models/account/account.ts @@ -1,16 +1,28 @@ import * as Sequelize from 'sequelize' import { - AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Model, Table, + AllowNull, + BeforeDestroy, + BelongsTo, + Column, + CreatedAt, + Default, + DefaultScope, + ForeignKey, + HasMany, + Is, + Model, + Table, UpdatedAt } from 'sequelize-typescript' import { Account } from '../../../shared/models/actors' +import { isAccountDescriptionValid } from '../../helpers/custom-validators/accounts' import { logger } from '../../helpers/logger' import { sendDeleteActor } from '../../lib/activitypub/send' import { ActorModel } from '../activitypub/actor' import { ApplicationModel } from '../application/application' import { AvatarModel } from '../avatar/avatar' import { ServerModel } from '../server/server' -import { getSort } from '../utils' +import { getSort, throwIfNotValid } from '../utils' import { VideoChannelModel } from '../video/video-channel' import { VideoCommentModel } from '../video/video-comment' import { UserModel } from './user' @@ -42,6 +54,12 @@ export class AccountModel extends Model { @Column name: string + @AllowNull(true) + @Default(null) + @Is('AccountDescription', value => throwIfNotValid(value, isAccountDescriptionValid, 'description')) + @Column + description: string + @CreatedAt createdAt: Date @@ -196,6 +214,7 @@ export class AccountModel extends Model { const account = { id: this.id, displayName: this.name, + description: this.description, createdAt: this.createdAt, updatedAt: this.updatedAt } @@ -204,7 +223,11 @@ export class AccountModel extends Model { } toActivityPubObject () { - return this.Actor.toActivityPubObject(this.name, 'Account') + const obj = this.Actor.toActivityPubObject(this.name, 'Account') + + return Object.assign(obj, { + summary: this.description + }) } isOwned () { diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index c79bba96b..1d0e54ee3 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts @@ -2,14 +2,31 @@ import { values } from 'lodash' import { extname } from 'path' import * as Sequelize from 'sequelize' import { - AllowNull, BelongsTo, Column, CreatedAt, DataType, Default, DefaultScope, ForeignKey, HasMany, HasOne, Is, IsUUID, Model, Scopes, - Table, UpdatedAt + AllowNull, + BelongsTo, + Column, + CreatedAt, + DataType, + Default, + DefaultScope, + ForeignKey, + HasMany, + HasOne, + Is, + IsUUID, + Model, + Scopes, + Table, + UpdatedAt } from 'sequelize-typescript' import { ActivityPubActorType } from '../../../shared/models/activitypub' import { Avatar } from '../../../shared/models/avatars/avatar.model' import { activityPubContextify } from '../../helpers/activitypub' import { - isActorFollowersCountValid, isActorFollowingCountValid, isActorPreferredUsernameValid, isActorPrivateKeyValid, + isActorFollowersCountValid, + isActorFollowingCountValid, + isActorPreferredUsernameValid, + isActorPrivateKeyValid, isActorPublicKeyValid } from '../../helpers/custom-validators/activitypub/actor' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index 7c161c864..289775a0f 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -1,9 +1,13 @@ import { AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, - UpdatedAt + UpdatedAt, Default } from 'sequelize-typescript' import { ActivityPubActor } from '../../../shared/models/activitypub' -import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' +import { VideoChannel } from '../../../shared/models/videos' +import { + isVideoChannelDescriptionValid, isVideoChannelNameValid, + isVideoChannelSupportValid +} from '../../helpers/custom-validators/video-channels' import { logger } from '../../helpers/logger' import { sendDeleteActor } from '../../lib/activitypub/send' import { AccountModel } from '../account/account' @@ -67,10 +71,17 @@ export class VideoChannelModel extends Model { name: string @AllowNull(true) + @Default(null) @Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description')) @Column description: string + @AllowNull(true) + @Default(null) + @Is('VideoChannelSupport', value => throwIfNotValid(value, isVideoChannelSupportValid, 'support')) + @Column + support: string + @CreatedAt createdAt: Date @@ -221,12 +232,13 @@ export class VideoChannelModel extends Model { .findById(id, options) } - toFormattedJSON () { + toFormattedJSON (): VideoChannel { const actor = this.Actor.toFormattedJSON() const account = { id: this.id, displayName: this.name, description: this.description, + support: this.support, isLocal: this.Actor.isOwned(), createdAt: this.createdAt, updatedAt: this.updatedAt @@ -240,6 +252,7 @@ export class VideoChannelModel extends Model { return Object.assign(obj, { summary: this.description, + support: this.support, attributedTo: [ { type: 'Person' as 'Person', diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 48ba68a4a..6f770957f 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,4 +1,5 @@ import * as Sequelize from 'sequelize' +import * as Bluebird from 'bluebird' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { CONSTRAINTS_FIELDS } from '../../initializers' @@ -115,7 +116,7 @@ export class VideoShareModel extends Model { .then(res => res.map(r => r.Actor)) } - static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) { + static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird { const query = { attributes: [], include: [ @@ -152,4 +153,29 @@ export class VideoShareModel extends Model { return VideoShareModel.scope(ScopeNames.FULL).findAll(query) .then(res => res.map(r => r.Actor)) } + + static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird { + const query = { + attributes: [], + include: [ + { + model: ActorModel, + required: true + }, + { + attributes: [], + model: VideoModel, + required: true, + where: { + channelId: videoChannelId + } + } + ], + transaction: t + } + + return VideoShareModel.scope(ScopeNames.FULL) + .findAll(query) + .then(res => res.map(r => r.Actor)) + } } 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