aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/server/redundancy.ts70
-rw-r--r--shared/extra-utils/videos/videos.ts18
2 files changed, 83 insertions, 5 deletions
diff --git a/shared/extra-utils/server/redundancy.ts b/shared/extra-utils/server/redundancy.ts
index c39ff2c8b..7b488e23e 100644
--- a/shared/extra-utils/server/redundancy.ts
+++ b/shared/extra-utils/server/redundancy.ts
@@ -1,6 +1,7 @@
1import { makePutBodyRequest } from '../requests/requests' 1import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2import { VideoRedundanciesTarget } from '@shared/models'
2 3
3async function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) { 4function updateRedundancy (url: string, accessToken: string, host: string, redundancyAllowed: boolean, expectedStatus = 204) {
4 const path = '/api/v1/server/redundancy/' + host 5 const path = '/api/v1/server/redundancy/' + host
5 6
6 return makePutBodyRequest({ 7 return makePutBodyRequest({
@@ -12,6 +13,69 @@ async function updateRedundancy (url: string, accessToken: string, host: string,
12 }) 13 })
13} 14}
14 15
16function listVideoRedundancies (options: {
17 url: string
18 accessToken: string,
19 target: VideoRedundanciesTarget,
20 start?: number,
21 count?: number,
22 sort?: string,
23 statusCodeExpected?: number
24}) {
25 const path = '/api/v1/server/redundancy/videos'
26
27 const { url, accessToken, target, statusCodeExpected, start, count, sort } = options
28
29 return makeGetRequest({
30 url,
31 token: accessToken,
32 path,
33 query: {
34 start: start ?? 0,
35 count: count ?? 5,
36 sort: sort ?? 'name',
37 target
38 },
39 statusCodeExpected: statusCodeExpected || 200
40 })
41}
42
43function addVideoRedundancy (options: {
44 url: string,
45 accessToken: string,
46 videoId: number
47}) {
48 const path = '/api/v1/server/redundancy/videos'
49 const { url, accessToken, videoId } = options
50
51 return makePostBodyRequest({
52 url,
53 token: accessToken,
54 path,
55 fields: { videoId },
56 statusCodeExpected: 204
57 })
58}
59
60function removeVideoRedundancy (options: {
61 url: string,
62 accessToken: string,
63 redundancyId: number
64}) {
65 const { url, accessToken, redundancyId } = options
66 const path = '/api/v1/server/redundancy/videos/' + redundancyId
67
68 return makeDeleteRequest({
69 url,
70 token: accessToken,
71 path,
72 statusCodeExpected: 204
73 })
74}
75
15export { 76export {
16 updateRedundancy 77 updateRedundancy,
78 listVideoRedundancies,
79 addVideoRedundancy,
80 removeVideoRedundancy
17} 81}
diff --git a/shared/extra-utils/videos/videos.ts b/shared/extra-utils/videos/videos.ts
index 7a77a03ad..aa13273ae 100644
--- a/shared/extra-utils/videos/videos.ts
+++ b/shared/extra-utils/videos/videos.ts
@@ -607,15 +607,28 @@ async function videoUUIDToId (url: string, id: number | string) {
607 return res.body.id 607 return res.body.id
608} 608}
609 609
610async function uploadVideoAndGetId (options: { server: ServerInfo, videoName: string, nsfw?: boolean, token?: string }) { 610async function uploadVideoAndGetId (options: {
611 server: ServerInfo,
612 videoName: string,
613 nsfw?: boolean,
614 privacy?: VideoPrivacy,
615 token?: string
616}) {
611 const videoAttrs: any = { name: options.videoName } 617 const videoAttrs: any = { name: options.videoName }
612 if (options.nsfw) videoAttrs.nsfw = options.nsfw 618 if (options.nsfw) videoAttrs.nsfw = options.nsfw
619 if (options.privacy) videoAttrs.privacy = options.privacy
613 620
614 const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs) 621 const res = await uploadVideo(options.server.url, options.token || options.server.accessToken, videoAttrs)
615 622
616 return { id: res.body.video.id, uuid: res.body.video.uuid } 623 return { id: res.body.video.id, uuid: res.body.video.uuid }
617} 624}
618 625
626async function getLocalIdByUUID (url: string, uuid: string) {
627 const res = await getVideo(url, uuid)
628
629 return res.body.id
630}
631
619// --------------------------------------------------------------------------- 632// ---------------------------------------------------------------------------
620 633
621export { 634export {
@@ -645,5 +658,6 @@ export {
645 completeVideoCheck, 658 completeVideoCheck,
646 checkVideoFilesWereRemoved, 659 checkVideoFilesWereRemoved,
647 getPlaylistVideos, 660 getPlaylistVideos,
648 uploadVideoAndGetId 661 uploadVideoAndGetId,
662 getLocalIdByUUID
649} 663}