diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-05-14 11:10:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 11:10:26 +0200 |
commit | 2158ac90341dc3fcae958540de65032da25c8d6e (patch) | |
tree | a780923d701f3daa130996768e38c1e1b6a0646c /shared | |
parent | 7405b6ba897dbce1b4fd50c92174f1df5ac15adc (diff) | |
download | PeerTube-2158ac90341dc3fcae958540de65032da25c8d6e.tar.gz PeerTube-2158ac90341dc3fcae958540de65032da25c8d6e.tar.zst PeerTube-2158ac90341dc3fcae958540de65032da25c8d6e.zip |
Add server plugin filter hooks for import with torrent and url (#2621)
* Add server plugin filter hooks for import with torrent and url
* WIP: pre and post-import filter hooks
* Rebased
* Cleanup filters to accept imports
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/extra-utils/videos/video-imports.ts | 4 | ||||
-rw-r--r-- | shared/models/plugins/server-hook.model.ts | 6 | ||||
-rw-r--r-- | shared/models/server/job.model.ts | 7 | ||||
-rw-r--r-- | shared/models/videos/import/video-import-state.enum.ts | 3 |
4 files changed, 14 insertions, 6 deletions
diff --git a/shared/extra-utils/videos/video-imports.ts b/shared/extra-utils/videos/video-imports.ts index 8e5abd2f5..d235181b0 100644 --- a/shared/extra-utils/videos/video-imports.ts +++ b/shared/extra-utils/videos/video-imports.ts | |||
@@ -15,7 +15,7 @@ function getBadVideoUrl () { | |||
15 | return 'https://download.cpy.re/peertube/bad_video.mp4' | 15 | return 'https://download.cpy.re/peertube/bad_video.mp4' |
16 | } | 16 | } |
17 | 17 | ||
18 | function importVideo (url: string, token: string, attributes: VideoImportCreate) { | 18 | function importVideo (url: string, token: string, attributes: VideoImportCreate & { torrentfile?: string }, statusCodeExpected = 200) { |
19 | const path = '/api/v1/videos/imports' | 19 | const path = '/api/v1/videos/imports' |
20 | 20 | ||
21 | let attaches: any = {} | 21 | let attaches: any = {} |
@@ -27,7 +27,7 @@ function importVideo (url: string, token: string, attributes: VideoImportCreate) | |||
27 | token, | 27 | token, |
28 | attaches, | 28 | attaches, |
29 | fields: attributes, | 29 | fields: attributes, |
30 | statusCodeExpected: 200 | 30 | statusCodeExpected |
31 | }) | 31 | }) |
32 | } | 32 | } |
33 | 33 | ||
diff --git a/shared/models/plugins/server-hook.model.ts b/shared/models/plugins/server-hook.model.ts index 20f89b86d..5f812904f 100644 --- a/shared/models/plugins/server-hook.model.ts +++ b/shared/models/plugins/server-hook.model.ts | |||
@@ -9,9 +9,13 @@ export const serverFilterHookObject = { | |||
9 | // Used to get detailed video information (video watch page for example) | 9 | // Used to get detailed video information (video watch page for example) |
10 | 'filter:api.video.get.result': true, | 10 | 'filter:api.video.get.result': true, |
11 | 11 | ||
12 | // Filter the result of the accept upload function | 12 | // Filter the result of the accept upload, import via torrent or url functions |
13 | // If this function returns false then the upload is aborted with an error | 13 | // If this function returns false then the upload is aborted with an error |
14 | 'filter:api.video.upload.accept.result': true, | 14 | 'filter:api.video.upload.accept.result': true, |
15 | 'filter:api.video.pre-import-url.accept.result': true, | ||
16 | 'filter:api.video.pre-import-torrent.accept.result': true, | ||
17 | 'filter:api.video.post-import-url.accept.result': true, | ||
18 | 'filter:api.video.post-import-torrent.accept.result': true, | ||
15 | // Filter the result of the accept comment (thread or reply) functions | 19 | // Filter the result of the accept comment (thread or reply) functions |
16 | // If the functions return false then the user cannot post its comment | 20 | // If the functions return false then the user cannot post its comment |
17 | 'filter:api.video-thread.create.accept.result': true, | 21 | 'filter:api.video-thread.create.accept.result': true, |
diff --git a/shared/models/server/job.model.ts b/shared/models/server/job.model.ts index 57d61c480..61010e5a8 100644 --- a/shared/models/server/job.model.ts +++ b/shared/models/server/job.model.ts | |||
@@ -70,8 +70,11 @@ export type VideoFileImportPayload = { | |||
70 | filePath: string | 70 | filePath: string |
71 | } | 71 | } |
72 | 72 | ||
73 | export type VideoImportTorrentPayloadType = 'magnet-uri' | 'torrent-file' | ||
74 | export type VideoImportYoutubeDLPayloadType = 'youtube-dl' | ||
75 | |||
73 | export type VideoImportYoutubeDLPayload = { | 76 | export type VideoImportYoutubeDLPayload = { |
74 | type: 'youtube-dl' | 77 | type: VideoImportYoutubeDLPayloadType |
75 | videoImportId: number | 78 | videoImportId: number |
76 | 79 | ||
77 | generateThumbnail: boolean | 80 | generateThumbnail: boolean |
@@ -80,7 +83,7 @@ export type VideoImportYoutubeDLPayload = { | |||
80 | fileExt?: string | 83 | fileExt?: string |
81 | } | 84 | } |
82 | export type VideoImportTorrentPayload = { | 85 | export type VideoImportTorrentPayload = { |
83 | type: 'magnet-uri' | 'torrent-file' | 86 | type: VideoImportTorrentPayloadType |
84 | videoImportId: number | 87 | videoImportId: number |
85 | } | 88 | } |
86 | export type VideoImportPayload = VideoImportYoutubeDLPayload | VideoImportTorrentPayload | 89 | export type VideoImportPayload = VideoImportYoutubeDLPayload | VideoImportTorrentPayload |
diff --git a/shared/models/videos/import/video-import-state.enum.ts b/shared/models/videos/import/video-import-state.enum.ts index b178fbf3a..8421b8ca7 100644 --- a/shared/models/videos/import/video-import-state.enum.ts +++ b/shared/models/videos/import/video-import-state.enum.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | export enum VideoImportState { | 1 | export enum VideoImportState { |
2 | PENDING = 1, | 2 | PENDING = 1, |
3 | SUCCESS = 2, | 3 | SUCCESS = 2, |
4 | FAILED = 3 | 4 | FAILED = 3, |
5 | REJECTED = 4 | ||
5 | } | 6 | } |