diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-16 15:55:01 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | d7d5611c8a23de9b483f0437ad3469afef7b8805 (patch) | |
tree | 35f8f77e5f211a65f8be3c967e939f83c7e17d29 /server/models | |
parent | 20494f122186bb1bfd82f4c598c4744acea27b0c (diff) | |
download | PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.tar.gz PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.tar.zst PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.zip |
Federate video update
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/account-follow.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-channel-share-interface.ts | 3 | ||||
-rw-r--r-- | server/models/video/video-channel-share.ts | 23 | ||||
-rw-r--r-- | server/models/video/video-interface.ts | 4 | ||||
-rw-r--r-- | server/models/video/video-share-interface.ts | 3 | ||||
-rw-r--r-- | server/models/video/video-share.ts | 23 | ||||
-rw-r--r-- | server/models/video/video.ts | 21 |
7 files changed, 73 insertions, 8 deletions
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 ( | |||
187 | let query = 'SELECT ' + selection + ' FROM "Accounts" ' + | 187 | let query = 'SELECT ' + selection + ' FROM "Accounts" ' + |
188 | 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + | 188 | 'INNER JOIN "AccountFollows" ON "AccountFollows"."' + firstJoin + '" = "Accounts"."id" ' + |
189 | 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + | 189 | 'INNER JOIN "Accounts" AS "Follows" ON "AccountFollows"."' + secondJoin + '" = "Follows"."id" ' + |
190 | 'WHERE "Accounts"."id" IN ($accountIds) AND "AccountFollows"."state" = \'accepted\' ' | 190 | 'WHERE "Accounts"."id" = ANY ($accountIds) AND "AccountFollows"."state" = \'accepted\' ' |
191 | 191 | ||
192 | if (start !== undefined) query += 'LIMIT ' + start | 192 | if (start !== undefined) query += 'LIMIT ' + start |
193 | if (count !== undefined) query += ', ' + count | 193 | if (count !== undefined) query += ', ' + count |
194 | 194 | ||
195 | const options = { | 195 | const options = { |
196 | bind: { accountIds: accountIds.join(',') }, | 196 | bind: { accountIds }, |
197 | type: Sequelize.QueryTypes.SELECT | 197 | type: Sequelize.QueryTypes.SELECT |
198 | } | 198 | } |
199 | tasks.push(AccountFollow['sequelize'].query(query, options)) | 199 | 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 @@ | |||
1 | import * as Bluebird from 'bluebird' | ||
1 | import * as Sequelize from 'sequelize' | 2 | import * as Sequelize from 'sequelize' |
2 | import { AccountInstance } from '../account/account-interface' | 3 | import { AccountInstance } from '../account/account-interface' |
3 | import { VideoChannelInstance } from './video-channel-interface' | 4 | import { VideoChannelInstance } from './video-channel-interface' |
4 | 5 | ||
5 | export namespace VideoChannelShareMethods { | 6 | export namespace VideoChannelShareMethods { |
7 | export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]> | ||
6 | } | 8 | } |
7 | 9 | ||
8 | export interface VideoChannelShareClass { | 10 | export interface VideoChannelShareClass { |
11 | loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare | ||
9 | } | 12 | } |
10 | 13 | ||
11 | export interface VideoChannelShareAttributes { | 14 | 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { addMethodsToModel } from '../utils' | 3 | import { addMethodsToModel } from '../utils' |
4 | import { VideoChannelShareAttributes, VideoChannelShareInstance } from './video-channel-share-interface' | 4 | import { VideoChannelShareAttributes, VideoChannelShareInstance, VideoChannelShareMethods } from './video-channel-share-interface' |
5 | 5 | ||
6 | let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> | 6 | let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> |
7 | let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare | ||
7 | 8 | ||
8 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 9 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
9 | VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare', | 10 | VideoChannelShare = sequelize.define<VideoChannelShareInstance, VideoChannelShareAttributes>('VideoChannelShare', |
@@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
21 | ) | 22 | ) |
22 | 23 | ||
23 | const classMethods = [ | 24 | const classMethods = [ |
24 | associate | 25 | associate, |
26 | loadAccountsByShare | ||
25 | ] | 27 | ] |
26 | addMethodsToModel(VideoChannelShare, classMethods) | 28 | addMethodsToModel(VideoChannelShare, classMethods) |
27 | 29 | ||
@@ -47,3 +49,20 @@ function associate (models) { | |||
47 | onDelete: 'cascade' | 49 | onDelete: 'cascade' |
48 | }) | 50 | }) |
49 | } | 51 | } |
52 | |||
53 | loadAccountsByShare = function (videoChannelId: number) { | ||
54 | const query = { | ||
55 | where: { | ||
56 | videoChannelId | ||
57 | }, | ||
58 | include: [ | ||
59 | { | ||
60 | model: VideoChannelShare['sequelize'].models.Account, | ||
61 | required: true | ||
62 | } | ||
63 | ] | ||
64 | } | ||
65 | |||
66 | return VideoChannelShare.findAll(query) | ||
67 | .then(res => res.map(r => r.Account)) | ||
68 | } | ||
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 { | |||
56 | 56 | ||
57 | export type Load = (id: number) => Bluebird<VideoInstance> | 57 | export type Load = (id: number) => Bluebird<VideoInstance> |
58 | export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> | 58 | export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> |
59 | export type LoadByUrl = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> | 59 | export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> |
60 | export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> | 60 | export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> |
61 | export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> | 61 | export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> |
62 | export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance> | 62 | export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance> |
@@ -82,7 +82,7 @@ export interface VideoClass { | |||
82 | loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags | 82 | loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags |
83 | loadByHostAndUUID: VideoMethods.LoadByHostAndUUID | 83 | loadByHostAndUUID: VideoMethods.LoadByHostAndUUID |
84 | loadByUUID: VideoMethods.LoadByUUID | 84 | loadByUUID: VideoMethods.LoadByUUID |
85 | loadByUrl: VideoMethods.LoadByUrl | 85 | loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount |
86 | loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL | 86 | loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL |
87 | loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID | 87 | loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID |
88 | loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags | 88 | 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | import { AccountInstance } from '../account/account-interface' | 2 | import { AccountInstance } from '../account/account-interface' |
3 | import { VideoInstance } from './video-interface' | 3 | import { VideoInstance } from './video-interface' |
4 | import * as Bluebird from 'bluebird' | ||
4 | 5 | ||
5 | export namespace VideoShareMethods { | 6 | export namespace VideoShareMethods { |
7 | export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]> | ||
6 | } | 8 | } |
7 | 9 | ||
8 | export interface VideoShareClass { | 10 | export interface VideoShareClass { |
11 | loadAccountsByShare: VideoShareMethods.LoadAccountsByShare | ||
9 | } | 12 | } |
10 | 13 | ||
11 | export interface VideoShareAttributes { | 14 | 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | 1 | import * as Sequelize from 'sequelize' |
2 | 2 | ||
3 | import { addMethodsToModel } from '../utils' | 3 | import { addMethodsToModel } from '../utils' |
4 | import { VideoShareAttributes, VideoShareInstance } from './video-share-interface' | 4 | import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface' |
5 | 5 | ||
6 | let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes> | 6 | let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes> |
7 | let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare | ||
7 | 8 | ||
8 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { | 9 | export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { |
9 | VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare', | 10 | VideoShare = sequelize.define<VideoShareInstance, VideoShareAttributes>('VideoShare', |
@@ -21,7 +22,8 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
21 | ) | 22 | ) |
22 | 23 | ||
23 | const classMethods = [ | 24 | const classMethods = [ |
24 | associate | 25 | associate, |
26 | loadAccountsByShare | ||
25 | ] | 27 | ] |
26 | addMethodsToModel(VideoShare, classMethods) | 28 | addMethodsToModel(VideoShare, classMethods) |
27 | 29 | ||
@@ -47,3 +49,20 @@ function associate (models) { | |||
47 | onDelete: 'cascade' | 49 | onDelete: 'cascade' |
48 | }) | 50 | }) |
49 | } | 51 | } |
52 | |||
53 | loadAccountsByShare = function (videoId: number) { | ||
54 | const query = { | ||
55 | where: { | ||
56 | videoId | ||
57 | }, | ||
58 | include: [ | ||
59 | { | ||
60 | model: VideoShare['sequelize'].models.Account, | ||
61 | required: true | ||
62 | } | ||
63 | ] | ||
64 | } | ||
65 | |||
66 | return VideoShare.findAll(query) | ||
67 | .then(res => res.map(r => r.Account)) | ||
68 | } | ||
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 | |||
84 | let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags | 84 | let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags |
85 | let listOwnedByAccount: VideoMethods.ListOwnedByAccount | 85 | let listOwnedByAccount: VideoMethods.ListOwnedByAccount |
86 | let load: VideoMethods.Load | 86 | let load: VideoMethods.Load |
87 | let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount | ||
87 | let loadByUUID: VideoMethods.LoadByUUID | 88 | let loadByUUID: VideoMethods.LoadByUUID |
88 | let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL | 89 | let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL |
89 | let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID | 90 | let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID |
@@ -271,6 +272,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da | |||
271 | listOwnedAndPopulateAccountAndTags, | 272 | listOwnedAndPopulateAccountAndTags, |
272 | listOwnedByAccount, | 273 | listOwnedByAccount, |
273 | load, | 274 | load, |
275 | loadByUrlAndPopulateAccount, | ||
274 | loadAndPopulateAccount, | 276 | loadAndPopulateAccount, |
275 | loadAndPopulateAccountAndServerAndTags, | 277 | loadAndPopulateAccountAndServerAndTags, |
276 | loadByHostAndUUID, | 278 | loadByHostAndUUID, |
@@ -936,6 +938,25 @@ loadByUUID = function (uuid: string, t?: Sequelize.Transaction) { | |||
936 | return Video.findOne(query) | 938 | return Video.findOne(query) |
937 | } | 939 | } |
938 | 940 | ||
941 | loadByUrlAndPopulateAccount = function (url: string, t?: Sequelize.Transaction) { | ||
942 | const query: Sequelize.FindOptions<VideoAttributes> = { | ||
943 | where: { | ||
944 | url | ||
945 | }, | ||
946 | include: [ | ||
947 | Video['sequelize'].models.VideoFile, | ||
948 | { | ||
949 | model: Video['sequelize'].models.VideoChannel, | ||
950 | include: [ Video['sequelize'].models.Account ] | ||
951 | } | ||
952 | ] | ||
953 | } | ||
954 | |||
955 | if (t !== undefined) query.transaction = t | ||
956 | |||
957 | return Video.findOne(query) | ||
958 | } | ||
959 | |||
939 | loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) { | 960 | loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) { |
940 | const query: Sequelize.FindOptions<VideoAttributes> = { | 961 | const query: Sequelize.FindOptions<VideoAttributes> = { |
941 | where: { | 962 | where: { |