aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/lib/activitypub/misc.ts6
-rw-r--r--server/lib/activitypub/process-add.ts13
-rw-r--r--server/lib/activitypub/process-create.ts2
-rw-r--r--server/lib/activitypub/process-delete.ts2
-rw-r--r--server/lib/activitypub/process-update.ts4
-rw-r--r--server/lib/activitypub/send-request.ts20
-rw-r--r--server/models/account/account-follow.ts4
-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
13 files changed, 102 insertions, 26 deletions
diff --git a/server/lib/activitypub/misc.ts b/server/lib/activitypub/misc.ts
index 13838fc4c..f853d742e 100644
--- a/server/lib/activitypub/misc.ts
+++ b/server/lib/activitypub/misc.ts
@@ -25,12 +25,8 @@ function videoChannelActivityObjectToDBAttributes (videoChannelObject: VideoChan
25 25
26async function videoActivityObjectToDBAttributes ( 26async function videoActivityObjectToDBAttributes (
27 videoChannel: VideoChannelInstance, 27 videoChannel: VideoChannelInstance,
28 videoObject: VideoTorrentObject, 28 videoObject: VideoTorrentObject
29 t: Sequelize.Transaction
30) { 29) {
31 const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoObject.uuid, videoObject.id, t)
32 if (videoFromDatabase) throw new Error('Video with this UUID/Url already exists.')
33
34 const duration = videoObject.duration.replace(/[^\d]+/, '') 30 const duration = videoObject.duration.replace(/[^\d]+/, '')
35 const videoData: VideoAttributes = { 31 const videoData: VideoAttributes = {
36 name: videoObject.name, 32 name: videoObject.name,
diff --git a/server/lib/activitypub/process-add.ts b/server/lib/activitypub/process-add.ts
index df7139d46..72c5b1932 100644
--- a/server/lib/activitypub/process-add.ts
+++ b/server/lib/activitypub/process-add.ts
@@ -1,12 +1,12 @@
1import * as Bluebird from 'bluebird'
1import { VideoTorrentObject } from '../../../shared' 2import { VideoTorrentObject } from '../../../shared'
2import { ActivityAdd } from '../../../shared/models/activitypub/activity' 3import { ActivityAdd } from '../../../shared/models/activitypub/activity'
3import { generateThumbnailFromUrl, logger, retryTransactionWrapper, getOrCreateAccount } from '../../helpers' 4import { generateThumbnailFromUrl, getOrCreateAccount, logger, retryTransactionWrapper } from '../../helpers'
5import { getOrCreateVideoChannel } from '../../helpers/activitypub'
4import { database as db } from '../../initializers' 6import { database as db } from '../../initializers'
5import { AccountInstance } from '../../models/account/account-interface' 7import { AccountInstance } from '../../models/account/account-interface'
6import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
7import Bluebird = require('bluebird')
8import { getOrCreateVideoChannel } from '../../helpers/activitypub'
9import { VideoChannelInstance } from '../../models/video/video-channel-interface' 8import { VideoChannelInstance } from '../../models/video/video-channel-interface'
9import { videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc'
10 10
11async function processAddActivity (activity: ActivityAdd) { 11async function processAddActivity (activity: ActivityAdd) {
12 const activityObject = activity.object 12 const activityObject = activity.object
@@ -51,7 +51,10 @@ function addRemoteVideo (account: AccountInstance, videoChannel: VideoChannelIns
51 51
52 if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.') 52 if (videoChannel.Account.id !== account.id) throw new Error('Video channel is not owned by this account.')
53 53
54 const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData, t) 54 const videoFromDatabase = await db.Video.loadByUUIDOrURL(videoToCreateData.uuid, videoToCreateData.id, t)
55 if (videoFromDatabase) throw new Error('Video with this UUID/Url already exists.')
56
57 const videoData = await videoActivityObjectToDBAttributes(videoChannel, videoToCreateData)
55 const video = db.Video.build(videoData) 58 const video = db.Video.build(videoData)
56 59
57 // Don't block on request 60 // Don't block on request
diff --git a/server/lib/activitypub/process-create.ts b/server/lib/activitypub/process-create.ts
index c4706a66b..faea3f48a 100644
--- a/server/lib/activitypub/process-create.ts
+++ b/server/lib/activitypub/process-create.ts
@@ -69,7 +69,7 @@ function addRemoteVideoAbuse (account: AccountInstance, videoAbuseToCreateData:
69 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object) 69 logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
70 70
71 return db.sequelize.transaction(async t => { 71 return db.sequelize.transaction(async t => {
72 const video = await db.Video.loadByUrl(videoAbuseToCreateData.object, t) 72 const video = await db.Video.loadByUrlAndPopulateAccount(videoAbuseToCreateData.object, t)
73 if (!video) { 73 if (!video) {
74 logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object) 74 logger.warn('Unknown video %s for remote video abuse.', videoAbuseToCreateData.object)
75 return 75 return
diff --git a/server/lib/activitypub/process-delete.ts b/server/lib/activitypub/process-delete.ts
index 377df432d..d4487d2cc 100644
--- a/server/lib/activitypub/process-delete.ts
+++ b/server/lib/activitypub/process-delete.ts
@@ -15,7 +15,7 @@ async function processDeleteActivity (activity: ActivityDelete) {
15 } 15 }
16 16
17 { 17 {
18 let videoObject = await db.Video.loadByUrl(activity.id) 18 let videoObject = await db.Video.loadByUrlAndPopulateAccount(activity.id)
19 if (videoObject !== undefined) { 19 if (videoObject !== undefined) {
20 return processDeleteVideo(account, videoObject) 20 return processDeleteVideo(account, videoObject)
21 } 21 }
diff --git a/server/lib/activitypub/process-update.ts b/server/lib/activitypub/process-update.ts
index cd8a4b8e2..4aefd1b9b 100644
--- a/server/lib/activitypub/process-update.ts
+++ b/server/lib/activitypub/process-update.ts
@@ -50,14 +50,14 @@ async function updateRemoteVideo (account: AccountInstance, videoAttributesToUpd
50 transaction: t 50 transaction: t
51 } 51 }
52 52
53 const videoInstance = await db.Video.loadByUrl(videoAttributesToUpdate.id, t) 53 const videoInstance = await db.Video.loadByUrlAndPopulateAccount(videoAttributesToUpdate.id, t)
54 if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.') 54 if (!videoInstance) throw new Error('Video ' + videoAttributesToUpdate.id + ' not found.')
55 55
56 if (videoInstance.VideoChannel.Account.id !== account.id) { 56 if (videoInstance.VideoChannel.Account.id !== account.id) {
57 throw new Error('Account ' + account.url + ' does not own video channel ' + videoInstance.VideoChannel.url) 57 throw new Error('Account ' + account.url + ' does not own video channel ' + videoInstance.VideoChannel.url)
58 } 58 }
59 59
60 const videoData = await videoActivityObjectToDBAttributes(videoInstance.VideoChannel, videoAttributesToUpdate, t) 60 const videoData = await videoActivityObjectToDBAttributes(videoInstance.VideoChannel, videoAttributesToUpdate)
61 videoInstance.set('name', videoData.name) 61 videoInstance.set('name', videoData.name)
62 videoInstance.set('category', videoData.category) 62 videoInstance.set('category', videoData.category)
63 videoInstance.set('licence', videoData.licence) 63 videoInstance.set('licence', videoData.licence)
diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts
index f9b72f2a8..d5d07011a 100644
--- a/server/lib/activitypub/send-request.ts
+++ b/server/lib/activitypub/send-request.ts
@@ -24,13 +24,19 @@ async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Se
24 const videoChannelObject = videoChannel.toActivityPubObject() 24 const videoChannelObject = videoChannel.toActivityPubObject()
25 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject) 25 const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
26 26
27 return broadcastToFollowers(data, [ videoChannel.Account ], t) 27 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
28 accountsInvolved.push(videoChannel.Account)
29
30 return broadcastToFollowers(data, accountsInvolved, t)
28} 31}
29 32
30async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { 33async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
31 const data = await deleteActivityData(videoChannel.url, videoChannel.Account) 34 const data = await deleteActivityData(videoChannel.url, videoChannel.Account)
32 35
33 return broadcastToFollowers(data, [ videoChannel.Account ], t) 36 const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
37 accountsInvolved.push(videoChannel.Account)
38
39 return broadcastToFollowers(data, accountsInvolved, t)
34} 40}
35 41
36async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) { 42async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
@@ -44,13 +50,19 @@ async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction)
44 const videoObject = video.toActivityPubObject() 50 const videoObject = video.toActivityPubObject()
45 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject) 51 const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject)
46 52
47 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) 53 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
54 accountsInvolved.push(video.VideoChannel.Account)
55
56 return broadcastToFollowers(data, accountsInvolved, t)
48} 57}
49 58
50async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) { 59async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
51 const data = await deleteActivityData(video.url, video.VideoChannel.Account) 60 const data = await deleteActivityData(video.url, video.VideoChannel.Account)
52 61
53 return broadcastToFollowers(data, [ video.VideoChannel.Account ], t) 62 const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
63 accountsInvolved.push(video.VideoChannel.Account)
64
65 return broadcastToFollowers(data, accountsInvolved, t)
54} 66}
55 67
56async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) { 68async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) {
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 @@
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: {