let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
let list: VideoMethods.List
let listForApi: VideoMethods.ListForApi
+let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
let listUserVideosForApi: VideoMethods.ListUserVideosForApi
let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
generateThumbnailFromData,
list,
+ listAllAndSharedByAccountForOutbox,
listForApi,
listUserVideosForApi,
listOwnedAndPopulateAccountAndTags,
},
onDelete: 'cascade'
})
+
+ Video.hasMany(models.VideoShare, {
+ foreignKey: {
+ name: 'videoId',
+ allowNull: false
+ },
+ onDelete: 'cascade'
+ })
}
function afterDestroy (video: VideoInstance) {
return Video.findAll(query)
}
+listAllAndSharedByAccountForOutbox = function (accountId: number, start: number, count: number) {
+ const queryVideo = 'SELECT "Video"."id" FROM "Videos" AS "Video" ' +
+ 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
+ 'WHERE "VideoChannel"."accountId" = ' + accountId
+ const queryVideoShare = 'SELECT "Video"."id" FROM "VideoShares" AS "VideoShare" ' +
+ 'INNER JOIN "Videos" AS "Video" ON "Video"."id" = "VideoShare"."videoId" ' +
+ 'INNER JOIN "VideoChannels" AS "VideoChannel" ON "VideoChannel"."id" = "Video"."channelId" ' +
+ 'WHERE "VideoShare"."accountId" = ' + accountId
+ const rawQuery = `(${queryVideo}) UNION (${queryVideoShare}) LIMIT ${count} OFFSET ${start}`
+
+ const query = {
+ distinct: true,
+ offset: start,
+ limit: count,
+ order: [ getSort('createdAt'), [ Video['sequelize'].models.Tag, 'name', 'ASC' ] ],
+ where: {
+ id: {
+ [Sequelize.Op.in]: Sequelize.literal('(' + rawQuery + ')')
+ }
+ },
+ include: [
+ {
+ model: Video['sequelize'].models.VideoShare,
+ required: false
+ },
+ {
+ model: Video['sequelize'].models.VideoChannel,
+ required: true,
+ include: [
+ {
+ model: Video['sequelize'].models.Account,
+ required: true
+ }
+ ]
+ },
+ Video['sequelize'].models.Tag,
+ Video['sequelize'].models.VideoFile
+ ]
+ }
+
+ return Video.findAndCountAll(query).then(({ rows, count }) => {
+ return {
+ data: rows,
+ total: count
+ }
+ })
+}
+
listUserVideosForApi = function (userId: number, start: number, count: number, sort: string) {
const query = {
distinct: true,