diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/video/video-share.ts | 15 | ||||
-rw-r--r-- | server/models/video/video.ts | 46 |
2 files changed, 52 insertions, 9 deletions
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 56576f98c..48ba68a4a 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts | |||
@@ -1,7 +1,10 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' | 2 | 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 { CONSTRAINTS_FIELDS } from '../../initializers' | ||
3 | import { AccountModel } from '../account/account' | 5 | import { AccountModel } from '../account/account' |
4 | import { ActorModel } from '../activitypub/actor' | 6 | import { ActorModel } from '../activitypub/actor' |
7 | import { throwIfNotValid } from '../utils' | ||
5 | import { VideoModel } from './video' | 8 | import { VideoModel } from './video' |
6 | import { VideoChannelModel } from './video-channel' | 9 | import { VideoChannelModel } from './video-channel' |
7 | 10 | ||
@@ -40,10 +43,20 @@ enum ScopeNames { | |||
40 | }, | 43 | }, |
41 | { | 44 | { |
42 | fields: [ 'videoId' ] | 45 | fields: [ 'videoId' ] |
46 | }, | ||
47 | { | ||
48 | fields: [ 'url' ], | ||
49 | unique: true | ||
43 | } | 50 | } |
44 | ] | 51 | ] |
45 | }) | 52 | }) |
46 | export class VideoShareModel extends Model<VideoShareModel> { | 53 | export class VideoShareModel extends Model<VideoShareModel> { |
54 | |||
55 | @AllowNull(false) | ||
56 | @Is('VideoShareUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) | ||
57 | @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_SHARE.URL.max)) | ||
58 | url: string | ||
59 | |||
47 | @CreatedAt | 60 | @CreatedAt |
48 | createdAt: Date | 61 | createdAt: Date |
49 | 62 | ||
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 81d8a64ff..bd834b088 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -5,8 +5,26 @@ import * as parseTorrent from 'parse-torrent' | |||
5 | import { join } from 'path' | 5 | import { join } from 'path' |
6 | import * as Sequelize from 'sequelize' | 6 | import * as Sequelize from 'sequelize' |
7 | import { | 7 | import { |
8 | AfterDestroy, AllowNull, BeforeDestroy, BelongsTo, BelongsToMany, Column, CreatedAt, DataType, Default, ForeignKey, HasMany, | 8 | AfterDestroy, |
9 | IFindOptions, Is, IsInt, IsUUID, Min, Model, Scopes, Table, UpdatedAt | 9 | AllowNull, |
10 | BeforeDestroy, | ||
11 | BelongsTo, | ||
12 | BelongsToMany, | ||
13 | Column, | ||
14 | CreatedAt, | ||
15 | DataType, | ||
16 | Default, | ||
17 | ForeignKey, | ||
18 | HasMany, | ||
19 | IFindOptions, | ||
20 | Is, | ||
21 | IsInt, | ||
22 | IsUUID, | ||
23 | Min, | ||
24 | Model, | ||
25 | Scopes, | ||
26 | Table, | ||
27 | UpdatedAt | ||
10 | } from 'sequelize-typescript' | 28 | } from 'sequelize-typescript' |
11 | import { VideoPrivacy, VideoResolution } from '../../../shared' | 29 | import { VideoPrivacy, VideoResolution } from '../../../shared' |
12 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' | 30 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' |
@@ -16,17 +34,30 @@ import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeF | |||
16 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 34 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
17 | import { isBooleanValid } from '../../helpers/custom-validators/misc' | 35 | import { isBooleanValid } from '../../helpers/custom-validators/misc' |
18 | import { | 36 | import { |
19 | isVideoCategoryValid, isVideoDescriptionValid, isVideoDurationValid, isVideoLanguageValid, isVideoLicenceValid, isVideoNameValid, | 37 | isVideoCategoryValid, |
38 | isVideoDescriptionValid, | ||
39 | isVideoDurationValid, | ||
40 | isVideoLanguageValid, | ||
41 | isVideoLicenceValid, | ||
42 | isVideoNameValid, | ||
20 | isVideoPrivacyValid | 43 | isVideoPrivacyValid |
21 | } from '../../helpers/custom-validators/videos' | 44 | } from '../../helpers/custom-validators/videos' |
22 | import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' | 45 | import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' |
23 | import { logger } from '../../helpers/logger' | 46 | import { logger } from '../../helpers/logger' |
24 | import { getServerActor } from '../../helpers/utils' | 47 | import { getServerActor } from '../../helpers/utils' |
25 | import { | 48 | import { |
26 | API_VERSION, CONFIG, CONSTRAINTS_FIELDS, PREVIEWS_SIZE, REMOTE_SCHEME, STATIC_PATHS, THUMBNAILS_SIZE, VIDEO_CATEGORIES, | 49 | API_VERSION, |
27 | VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES | 50 | CONFIG, |
51 | CONSTRAINTS_FIELDS, | ||
52 | PREVIEWS_SIZE, | ||
53 | REMOTE_SCHEME, | ||
54 | STATIC_PATHS, | ||
55 | THUMBNAILS_SIZE, | ||
56 | VIDEO_CATEGORIES, | ||
57 | VIDEO_LANGUAGES, | ||
58 | VIDEO_LICENCES, | ||
59 | VIDEO_PRIVACIES | ||
28 | } from '../../initializers' | 60 | } from '../../initializers' |
29 | import { getAnnounceActivityPubUrl } from '../../lib/activitypub' | ||
30 | import { sendDeleteVideo } from '../../lib/activitypub/send' | 61 | import { sendDeleteVideo } from '../../lib/activitypub/send' |
31 | import { AccountModel } from '../account/account' | 62 | import { AccountModel } from '../account/account' |
32 | import { AccountVideoRateModel } from '../account/account-video-rate' | 63 | import { AccountVideoRateModel } from '../account/account-video-rate' |
@@ -936,8 +967,7 @@ export class VideoModel extends Model<VideoModel> { | |||
936 | const shares: string[] = [] | 967 | const shares: string[] = [] |
937 | 968 | ||
938 | for (const videoShare of this.VideoShares) { | 969 | for (const videoShare of this.VideoShares) { |
939 | const shareUrl = getAnnounceActivityPubUrl(this.url, videoShare.Actor) | 970 | shares.push(videoShare.url) |
940 | shares.push(shareUrl) | ||
941 | } | 971 | } |
942 | 972 | ||
943 | sharesObject = activityPubCollection(shares) | 973 | sharesObject = activityPubCollection(shares) |