aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-21 18:23:10 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commite71bcc0f4b31ecfd84a786411febfc6d18a85258 (patch)
treeea31776b6bc69bd3b72e6c6f615cf94072271c82 /server/models
parentb1cbc0dd3ee0fce6d8390b6d3996386a5b6097ac (diff)
downloadPeerTube-e71bcc0f4b31ecfd84a786411febfc6d18a85258.tar.gz
PeerTube-e71bcc0f4b31ecfd84a786411febfc6d18a85258.tar.zst
PeerTube-e71bcc0f4b31ecfd84a786411febfc6d18a85258.zip
Add outbox
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-follow.ts4
-rw-r--r--server/models/video/video-interface.ts8
-rw-r--r--server/models/video/video.ts58
3 files changed, 68 insertions, 2 deletions
diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts
index 34ba3f8db..578bcda39 100644
--- a/server/models/account/account-follow.ts
+++ b/server/models/account/account-follow.ts
@@ -221,8 +221,8 @@ async function createListAcceptedFollowForApiQuery (
221 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + 221 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' +
222 'WHERE "Accounts"."id" = ANY ($accountIds) AND "AccountFollows"."state" = \'accepted\' ' 222 'WHERE "Accounts"."id" = ANY ($accountIds) AND "AccountFollows"."state" = \'accepted\' '
223 223
224 if (start !== undefined) query += 'LIMIT ' + start 224 if (count !== undefined) query += 'LIMIT ' + count
225 if (count !== undefined) query += ', ' + count 225 if (start !== undefined) query += ' OFFSET ' + start
226 226
227 const options = { 227 const options = {
228 bind: { accountIds }, 228 bind: { accountIds },
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts
index 9f29c842c..391ecff43 100644
--- a/server/models/video/video-interface.ts
+++ b/server/models/video/video-interface.ts
@@ -7,6 +7,7 @@ import { Video as FormattedVideo, VideoDetails as FormattedDetailsVideo } from '
7import { TagAttributes, TagInstance } from './tag-interface' 7import { TagAttributes, TagInstance } from './tag-interface'
8import { VideoChannelInstance } from './video-channel-interface' 8import { VideoChannelInstance } from './video-channel-interface'
9import { VideoFileAttributes, VideoFileInstance } from './video-file-interface' 9import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
10import { VideoShareInstance } from './video-share-interface'
10 11
11export namespace VideoMethods { 12export namespace VideoMethods {
12 export type GetThumbnailName = (this: VideoInstance) => string 13 export type GetThumbnailName = (this: VideoInstance) => string
@@ -44,6 +45,11 @@ export namespace VideoMethods {
44 export type ListOwnedAndPopulateAccountAndTags = () => Bluebird<VideoInstance[]> 45 export type ListOwnedAndPopulateAccountAndTags = () => Bluebird<VideoInstance[]>
45 export type ListOwnedByAccount = (account: string) => Bluebird<VideoInstance[]> 46 export type ListOwnedByAccount = (account: string) => Bluebird<VideoInstance[]>
46 47
48 export type ListAllAndSharedByAccountForOutbox = (
49 accountId: number,
50 start: number,
51 count: number
52 ) => Bluebird< ResultList<VideoInstance> >
47 export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> > 53 export type ListForApi = (start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
48 export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> > 54 export type ListUserVideosForApi = (userId: number, start: number, count: number, sort: string) => Bluebird< ResultList<VideoInstance> >
49 export type SearchAndPopulateAccountAndServerAndTags = ( 55 export type SearchAndPopulateAccountAndServerAndTags = (
@@ -73,6 +79,7 @@ export namespace VideoMethods {
73export interface VideoClass { 79export interface VideoClass {
74 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData 80 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
75 list: VideoMethods.List 81 list: VideoMethods.List
82 listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
76 listForApi: VideoMethods.ListForApi 83 listForApi: VideoMethods.ListForApi
77 listUserVideosForApi: VideoMethods.ListUserVideosForApi 84 listUserVideosForApi: VideoMethods.ListUserVideosForApi
78 listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags 85 listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
@@ -115,6 +122,7 @@ export interface VideoAttributes {
115 VideoChannel?: VideoChannelInstance 122 VideoChannel?: VideoChannelInstance
116 Tags?: TagInstance[] 123 Tags?: TagInstance[]
117 VideoFiles?: VideoFileInstance[] 124 VideoFiles?: VideoFileInstance[]
125 VideoShare?: VideoShareInstance
118} 126}
119 127
120export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> { 128export interface VideoInstance extends VideoClass, VideoAttributes, Sequelize.Instance<VideoAttributes> {
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index e2069eb0c..3b7e83779 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -78,6 +78,7 @@ let getLanguageLabel: VideoMethods.GetLanguageLabel
78let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData 78let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
79let list: VideoMethods.List 79let list: VideoMethods.List
80let listForApi: VideoMethods.ListForApi 80let listForApi: VideoMethods.ListForApi
81let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
81let listUserVideosForApi: VideoMethods.ListUserVideosForApi 82let listUserVideosForApi: VideoMethods.ListUserVideosForApi
82let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID 83let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
83let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags 84let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
@@ -266,6 +267,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
266 267
267 generateThumbnailFromData, 268 generateThumbnailFromData,
268 list, 269 list,
270 listAllAndSharedByAccountForOutbox,
269 listForApi, 271 listForApi,
270 listUserVideosForApi, 272 listUserVideosForApi,
271 listOwnedAndPopulateAccountAndTags, 273 listOwnedAndPopulateAccountAndTags,
@@ -348,6 +350,14 @@ function associate (models) {
348 }, 350 },
349 onDelete: 'cascade' 351 onDelete: 'cascade'
350 }) 352 })
353
354 Video.hasMany(models.VideoShare, {
355 foreignKey: {
356 name: 'videoId',
357 allowNull: false
358 },
359 onDelete: 'cascade'
360 })
351} 361}
352 362
353function afterDestroy (video: VideoInstance) { 363function afterDestroy (video: VideoInstance) {
@@ -775,6 +785,54 @@ list = function () {
775 return Video.findAll(query) 785 return Video.findAll(query)
776} 786}
777 787
788listAllAndSharedByAccountForOutbox = function (accountId: number, start: number, count: number) {
789 const queryVideo = 'SELECT "Video"."id" FROM "Videos" AS "Video" ' +
790 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
791 'WHERE "VideoChannel"."accountId" = ' + accountId
792 const queryVideoShare = 'SELECT "Video"."id" FROM "VideoShares" AS "VideoShare" ' +
793 'INNER JOIN "Videos" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
794 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
795 'WHERE "VideoShare"."accountId" = ' + accountId
796 const rawQuery = `(${queryVideo}) UNION (${queryVideoShare}) LIMIT ${count} OFFSET ${start}`
797
798 const query = {
799 distinct: true,
800 offset: start,
801 limit: count,
802 order: [ getSort('createdAt'), [ Video['sequelize'].models.Tag, 'name', 'ASC' ] ],
803 where: {
804 id: {
805 [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')')
806 }
807 },
808 include: [
809 {
810 model: Video['sequelize'].models.VideoShare,
811 required: false
812 },
813 {
814 model: Video['sequelize'].models.VideoChannel,
815 required: true,
816 include: [
817 {
818 model: Video['sequelize'].models.Account,
819 required: true
820 }
821 ]
822 },
823 Video['sequelize'].models.Tag,
824 Video['sequelize'].models.VideoFile
825 ]
826 }
827
828 return Video.findAndCountAll(query).then(({ rows, count }) => {
829 return {
830 data: rows,
831 total: count
832 }
833 })
834}
835
778listUserVideosForApi = function (userId: number, start: number, count: number, sort: string) { 836listUserVideosForApi = function (userId: number, start: number, count: number, sort: string) {
779 const query = { 837 const query = {
780 distinct: true, 838 distinct: true,