aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-16 15:55:01 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commitd7d5611c8a23de9b483f0437ad3469afef7b8805 (patch)
tree35f8f77e5f211a65f8be3c967e939f83c7e17d29 /server/models/video
parent20494f122186bb1bfd82f4c598c4744acea27b0c (diff)
downloadPeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.tar.gz
PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.tar.zst
PeerTube-d7d5611c8a23de9b483f0437ad3469afef7b8805.zip
Federate video update
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-channel-share-interface.ts3
-rw-r--r--server/models/video/video-channel-share.ts23
-rw-r--r--server/models/video/video-interface.ts4
-rw-r--r--server/models/video/video-share-interface.ts3
-rw-r--r--server/models/video/video-share.ts23
-rw-r--r--server/models/video/video.ts21
6 files changed, 71 insertions, 6 deletions
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 @@
1import * as Bluebird from 'bluebird'
1import * as Sequelize from 'sequelize' 2import * as Sequelize from 'sequelize'
2import { AccountInstance } from '../account/account-interface' 3import { AccountInstance } from '../account/account-interface'
3import { VideoChannelInstance } from './video-channel-interface' 4import { VideoChannelInstance } from './video-channel-interface'
4 5
5export namespace VideoChannelShareMethods { 6export namespace VideoChannelShareMethods {
7 export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]>
6} 8}
7 9
8export interface VideoChannelShareClass { 10export interface VideoChannelShareClass {
11 loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare
9} 12}
10 13
11export interface VideoChannelShareAttributes { 14export 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 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { addMethodsToModel } from '../utils' 3import { addMethodsToModel } from '../utils'
4import { VideoChannelShareAttributes, VideoChannelShareInstance } from './video-channel-share-interface' 4import { VideoChannelShareAttributes, VideoChannelShareInstance, VideoChannelShareMethods } from './video-channel-share-interface'
5 5
6let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes> 6let VideoChannelShare: Sequelize.Model<VideoChannelShareInstance, VideoChannelShareAttributes>
7let loadAccountsByShare: VideoChannelShareMethods.LoadAccountsByShare
7 8
8export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 9export 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
53loadAccountsByShare = 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 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { AccountInstance } from '../account/account-interface' 2import { AccountInstance } from '../account/account-interface'
3import { VideoInstance } from './video-interface' 3import { VideoInstance } from './video-interface'
4import * as Bluebird from 'bluebird'
4 5
5export namespace VideoShareMethods { 6export namespace VideoShareMethods {
7 export type LoadAccountsByShare = (videoChannelId: number) => Bluebird<AccountInstance[]>
6} 8}
7 9
8export interface VideoShareClass { 10export interface VideoShareClass {
11 loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
9} 12}
10 13
11export interface VideoShareAttributes { 14export 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 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { addMethodsToModel } from '../utils' 3import { addMethodsToModel } from '../utils'
4import { VideoShareAttributes, VideoShareInstance } from './video-share-interface' 4import { VideoShareAttributes, VideoShareInstance, VideoShareMethods } from './video-share-interface'
5 5
6let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes> 6let VideoShare: Sequelize.Model<VideoShareInstance, VideoShareAttributes>
7let loadAccountsByShare: VideoShareMethods.LoadAccountsByShare
7 8
8export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 9export 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
53loadAccountsByShare = 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
84let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags 84let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
85let listOwnedByAccount: VideoMethods.ListOwnedByAccount 85let listOwnedByAccount: VideoMethods.ListOwnedByAccount
86let load: VideoMethods.Load 86let load: VideoMethods.Load
87let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
87let loadByUUID: VideoMethods.LoadByUUID 88let loadByUUID: VideoMethods.LoadByUUID
88let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL 89let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
89let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID 90let 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
941loadByUrlAndPopulateAccount = 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
939loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) { 960loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction) {
940 const query: Sequelize.FindOptions<VideoAttributes> = { 961 const query: Sequelize.FindOptions<VideoAttributes> = {
941 where: { 962 where: {