aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/friends.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-24 19:41:09 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 09:11:38 +0200
commit72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (patch)
tree1bfdee99dbe2392cc997edba8e314e2a8a401c72 /server/lib/friends.ts
parent8113a93a0d9f31aa9e23702bbc31b8a76275ae22 (diff)
downloadPeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.gz
PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.zst
PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.zip
Add video channels
Diffstat (limited to 'server/lib/friends.ts')
-rw-r--r--server/lib/friends.ts138
1 files changed, 125 insertions, 13 deletions
diff --git a/server/lib/friends.ts b/server/lib/friends.ts
index 65349ef5f..f035b099b 100644
--- a/server/lib/friends.ts
+++ b/server/lib/friends.ts
@@ -42,7 +42,13 @@ import {
42 RemoteVideoRemoveData, 42 RemoteVideoRemoveData,
43 RemoteVideoReportAbuseData, 43 RemoteVideoReportAbuseData,
44 ResultList, 44 ResultList,
45 Pod as FormattedPod 45 RemoteVideoRequestType,
46 Pod as FormattedPod,
47 RemoteVideoChannelCreateData,
48 RemoteVideoChannelUpdateData,
49 RemoteVideoChannelRemoveData,
50 RemoteVideoAuthorCreateData,
51 RemoteVideoAuthorRemoveData
46} from '../../shared' 52} from '../../shared'
47 53
48type QaduParam = { videoId: number, type: RequestVideoQaduType } 54type QaduParam = { videoId: number, type: RequestVideoQaduType }
@@ -62,7 +68,7 @@ function activateSchedulers () {
62 68
63function addVideoToFriends (videoData: RemoteVideoCreateData, transaction: Sequelize.Transaction) { 69function addVideoToFriends (videoData: RemoteVideoCreateData, transaction: Sequelize.Transaction) {
64 const options = { 70 const options = {
65 type: ENDPOINT_ACTIONS.ADD, 71 type: ENDPOINT_ACTIONS.ADD_VIDEO,
66 endpoint: REQUEST_ENDPOINTS.VIDEOS, 72 endpoint: REQUEST_ENDPOINTS.VIDEOS,
67 data: videoData, 73 data: videoData,
68 transaction 74 transaction
@@ -72,7 +78,7 @@ function addVideoToFriends (videoData: RemoteVideoCreateData, transaction: Seque
72 78
73function updateVideoToFriends (videoData: RemoteVideoUpdateData, transaction: Sequelize.Transaction) { 79function updateVideoToFriends (videoData: RemoteVideoUpdateData, transaction: Sequelize.Transaction) {
74 const options = { 80 const options = {
75 type: ENDPOINT_ACTIONS.UPDATE, 81 type: ENDPOINT_ACTIONS.UPDATE_VIDEO,
76 endpoint: REQUEST_ENDPOINTS.VIDEOS, 82 endpoint: REQUEST_ENDPOINTS.VIDEOS,
77 data: videoData, 83 data: videoData,
78 transaction 84 transaction
@@ -82,7 +88,7 @@ function updateVideoToFriends (videoData: RemoteVideoUpdateData, transaction: Se
82 88
83function removeVideoToFriends (videoParams: RemoteVideoRemoveData, transaction: Sequelize.Transaction) { 89function removeVideoToFriends (videoParams: RemoteVideoRemoveData, transaction: Sequelize.Transaction) {
84 const options = { 90 const options = {
85 type: ENDPOINT_ACTIONS.REMOVE, 91 type: ENDPOINT_ACTIONS.REMOVE_VIDEO,
86 endpoint: REQUEST_ENDPOINTS.VIDEOS, 92 endpoint: REQUEST_ENDPOINTS.VIDEOS,
87 data: videoParams, 93 data: videoParams,
88 transaction 94 transaction
@@ -90,12 +96,62 @@ function removeVideoToFriends (videoParams: RemoteVideoRemoveData, transaction:
90 return createRequest(options) 96 return createRequest(options)
91} 97}
92 98
99function addVideoAuthorToFriends (authorData: RemoteVideoAuthorCreateData, transaction: Sequelize.Transaction) {
100 const options = {
101 type: ENDPOINT_ACTIONS.ADD_AUTHOR,
102 endpoint: REQUEST_ENDPOINTS.VIDEOS,
103 data: authorData,
104 transaction
105 }
106 return createRequest(options)
107}
108
109function removeVideoAuthorToFriends (authorData: RemoteVideoAuthorRemoveData, transaction: Sequelize.Transaction) {
110 const options = {
111 type: ENDPOINT_ACTIONS.REMOVE_AUTHOR,
112 endpoint: REQUEST_ENDPOINTS.VIDEOS,
113 data: authorData,
114 transaction
115 }
116 return createRequest(options)
117}
118
119function addVideoChannelToFriends (videoChannelData: RemoteVideoChannelCreateData, transaction: Sequelize.Transaction) {
120 const options = {
121 type: ENDPOINT_ACTIONS.ADD_CHANNEL,
122 endpoint: REQUEST_ENDPOINTS.VIDEOS,
123 data: videoChannelData,
124 transaction
125 }
126 return createRequest(options)
127}
128
129function updateVideoChannelToFriends (videoChannelData: RemoteVideoChannelUpdateData, transaction: Sequelize.Transaction) {
130 const options = {
131 type: ENDPOINT_ACTIONS.UPDATE_CHANNEL,
132 endpoint: REQUEST_ENDPOINTS.VIDEOS,
133 data: videoChannelData,
134 transaction
135 }
136 return createRequest(options)
137}
138
139function removeVideoChannelToFriends (videoChannelParams: RemoteVideoChannelRemoveData, transaction: Sequelize.Transaction) {
140 const options = {
141 type: ENDPOINT_ACTIONS.REMOVE_CHANNEL,
142 endpoint: REQUEST_ENDPOINTS.VIDEOS,
143 data: videoChannelParams,
144 transaction
145 }
146 return createRequest(options)
147}
148
93function reportAbuseVideoToFriend (reportData: RemoteVideoReportAbuseData, video: VideoInstance, transaction: Sequelize.Transaction) { 149function reportAbuseVideoToFriend (reportData: RemoteVideoReportAbuseData, video: VideoInstance, transaction: Sequelize.Transaction) {
94 const options = { 150 const options = {
95 type: ENDPOINT_ACTIONS.REPORT_ABUSE, 151 type: ENDPOINT_ACTIONS.REPORT_ABUSE,
96 endpoint: REQUEST_ENDPOINTS.VIDEOS, 152 endpoint: REQUEST_ENDPOINTS.VIDEOS,
97 data: reportData, 153 data: reportData,
98 toIds: [ video.Author.podId ], 154 toIds: [ video.VideoChannel.Author.podId ],
99 transaction 155 transaction
100 } 156 }
101 return createRequest(options) 157 return createRequest(options)
@@ -207,15 +263,66 @@ function quitFriends () {
207 .finally(() => requestScheduler.activate()) 263 .finally(() => requestScheduler.activate())
208} 264}
209 265
266function sendOwnedDataToPod (podId: number) {
267 // First send authors
268 return sendOwnedAuthorsToPod(podId)
269 .then(() => sendOwnedChannelsToPod(podId))
270 .then(() => sendOwnedVideosToPod(podId))
271}
272
273function sendOwnedChannelsToPod (podId: number) {
274 return db.VideoChannel.listOwned()
275 .then(videoChannels => {
276 const tasks = []
277 videoChannels.forEach(videoChannel => {
278 const remoteVideoChannel = videoChannel.toAddRemoteJSON()
279 const options = {
280 type: 'add-channel' as 'add-channel',
281 endpoint: REQUEST_ENDPOINTS.VIDEOS,
282 data: remoteVideoChannel,
283 toIds: [ podId ],
284 transaction: null
285 }
286
287 const p = createRequest(options)
288 tasks.push(p)
289 })
290
291 return Promise.all(tasks)
292 })
293}
294
295function sendOwnedAuthorsToPod (podId: number) {
296 return db.Author.listOwned()
297 .then(authors => {
298 const tasks = []
299 authors.forEach(author => {
300 const remoteAuthor = author.toAddRemoteJSON()
301 const options = {
302 type: 'add-author' as 'add-author',
303 endpoint: REQUEST_ENDPOINTS.VIDEOS,
304 data: remoteAuthor,
305 toIds: [ podId ],
306 transaction: null
307 }
308
309 const p = createRequest(options)
310 tasks.push(p)
311 })
312
313 return Promise.all(tasks)
314 })
315}
316
210function sendOwnedVideosToPod (podId: number) { 317function sendOwnedVideosToPod (podId: number) {
211 db.Video.listOwnedAndPopulateAuthorAndTags() 318 return db.Video.listOwnedAndPopulateAuthorAndTags()
212 .then(videosList => { 319 .then(videosList => {
213 const tasks = [] 320 const tasks = []
214 videosList.forEach(video => { 321 videosList.forEach(video => {
215 const promise = video.toAddRemoteJSON() 322 const promise = video.toAddRemoteJSON()
216 .then(remoteVideo => { 323 .then(remoteVideo => {
217 const options = { 324 const options = {
218 type: 'add', 325 type: 'add-video' as 'add-video',
219 endpoint: REQUEST_ENDPOINTS.VIDEOS, 326 endpoint: REQUEST_ENDPOINTS.VIDEOS,
220 data: remoteVideo, 327 data: remoteVideo,
221 toIds: [ podId ], 328 toIds: [ podId ],
@@ -236,8 +343,8 @@ function sendOwnedVideosToPod (podId: number) {
236 }) 343 })
237} 344}
238 345
239function fetchRemotePreview (pod: PodInstance, video: VideoInstance) { 346function fetchRemotePreview (video: VideoInstance) {
240 const host = video.Author.Pod.host 347 const host = video.VideoChannel.Author.Pod.host
241 const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName()) 348 const path = join(STATIC_PATHS.PREVIEWS, video.getPreviewName())
242 349
243 return request.get(REMOTE_SCHEME.HTTP + '://' + host + path) 350 return request.get(REMOTE_SCHEME.HTTP + '://' + host + path)
@@ -274,7 +381,9 @@ function getRequestVideoEventScheduler () {
274export { 381export {
275 activateSchedulers, 382 activateSchedulers,
276 addVideoToFriends, 383 addVideoToFriends,
384 removeVideoAuthorToFriends,
277 updateVideoToFriends, 385 updateVideoToFriends,
386 addVideoAuthorToFriends,
278 reportAbuseVideoToFriend, 387 reportAbuseVideoToFriend,
279 quickAndDirtyUpdateVideoToFriends, 388 quickAndDirtyUpdateVideoToFriends,
280 quickAndDirtyUpdatesVideoToFriends, 389 quickAndDirtyUpdatesVideoToFriends,
@@ -285,11 +394,14 @@ export {
285 quitFriends, 394 quitFriends,
286 removeFriend, 395 removeFriend,
287 removeVideoToFriends, 396 removeVideoToFriends,
288 sendOwnedVideosToPod, 397 sendOwnedDataToPod,
289 getRequestScheduler, 398 getRequestScheduler,
290 getRequestVideoQaduScheduler, 399 getRequestVideoQaduScheduler,
291 getRequestVideoEventScheduler, 400 getRequestVideoEventScheduler,
292 fetchRemotePreview 401 fetchRemotePreview,
402 addVideoChannelToFriends,
403 updateVideoChannelToFriends,
404 removeVideoChannelToFriends
293} 405}
294 406
295// --------------------------------------------------------------------------- 407// ---------------------------------------------------------------------------
@@ -373,7 +485,7 @@ function makeRequestsToWinningPods (cert: string, podsList: PodInstance[]) {
373 .then(podCreated => { 485 .then(podCreated => {
374 486
375 // Add our videos to the request scheduler 487 // Add our videos to the request scheduler
376 sendOwnedVideosToPod(podCreated.id) 488 sendOwnedDataToPod(podCreated.id)
377 }) 489 })
378 .catch(err => { 490 .catch(err => {
379 logger.error('Cannot add friend %s pod.', pod.host, err) 491 logger.error('Cannot add friend %s pod.', pod.host, err)
@@ -397,7 +509,7 @@ function makeRequestsToWinningPods (cert: string, podsList: PodInstance[]) {
397 509
398// Wrapper that populate "toIds" argument with all our friends if it is not specified 510// Wrapper that populate "toIds" argument with all our friends if it is not specified
399type CreateRequestOptions = { 511type CreateRequestOptions = {
400 type: string 512 type: RemoteVideoRequestType
401 endpoint: RequestEndpoint 513 endpoint: RequestEndpoint
402 data: Object 514 data: Object
403 toIds?: number[] 515 toIds?: number[]