diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 58 |
1 files changed, 58 insertions, 0 deletions
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 | |||
78 | let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData | 78 | let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData |
79 | let list: VideoMethods.List | 79 | let list: VideoMethods.List |
80 | let listForApi: VideoMethods.ListForApi | 80 | let listForApi: VideoMethods.ListForApi |
81 | let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox | ||
81 | let listUserVideosForApi: VideoMethods.ListUserVideosForApi | 82 | let listUserVideosForApi: VideoMethods.ListUserVideosForApi |
82 | let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID | 83 | let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID |
83 | let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags | 84 | let 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 | ||
353 | function afterDestroy (video: VideoInstance) { | 363 | function afterDestroy (video: VideoInstance) { |
@@ -775,6 +785,54 @@ list = function () { | |||
775 | return Video.findAll(query) | 785 | return Video.findAll(query) |
776 | } | 786 | } |
777 | 787 | ||
788 | listAllAndSharedByAccountForOutbox = 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 | |||
778 | listUserVideosForApi = function (userId: number, start: number, count: number, sort: string) { | 836 | listUserVideosForApi = function (userId: number, start: number, count: number, sort: string) { |
779 | const query = { | 837 | const query = { |
780 | distinct: true, | 838 | distinct: true, |