From d7d5611c8a23de9b483f0437ad3469afef7b8805 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 16 Nov 2017 15:55:01 +0100 Subject: Federate video update --- server/models/account/account-follow.ts | 4 ++-- .../models/video/video-channel-share-interface.ts | 3 +++ server/models/video/video-channel-share.ts | 23 ++++++++++++++++++++-- server/models/video/video-interface.ts | 4 ++-- server/models/video/video-share-interface.ts | 3 +++ server/models/video/video-share.ts | 23 ++++++++++++++++++++-- server/models/video/video.ts | 21 ++++++++++++++++++++ 7 files changed, 73 insertions(+), 8 deletions(-) (limited to 'server/models') diff --git a/server/models/account/account-follow.ts b/server/models/account/account-follow.ts index 8a7474c9d..cc9b7c42b 100644 --- a/server/models/account/account-follow.ts +++ b/server/models/account/account-follow.ts @@ -187,13 +187,13 @@ async function createListAcceptedFollowForApiQuery ( let query = 'SELECT ' + selection + ' FROM "Accounts" ' + 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + - 'WHERE "Accounts"."id" IN ($accountIds) AND "AccountFollows"."state" = \'accepted\' ' + 'WHERE "Accounts"."id" = ANY ($accountIds) AND "AccountFollows"."state" = \'accepted\' ' if (start !== undefined) query += 'LIMIT ' + start if (count !== undefined) query += ', ' + count const options = { - bind: { accountIds: accountIds.join(',') }, + bind: { accountIds }, type: Sequelize.QueryTypes.SELECT } tasks.push(AccountFollow['sequelize'].query(query, options)) diff --git a/server/models/video/video-channel-share-interface.ts b/server/models/video/video-channel-share-interface.ts index 9ac6d7b23..8bb531af2 100644 --- a/server/models/video/video-channel-share-interface.ts +++ b/server/models/video/video-channel-share-interface.ts @@ -1,11 +1,14 @@ +import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' import { AccountInstance } from '../account/account-interface' import { VideoChannelInstance } from './video-channel-interface' export namespace VideoChannelShareMethods { + export type LoadAccountsByShare = (videoChannelId: number) => Bluebird } export interface VideoChannelShareClass { + loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare } export interface VideoChannelShareAttributes { diff --git a/server/models/video/video-channel-share.ts b/server/models/video/video-channel-share.ts index b6199279f..01f84c806 100644 --- a/server/models/video/video-channel-share.ts +++ b/server/models/video/video-channel-share.ts @@ -1,9 +1,10 @@ import * as Sequelize from 'sequelize' import { addMethodsToModel } from '../utils' -import { VideoChannelShareAttributes, VideoChannelShareInstance } from './video-channel-share-interface' +import { VideoChannelShareAttributes, VideoChannelShareInstance, VideoChannelShareMethods } from './video-channel-share-interface' let VideoChannelShare: Sequelize.Model +let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { VideoChannelShare = sequelize.define('VideoChannelShare', @@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da ) const classMethods = [ - associate + associate, + loadAccountsByShare ] addMethodsToModel(VideoChannelShare, classMethods) @@ -47,3 +49,20 @@ function associate (models) { onDelete: 'cascade' }) } + +loadAccountsByShare = function (videoChannelId: number) { + const query = { + where: { + videoChannelId + }, + include: [ + { + model: VideoChannelShare['sequelize'].models.Account, + required: true + } + ] + } + + return VideoChannelShare.findAll(query) + .then(res => res.map(r => r.Account)) +} diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts index 4df33f801..9f29c842c 100644 --- a/server/models/video/video-interface.ts +++ b/server/models/video/video-interface.ts @@ -56,7 +56,7 @@ export namespace VideoMethods { export type Load = (id: number) => Bluebird export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird - export type LoadByUrl = (url: string, t?: Sequelize.Transaction) => Bluebird + export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird export type LoadAndPopulateAccount = (id: number) => Bluebird @@ -82,7 +82,7 @@ export interface VideoClass { loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags loadByHostAndUUID: VideoMethods.LoadByHostAndUUID loadByUUID: VideoMethods.LoadByUUID - loadByUrl: VideoMethods.LoadByUrl + loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags diff --git a/server/models/video/video-share-interface.ts b/server/models/video/video-share-interface.ts index 7928b9a9c..569568842 100644 --- a/server/models/video/video-share-interface.ts +++ b/server/models/video/video-share-interface.ts @@ -1,11 +1,14 @@ import * as Sequelize from 'sequelize' import { AccountInstance } from '../account/account-interface' import { VideoInstance } from './video-interface' +import * as Bluebird from 'bluebird' export namespace VideoShareMethods { + export type LoadAccountsByShare = (videoChannelId: number) => Bluebird } export interface VideoShareClass { + loadAccountsByShare: VideoShareMethods.LoadAccountsByShare } export interface VideoShareAttributes { diff --git a/server/models/video/video-share.ts b/server/models/video/video-share.ts index 358491fd2..22ac31a4a 100644 --- a/server/models/video/video-share.ts +++ b/server/models/video/video-share.ts @@ -1,9 +1,10 @@ import * as Sequelize from 'sequelize' import { addMethodsToModel } from '../utils' -import { VideoShareAttributes, VideoShareInstance } from './video-share-interface' +import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface' let VideoShare: Sequelize.Model +let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { VideoShare = sequelize.define('VideoShare', @@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da ) const classMethods = [ - associate + associate, + loadAccountsByShare ] addMethodsToModel(VideoShare, classMethods) @@ -47,3 +49,20 @@ function associate (models) { onDelete: 'cascade' }) } + +loadAccountsByShare = function (videoId: number) { + const query = { + where: { + videoId + }, + include: [ + { + model: VideoShare['sequelize'].models.Account, + required: true + } + ] + } + + return VideoShare.findAll(query) + .then(res => res.map(r => r.Account)) +} diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 64ee7ae34..5b0377c2e 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -84,6 +84,7 @@ let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags let listOwnedByAccount: VideoMethods.ListOwnedByAccount let load: VideoMethods.Load +let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount let loadByUUID: VideoMethods.LoadByUUID let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID @@ -271,6 +272,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da listOwnedAndPopulateAccountAndTags, listOwnedByAccount, load, + loadByUrlAndPopulateAccount, loadAndPopulateAccount, loadAndPopulateAccountAndServerAndTags, loadByHostAndUUID, @@ -936,6 +938,25 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) { return Video.findOne(query) } +loadByUrlAndPopulateAccount = function (url: string, t?: Sequelize.Transaction) { + const query: Sequelize.FindOptions = { + where: { + url + }, + include: [ + Video['sequelize'].models.VideoFile, + { + model: Video['sequelize'].models.VideoChannel, + include: [ Video['sequelize'].models.Account ] + } + ] + } + + if (t !== undefined) query.transaction = t + + return Video.findOne(query) +} + loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) { const query: Sequelize.FindOptions = { where: { -- cgit v1.2.3