diff options
Diffstat (limited to 'server/models/video')
-rw-r--r-- | server/models/video/video-channel.ts | 19 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 28 | ||||
-rw-r--r-- | server/models/video/video.ts | 29 |
3 files changed, 56 insertions, 20 deletions
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 @@ | |||
1 | import { | 1 | import { |
2 | AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, | 2 | AllowNull, BeforeDestroy, BelongsTo, Column, CreatedAt, DefaultScope, ForeignKey, HasMany, Is, Model, Scopes, Table, |
3 | UpdatedAt | 3 | UpdatedAt, Default |
4 | } from 'sequelize-typescript' | 4 | } from 'sequelize-typescript' |
5 | import { ActivityPubActor } from '../../../shared/models/activitypub' | 5 | import { ActivityPubActor } from '../../../shared/models/activitypub' |
6 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' | 6 | import { VideoChannel } from '../../../shared/models/videos' |
7 | import { | ||
8 | isVideoChannelDescriptionValid, isVideoChannelNameValid, | ||
9 | isVideoChannelSupportValid | ||
10 | } from '../../helpers/custom-validators/video-channels' | ||
7 | import { logger } from '../../helpers/logger' | 11 | import { logger } from '../../helpers/logger' |
8 | import { sendDeleteActor } from '../../lib/activitypub/send' | 12 | import { sendDeleteActor } from '../../lib/activitypub/send' |
9 | import { AccountModel } from '../account/account' | 13 | import { AccountModel } from '../account/account' |
@@ -67,10 +71,17 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
67 | name: string | 71 | name: string |
68 | 72 | ||
69 | @AllowNull(true) | 73 | @AllowNull(true) |
74 | @Default(null) | ||
70 | @Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description')) | 75 | @Is('VideoChannelDescription', value => throwIfNotValid(value, isVideoChannelDescriptionValid, 'description')) |
71 | @Column | 76 | @Column |
72 | description: string | 77 | description: string |
73 | 78 | ||
79 | @AllowNull(true) | ||
80 | @Default(null) | ||
81 | @Is('VideoChannelSupport', value => throwIfNotValid(value, isVideoChannelSupportValid, 'support')) | ||
82 | @Column | ||
83 | support: string | ||
84 | |||
74 | @CreatedAt | 85 | @CreatedAt |
75 | createdAt: Date | 86 | createdAt: Date |
76 | 87 | ||
@@ -221,12 +232,13 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
221 | .findById(id, options) | 232 | .findById(id, options) |
222 | } | 233 | } |
223 | 234 | ||
224 | toFormattedJSON () { | 235 | toFormattedJSON (): VideoChannel { |
225 | const actor = this.Actor.toFormattedJSON() | 236 | const actor = this.Actor.toFormattedJSON() |
226 | const account = { | 237 | const account = { |
227 | id: this.id, | 238 | id: this.id, |
228 | displayName: this.name, | 239 | displayName: this.name, |
229 | description: this.description, | 240 | description: this.description, |
241 | support: this.support, | ||
230 | isLocal: this.Actor.isOwned(), | 242 | isLocal: this.Actor.isOwned(), |
231 | createdAt: this.createdAt, | 243 | createdAt: this.createdAt, |
232 | updatedAt: this.updatedAt | 244 | updatedAt: this.updatedAt |
@@ -240,6 +252,7 @@ export class VideoChannelModel extends Model<VideoChannelModel> { | |||
240 | 252 | ||
241 | return Object.assign(obj, { | 253 | return Object.assign(obj, { |
242 | summary: this.description, | 254 | summary: this.description, |
255 | support: this.support, | ||
243 | attributedTo: [ | 256 | attributedTo: [ |
244 | { | 257 | { |
245 | type: 'Person' as 'Person', | 258 | 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import * as Bluebird from 'bluebird' | ||
2 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 3 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
3 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 4 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 5 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
@@ -115,7 +116,7 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
115 | .then(res => res.map(r => r.Actor)) | 116 | .then(res => res.map(r => r.Actor)) |
116 | } | 117 | } |
117 | 118 | ||
118 | static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction) { | 119 | static loadActorsByVideoOwner (actorOwnerId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> { |
119 | const query = { | 120 | const query = { |
120 | attributes: [], | 121 | attributes: [], |
121 | include: [ | 122 | include: [ |
@@ -152,4 +153,29 @@ export class VideoShareModel extends Model<VideoShareModel> { | |||
152 | return VideoShareModel.scope(ScopeNames.FULL).findAll(query) | 153 | return VideoShareModel.scope(ScopeNames.FULL).findAll(query) |
153 | .then(res => res.map(r => r.Actor)) | 154 | .then(res => res.map(r => r.Actor)) |
154 | } | 155 | } |
156 | |||
157 | static loadActorsByVideoChannel (videoChannelId: number, t: Sequelize.Transaction): Bluebird<ActorModel[]> { | ||
158 | const query = { | ||
159 | attributes: [], | ||
160 | include: [ | ||
161 | { | ||
162 | model: ActorModel, | ||
163 | required: true | ||
164 | }, | ||
165 | { | ||
166 | attributes: [], | ||
167 | model: VideoModel, | ||
168 | required: true, | ||
169 | where: { | ||
170 | channelId: videoChannelId | ||
171 | } | ||
172 | } | ||
173 | ], | ||
174 | transaction: t | ||
175 | } | ||
176 | |||
177 | return VideoShareModel.scope(ScopeNames.FULL) | ||
178 | .findAll(query) | ||
179 | .then(res => res.map(r => r.Actor)) | ||
180 | } | ||
155 | } | 181 | } |
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 { | |||
40 | isVideoLanguageValid, | 40 | isVideoLanguageValid, |
41 | isVideoLicenceValid, | 41 | isVideoLicenceValid, |
42 | isVideoNameValid, | 42 | isVideoNameValid, |
43 | isVideoPrivacyValid | 43 | isVideoPrivacyValid, isVideoSupportValid |
44 | } from '../../helpers/custom-validators/videos' | 44 | } from '../../helpers/custom-validators/videos' |
45 | import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' | 45 | import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' |
46 | import { logger } from '../../helpers/logger' | 46 | import { logger } from '../../helpers/logger' |
@@ -299,6 +299,12 @@ export class VideoModel extends Model<VideoModel> { | |||
299 | @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max)) | 299 | @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.DESCRIPTION.max)) |
300 | description: string | 300 | description: string |
301 | 301 | ||
302 | @AllowNull(true) | ||
303 | @Default(null) | ||
304 | @Is('VideoSupport', value => throwIfNotValid(value, isVideoSupportValid, 'support')) | ||
305 | @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.SUPPORT.max)) | ||
306 | support: string | ||
307 | |||
302 | @AllowNull(false) | 308 | @AllowNull(false) |
303 | @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration')) | 309 | @Is('VideoDuration', value => throwIfNotValid(value, isVideoDurationValid, 'duration')) |
304 | @Column | 310 | @Column |
@@ -841,7 +847,7 @@ export class VideoModel extends Model<VideoModel> { | |||
841 | return join(STATIC_PATHS.PREVIEWS, this.getPreviewName()) | 847 | return join(STATIC_PATHS.PREVIEWS, this.getPreviewName()) |
842 | } | 848 | } |
843 | 849 | ||
844 | toFormattedJSON () { | 850 | toFormattedJSON (): Video { |
845 | let serverHost | 851 | let serverHost |
846 | 852 | ||
847 | if (this.VideoChannel.Account.Actor.Server) { | 853 | if (this.VideoChannel.Account.Actor.Server) { |
@@ -875,10 +881,10 @@ export class VideoModel extends Model<VideoModel> { | |||
875 | embedPath: this.getEmbedPath(), | 881 | embedPath: this.getEmbedPath(), |
876 | createdAt: this.createdAt, | 882 | createdAt: this.createdAt, |
877 | updatedAt: this.updatedAt | 883 | updatedAt: this.updatedAt |
878 | } as Video | 884 | } |
879 | } | 885 | } |
880 | 886 | ||
881 | toFormattedDetailsJSON () { | 887 | toFormattedDetailsJSON (): VideoDetails { |
882 | const formattedJson = this.toFormattedJSON() | 888 | const formattedJson = this.toFormattedJSON() |
883 | 889 | ||
884 | // Maybe our server is not up to date and there are new privacy settings since our version | 890 | // 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<VideoModel> { | |||
888 | const detailsJson = { | 894 | const detailsJson = { |
889 | privacyLabel, | 895 | privacyLabel, |
890 | privacy: this.privacy, | 896 | privacy: this.privacy, |
897 | support: this.support, | ||
891 | descriptionPath: this.getDescriptionPath(), | 898 | descriptionPath: this.getDescriptionPath(), |
892 | channel: this.VideoChannel.toFormattedJSON(), | 899 | channel: this.VideoChannel.toFormattedJSON(), |
893 | account: this.VideoChannel.Account.toFormattedJSON(), | 900 | account: this.VideoChannel.Account.toFormattedJSON(), |
@@ -917,7 +924,7 @@ export class VideoModel extends Model<VideoModel> { | |||
917 | return -1 | 924 | return -1 |
918 | }) | 925 | }) |
919 | 926 | ||
920 | return Object.assign(formattedJson, detailsJson) as VideoDetails | 927 | return Object.assign(formattedJson, detailsJson) |
921 | } | 928 | } |
922 | 929 | ||
923 | toActivityPubObject (): VideoTorrentObject { | 930 | toActivityPubObject (): VideoTorrentObject { |
@@ -957,17 +964,6 @@ export class VideoModel extends Model<VideoModel> { | |||
957 | let dislikesObject | 964 | let dislikesObject |
958 | 965 | ||
959 | if (Array.isArray(this.AccountVideoRates)) { | 966 | if (Array.isArray(this.AccountVideoRates)) { |
960 | const likes: string[] = [] | ||
961 | const dislikes: string[] = [] | ||
962 | |||
963 | for (const rate of this.AccountVideoRates) { | ||
964 | if (rate.type === 'like') { | ||
965 | likes.push(rate.Account.Actor.url) | ||
966 | } else if (rate.type === 'dislike') { | ||
967 | dislikes.push(rate.Account.Actor.url) | ||
968 | } | ||
969 | } | ||
970 | |||
971 | const res = this.toRatesActivityPubObjects() | 967 | const res = this.toRatesActivityPubObjects() |
972 | likesObject = res.likesObject | 968 | likesObject = res.likesObject |
973 | dislikesObject = res.dislikesObject | 969 | dislikesObject = res.dislikesObject |
@@ -1032,6 +1028,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1032 | updated: this.updatedAt.toISOString(), | 1028 | updated: this.updatedAt.toISOString(), |
1033 | mediaType: 'text/markdown', | 1029 | mediaType: 'text/markdown', |
1034 | content: this.getTruncatedDescription(), | 1030 | content: this.getTruncatedDescription(), |
1031 | support: this.support, | ||
1035 | icon: { | 1032 | icon: { |
1036 | type: 'Image', | 1033 | type: 'Image', |
1037 | url: this.getThumbnailUrl(baseUrlHttp), | 1034 | url: this.getThumbnailUrl(baseUrlHttp), |