aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts78
1 files changed, 49 insertions, 29 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 1f940a50d..97fdbc8ef 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -66,9 +66,10 @@ import {
66 VIDEO_PRIVACIES 66 VIDEO_PRIVACIES
67} from '../../initializers' 67} from '../../initializers'
68import { getAnnounceActivityPubUrl } from '../../lib/activitypub' 68import { getAnnounceActivityPubUrl } from '../../lib/activitypub'
69import { sendDeleteVideo } from '../../lib/index' 69import { sendDeleteVideo } from '../../lib/activitypub/send'
70import { AccountModel } from '../account/account' 70import { AccountModel } from '../account/account'
71import { AccountVideoRateModel } from '../account/account-video-rate' 71import { AccountVideoRateModel } from '../account/account-video-rate'
72import { ActorModel } from '../activitypub/actor'
72import { ServerModel } from '../server/server' 73import { ServerModel } from '../server/server'
73import { getSort, throwIfNotValid } from '../utils' 74import { getSort, throwIfNotValid } from '../utils'
74import { TagModel } from './tag' 75import { TagModel } from './tag'
@@ -79,8 +80,7 @@ import { VideoShareModel } from './video-share'
79import { VideoTagModel } from './video-tag' 80import { VideoTagModel } from './video-tag'
80 81
81enum ScopeNames { 82enum ScopeNames {
82 NOT_IN_BLACKLIST = 'NOT_IN_BLACKLIST', 83 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
83 PUBLIC = 'PUBLIC',
84 WITH_ACCOUNT = 'WITH_ACCOUNT', 84 WITH_ACCOUNT = 'WITH_ACCOUNT',
85 WITH_TAGS = 'WITH_TAGS', 85 WITH_TAGS = 'WITH_TAGS',
86 WITH_FILES = 'WITH_FILES', 86 WITH_FILES = 'WITH_FILES',
@@ -89,17 +89,13 @@ enum ScopeNames {
89} 89}
90 90
91@Scopes({ 91@Scopes({
92 [ScopeNames.NOT_IN_BLACKLIST]: { 92 [ScopeNames.AVAILABLE_FOR_LIST]: {
93 where: { 93 where: {
94 id: { 94 id: {
95 [Sequelize.Op.notIn]: Sequelize.literal( 95 [Sequelize.Op.notIn]: Sequelize.literal(
96 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")' 96 '(SELECT "videoBlacklist"."videoId" FROM "videoBlacklist")'
97 ) 97 )
98 } 98 },
99 }
100 },
101 [ScopeNames.PUBLIC]: {
102 where: {
103 privacy: VideoPrivacy.PUBLIC 99 privacy: VideoPrivacy.PUBLIC
104 } 100 }
105 }, 101 },
@@ -114,8 +110,14 @@ enum ScopeNames {
114 required: true, 110 required: true,
115 include: [ 111 include: [
116 { 112 {
117 model: () => ServerModel, 113 model: () => ActorModel,
118 required: false 114 required: true,
115 include: [
116 {
117 model: () => ServerModel,
118 required: false
119 }
120 ]
119 } 121 }
120 ] 122 ]
121 } 123 }
@@ -138,7 +140,7 @@ enum ScopeNames {
138 include: [ 140 include: [
139 { 141 {
140 model: () => VideoShareModel, 142 model: () => VideoShareModel,
141 include: [ () => AccountModel ] 143 include: [ () => ActorModel ]
142 } 144 }
143 ] 145 ]
144 }, 146 },
@@ -271,7 +273,7 @@ export class VideoModel extends Model<VideoModel> {
271 273
272 @BelongsTo(() => VideoChannelModel, { 274 @BelongsTo(() => VideoChannelModel, {
273 foreignKey: { 275 foreignKey: {
274 allowNull: false 276 allowNull: true
275 }, 277 },
276 onDelete: 'cascade' 278 onDelete: 'cascade'
277 }) 279 })
@@ -351,14 +353,15 @@ export class VideoModel extends Model<VideoModel> {
351 return VideoModel.scope(ScopeNames.WITH_FILES).findAll() 353 return VideoModel.scope(ScopeNames.WITH_FILES).findAll()
352 } 354 }
353 355
354 static listAllAndSharedByAccountForOutbox (accountId: number, start: number, count: number) { 356 static listAllAndSharedByActorForOutbox (actorId: number, start: number, count: number) {
355 function getRawQuery (select: string) { 357 function getRawQuery (select: string) {
356 const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' + 358 const queryVideo = 'SELECT ' + select + ' FROM "video" AS "Video" ' +
357 'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' + 359 'INNER JOIN "videoChannel" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
358 'WHERE "VideoChannel"."accountId" = ' + accountId 360 'INNER JOIN "account" AS "Account" ON "Account"."id" = "VideoChannel"."accountId" ' +
361 'WHERE "Account"."actorId" = ' + actorId
359 const queryVideoShare = 'SELECT ' + select + ' FROM "videoShare" AS "VideoShare" ' + 362 const queryVideoShare = 'SELECT ' + select + ' FROM "videoShare" AS "VideoShare" ' +
360 'INNER JOIN "video" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' + 363 'INNER JOIN "video" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
361 'WHERE "VideoShare"."accountId" = ' + accountId 364 'WHERE "VideoShare"."actorId" = ' + actorId
362 365
363 return `(${queryVideo}) UNION (${queryVideoShare})` 366 return `(${queryVideo}) UNION (${queryVideoShare})`
364 } 367 }
@@ -388,11 +391,16 @@ export class VideoModel extends Model<VideoModel> {
388 } 391 }
389 }, 392 },
390 { 393 {
391 accountId 394 actorId
392 } 395 }
393 ] 396 ]
394 }, 397 },
395 include: [ AccountModel ] 398 include: [
399 {
400 model: ActorModel,
401 required: true
402 }
403 ]
396 }, 404 },
397 { 405 {
398 model: VideoChannelModel, 406 model: VideoChannelModel,
@@ -469,7 +477,7 @@ export class VideoModel extends Model<VideoModel> {
469 order: [ getSort(sort) ] 477 order: [ getSort(sort) ]
470 } 478 }
471 479
472 return VideoModel.scope([ ScopeNames.NOT_IN_BLACKLIST, ScopeNames.PUBLIC, ScopeNames.WITH_ACCOUNT ]) 480 return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT ])
473 .findAndCountAll(query) 481 .findAndCountAll(query)
474 .then(({ rows, count }) => { 482 .then(({ rows, count }) => {
475 return { 483 return {
@@ -541,7 +549,13 @@ export class VideoModel extends Model<VideoModel> {
541 549
542 const accountInclude: IIncludeOptions = { 550 const accountInclude: IIncludeOptions = {
543 model: AccountModel, 551 model: AccountModel,
544 include: [ serverInclude ] 552 include: [
553 {
554 model: ActorModel,
555 required: true,
556 include: [ serverInclude ]
557 }
558 ]
545 } 559 }
546 560
547 const videoChannelInclude: IIncludeOptions = { 561 const videoChannelInclude: IIncludeOptions = {
@@ -586,7 +600,7 @@ export class VideoModel extends Model<VideoModel> {
586 videoChannelInclude, tagInclude 600 videoChannelInclude, tagInclude
587 ] 601 ]
588 602
589 return VideoModel.scope([ ScopeNames.NOT_IN_BLACKLIST, ScopeNames.PUBLIC ]) 603 return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST ])
590 .findAndCountAll(query).then(({ rows, count }) => { 604 .findAndCountAll(query).then(({ rows, count }) => {
591 return { 605 return {
592 data: rows, 606 data: rows,
@@ -688,8 +702,8 @@ export class VideoModel extends Model<VideoModel> {
688 toFormattedJSON () { 702 toFormattedJSON () {
689 let serverHost 703 let serverHost
690 704
691 if (this.VideoChannel.Account.Server) { 705 if (this.VideoChannel.Account.Actor.Server) {
692 serverHost = this.VideoChannel.Account.Server.host 706 serverHost = this.VideoChannel.Account.Actor.Server.host
693 } else { 707 } else {
694 // It means it's our video 708 // It means it's our video
695 serverHost = CONFIG.WEBSERVER.HOST 709 serverHost = CONFIG.WEBSERVER.HOST
@@ -805,9 +819,9 @@ export class VideoModel extends Model<VideoModel> {
805 819
806 for (const rate of this.AccountVideoRates) { 820 for (const rate of this.AccountVideoRates) {
807 if (rate.type === 'like') { 821 if (rate.type === 'like') {
808 likes.push(rate.Account.url) 822 likes.push(rate.Account.Actor.url)
809 } else if (rate.type === 'dislike') { 823 } else if (rate.type === 'dislike') {
810 dislikes.push(rate.Account.url) 824 dislikes.push(rate.Account.Actor.url)
811 } 825 }
812 } 826 }
813 827
@@ -820,7 +834,7 @@ export class VideoModel extends Model<VideoModel> {
820 const shares: string[] = [] 834 const shares: string[] = []
821 835
822 for (const videoShare of this.VideoShares) { 836 for (const videoShare of this.VideoShares) {
823 const shareUrl = getAnnounceActivityPubUrl(this.url, videoShare.Account) 837 const shareUrl = getAnnounceActivityPubUrl(this.url, videoShare.Actor)
824 shares.push(shareUrl) 838 shares.push(shareUrl)
825 } 839 }
826 840
@@ -886,7 +900,13 @@ export class VideoModel extends Model<VideoModel> {
886 url, 900 url,
887 likes: likesObject, 901 likes: likesObject,
888 dislikes: dislikesObject, 902 dislikes: dislikesObject,
889 shares: sharesObject 903 shares: sharesObject,
904 attributedTo: [
905 {
906 type: 'Group',
907 id: this.VideoChannel.Actor.url
908 }
909 ]
890 } 910 }
891 } 911 }
892 912
@@ -1030,8 +1050,8 @@ export class VideoModel extends Model<VideoModel> {
1030 baseUrlHttp = CONFIG.WEBSERVER.URL 1050 baseUrlHttp = CONFIG.WEBSERVER.URL
1031 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT 1051 baseUrlWs = CONFIG.WEBSERVER.WS + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
1032 } else { 1052 } else {
1033 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Server.host 1053 baseUrlHttp = REMOTE_SCHEME.HTTP + '://' + this.VideoChannel.Account.Actor.Server.host
1034 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Server.host 1054 baseUrlWs = REMOTE_SCHEME.WS + '://' + this.VideoChannel.Account.Actor.Server.host
1035 } 1055 }
1036 1056
1037 return { baseUrlHttp, baseUrlWs } 1057 return { baseUrlHttp, baseUrlWs }