aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/video/video-share.ts15
-rw-r--r--server/models/video/video.ts46
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 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' 2import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
3import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
4import { CONSTRAINTS_FIELDS } from '../../initializers'
3import { AccountModel } from '../account/account' 5import { AccountModel } from '../account/account'
4import { ActorModel } from '../activitypub/actor' 6import { ActorModel } from '../activitypub/actor'
7import { throwIfNotValid } from '../utils'
5import { VideoModel } from './video' 8import { VideoModel } from './video'
6import { VideoChannelModel } from './video-channel' 9import { 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})
46export class VideoShareModel extends Model<VideoShareModel> { 53export 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'
5import { join } from 'path' 5import { join } from 'path'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7import { 7import {
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'
11import { VideoPrivacy, VideoResolution } from '../../../shared' 29import { VideoPrivacy, VideoResolution } from '../../../shared'
12import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' 30import { VideoTorrentObject } from '../../../shared/models/activitypub/objects'
@@ -16,17 +34,30 @@ import { createTorrentPromise, renamePromise, statPromise, unlinkPromise, writeF
16import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 34import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
17import { isBooleanValid } from '../../helpers/custom-validators/misc' 35import { isBooleanValid } from '../../helpers/custom-validators/misc'
18import { 36import {
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'
22import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils' 45import { generateImageFromVideoFile, getVideoFileHeight, transcode } from '../../helpers/ffmpeg-utils'
23import { logger } from '../../helpers/logger' 46import { logger } from '../../helpers/logger'
24import { getServerActor } from '../../helpers/utils' 47import { getServerActor } from '../../helpers/utils'
25import { 48import {
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'
29import { getAnnounceActivityPubUrl } from '../../lib/activitypub'
30import { sendDeleteVideo } from '../../lib/activitypub/send' 61import { sendDeleteVideo } from '../../lib/activitypub/send'
31import { AccountModel } from '../account/account' 62import { AccountModel } from '../account/account'
32import { AccountVideoRateModel } from '../account/account-video-rate' 63import { 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)