aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-channel-interface.ts2
-rw-r--r--server/models/video/video-channel-share-interface.ts2
-rw-r--r--server/models/video/video-channel-share.ts15
-rw-r--r--server/models/video/video-channel.ts17
-rw-r--r--server/models/video/video-share-interface.ts6
-rw-r--r--server/models/video/video-share.ts16
-rw-r--r--server/models/video/video.ts19
7 files changed, 71 insertions, 6 deletions
diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.ts
index b409d1db3..21f81e901 100644
--- a/server/models/video/video-channel-interface.ts
+++ b/server/models/video/video-channel-interface.ts
@@ -6,6 +6,7 @@ import { VideoChannelObject } from '../../../shared/models/activitypub/objects/v
6import { VideoChannel as FormattedVideoChannel } from '../../../shared/models/videos/video-channel.model' 6import { VideoChannel as FormattedVideoChannel } from '../../../shared/models/videos/video-channel.model'
7import { AccountInstance } from '../account/account-interface' 7import { AccountInstance } from '../account/account-interface'
8import { VideoInstance } from './video-interface' 8import { VideoInstance } from './video-interface'
9import { VideoChannelShareInstance } from './video-channel-share-interface'
9 10
10export namespace VideoChannelMethods { 11export namespace VideoChannelMethods {
11 export type ToFormattedJSON = (this: VideoChannelInstance) => FormattedVideoChannel 12 export type ToFormattedJSON = (this: VideoChannelInstance) => FormattedVideoChannel
@@ -47,6 +48,7 @@ export interface VideoChannelAttributes {
47 48
48 Account?: AccountInstance 49 Account?: AccountInstance
49 Videos?: VideoInstance[] 50 Videos?: VideoInstance[]
51 VideoChannelShares?: VideoChannelShareInstance[]
50} 52}
51 53
52export interface VideoChannelInstance extends VideoChannelClass, VideoChannelAttributes, Sequelize.Instance<VideoChannelAttributes> { 54export interface VideoChannelInstance extends VideoChannelClass, VideoChannelAttributes, Sequelize.Instance<VideoChannelAttributes> {
diff --git a/server/models/video/video-channel-share-interface.ts b/server/models/video/video-channel-share-interface.ts
index 8bb531af2..bcb3a0e24 100644
--- a/server/models/video/video-channel-share-interface.ts
+++ b/server/models/video/video-channel-share-interface.ts
@@ -5,10 +5,12 @@ import { VideoChannelInstance } from './video-channel-interface'
5 5
6export namespace VideoChannelShareMethods { 6export namespace VideoChannelShareMethods {
7 export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]> 7 export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]>
8 export type Load = (accountId: number, videoId: number) => Bluebird<VideoChannelShareInstance>
8} 9}
9 10
10export interface VideoChannelShareClass { 11export interface VideoChannelShareClass {
11 loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare 12 loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare
13 load: VideoChannelShareMethods.Load
12} 14}
13 15
14export interface VideoChannelShareAttributes { 16export interface VideoChannelShareAttributes {
diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts
index 01f84c806..e47c0dae7 100644
--- a/server/models/video/video-channel-share.ts
+++ b/server/models/video/video-channel-share.ts
@@ -5,6 +5,7 @@ import { VideoChannelShareAttributes, VideoChannelShareInstance, VideoChannelSha
5 5
6let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> 6let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes>
7let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare 7let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare
8let load: VideoChannelShareMethods.Load
8 9
9export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 10export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
10 VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare', 11 VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare',
@@ -23,6 +24,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
23 24
24 const classMethods = [ 25 const classMethods = [
25 associate, 26 associate,
27 load,
26 loadAccountsByShare 28 loadAccountsByShare
27 ] 29 ]
28 addMethodsToModel(VideoChannelShare, classMethods) 30 addMethodsToModel(VideoChannelShare, classMethods)
@@ -50,6 +52,19 @@ function associate (models) {
50 }) 52 })
51} 53}
52 54
55load = function (accountId: number, videoChannelId: number) {
56 return VideoChannelShare.findOne({
57 where: {
58 accountId,
59 videoChannelId
60 },
61 include: [
62 VideoChannelShare['sequelize'].models.Account,
63 VideoChannelShare['sequelize'].models.VideoChannel
64 ]
65 })
66}
67
53loadAccountsByShare = function (videoChannelId: number) { 68loadAccountsByShare = function (videoChannelId: number) {
54 const query = { 69 const query = {
55 where: { 70 where: {
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 64130310d..e11268b2c 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -6,6 +6,8 @@ import { sendDeleteVideoChannel } from '../../lib/activitypub/send/send-delete'
6 6
7import { addMethodsToModel, getSort } from '../utils' 7import { addMethodsToModel, getSort } from '../utils'
8import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface' 8import { VideoChannelAttributes, VideoChannelInstance, VideoChannelMethods } from './video-channel-interface'
9import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
10import { activityPubCollection } from '../../helpers/activitypub'
9 11
10let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes> 12let VideoChannel: Sequelize.Model<VideoChannelInstance, VideoChannelAttributes>
11let toFormattedJSON: VideoChannelMethods.ToFormattedJSON 13let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
@@ -139,6 +141,18 @@ toFormattedJSON = function (this: VideoChannelInstance) {
139} 141}
140 142
141toActivityPubObject = function (this: VideoChannelInstance) { 143toActivityPubObject = function (this: VideoChannelInstance) {
144 let sharesObject
145 if (Array.isArray(this.VideoChannelShares)) {
146 const shares: string[] = []
147
148 for (const videoChannelShare of this.VideoChannelShares) {
149 const shareUrl = getAnnounceActivityPubUrl(this.url, videoChannelShare.Account)
150 shares.push(shareUrl)
151 }
152
153 sharesObject = activityPubCollection(shares)
154 }
155
142 const json = { 156 const json = {
143 type: 'VideoChannel' as 'VideoChannel', 157 type: 'VideoChannel' as 'VideoChannel',
144 id: this.url, 158 id: this.url,
@@ -146,7 +160,8 @@ toActivityPubObject = function (this: VideoChannelInstance) {
146 content: this.description, 160 content: this.description,
147 name: this.name, 161 name: this.name,
148 published: this.createdAt.toISOString(), 162 published: this.createdAt.toISOString(),
149 updated: this.updatedAt.toISOString() 163 updated: this.updatedAt.toISOString(),
164 shares: sharesObject
150 } 165 }
151 166
152 return json 167 return json
diff --git a/server/models/video/video-share-interface.ts b/server/models/video/video-share-interface.ts
index 569568842..ad23444b6 100644
--- a/server/models/video/video-share-interface.ts
+++ b/server/models/video/video-share-interface.ts
@@ -1,14 +1,16 @@
1import * as Bluebird from 'bluebird'
1import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
2import { AccountInstance } from '../account/account-interface' 3import { AccountInstance } from '../account/account-interface'
3import { VideoInstance } from './video-interface' 4import { VideoInstance } from './video-interface'
4import * as Bluebird from 'bluebird'
5 5
6export namespace VideoShareMethods { 6export namespace VideoShareMethods {
7 export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]> 7 export type LoadAccountsByShare = (videoId: number) => Bluebird<AccountInstance[]>
8 export type Load = (accountId: number, videoId: number) => Bluebird<VideoShareInstance>
8} 9}
9 10
10export interface VideoShareClass { 11export interface VideoShareClass {
11 loadAccountsByShare: VideoShareMethods.LoadAccountsByShare 12 loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
13 load: VideoShareMethods.Load
12} 14}
13 15
14export interface VideoShareAttributes { 16export interface VideoShareAttributes {
diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts
index 22ac31a4a..fe5d56d42 100644
--- a/server/models/video/video-share.ts
+++ b/server/models/video/video-share.ts
@@ -5,6 +5,7 @@ import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './v
5 5
6let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes> 6let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes>
7let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare 7let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
8let load: VideoShareMethods.Load
8 9
9export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 10export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
10 VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare', 11 VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare',
@@ -23,7 +24,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
23 24
24 const classMethods = [ 25 const classMethods = [
25 associate, 26 associate,
26 loadAccountsByShare 27 loadAccountsByShare,
28 load
27 ] 29 ]
28 addMethodsToModel(VideoShare, classMethods) 30 addMethodsToModel(VideoShare, classMethods)
29 31
@@ -50,6 +52,18 @@ function associate (models) {
50 }) 52 })
51} 53}
52 54
55load = function (accountId: number, videoId: number) {
56 return VideoShare.findOne({
57 where: {
58 accountId,
59 videoId
60 },
61 include: [
62 VideoShare['sequelize'].models.Account
63 ]
64 })
65}
66
53loadAccountsByShare = function (videoId: number) { 67loadAccountsByShare = function (videoId: number) {
54 const query = { 68 const query = {
55 where: { 69 where: {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 457bfce77..4956b57ee 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -32,6 +32,7 @@ import { isVideoNameValid, isVideoLicenceValid, isVideoNSFWValid, isVideoDescrip
32import { logger } from '../../helpers/logger' 32import { logger } from '../../helpers/logger'
33import { generateImageFromVideoFile, transcode, getVideoFileHeight } from '../../helpers/ffmpeg-utils' 33import { generateImageFromVideoFile, transcode, getVideoFileHeight } from '../../helpers/ffmpeg-utils'
34import { createTorrentPromise, writeFilePromise, unlinkPromise, renamePromise, statPromise } from '../../helpers/core-utils' 34import { createTorrentPromise, writeFilePromise, unlinkPromise, renamePromise, statPromise } from '../../helpers/core-utils'
35import { getAnnounceActivityPubUrl } from '../../lib/activitypub/url'
35 36
36let Video: Sequelize.Model<VideoInstance, VideoAttributes> 37let Video: Sequelize.Model<VideoInstance, VideoAttributes>
37let getOriginalFile: VideoMethods.GetOriginalFile 38let getOriginalFile: VideoMethods.GetOriginalFile
@@ -573,6 +574,18 @@ toActivityPubObject = function (this: VideoInstance) {
573 dislikesObject = activityPubCollection(dislikes) 574 dislikesObject = activityPubCollection(dislikes)
574 } 575 }
575 576
577 let sharesObject
578 if (Array.isArray(this.VideoShares)) {
579 const shares: string[] = []
580
581 for (const videoShare of this.VideoShares) {
582 const shareUrl = getAnnounceActivityPubUrl(this.url, videoShare.Account)
583 shares.push(shareUrl)
584 }
585
586 sharesObject = activityPubCollection(shares)
587 }
588
576 const url = [] 589 const url = []
577 for (const file of this.VideoFiles) { 590 for (const file of this.VideoFiles) {
578 url.push({ 591 url.push({
@@ -630,7 +643,8 @@ toActivityPubObject = function (this: VideoInstance) {
630 }, 643 },
631 url, 644 url,
632 likes: likesObject, 645 likes: likesObject,
633 dislikes: dislikesObject 646 dislikes: dislikesObject,
647 shares: sharesObject
634 } 648 }
635 649
636 return videoObject 650 return videoObject
@@ -823,7 +837,8 @@ listAllAndSharedByAccountForOutbox = function (accountId: number, start: number,
823 accountId 837 accountId
824 } 838 }
825 ] 839 ]
826 } 840 },
841 include: [ Video['sequelize'].models.Account ]
827 }, 842 },
828 { 843 {
829 model: Video['sequelize'].models.VideoChannel, 844 model: Video['sequelize'].models.VideoChannel,