diff options
author | Chocobozzz <me@florianbigard.com> | 2022-01-19 14:23:00 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-01-19 14:31:05 +0100 |
commit | 419b520ca4434d17f3505013174e195c3a316716 (patch) | |
tree | 24dbf663c4e11e970cb780f96e6eb3efe023b222 /server/controllers/api/videos | |
parent | 52435e467a0b30175a10af1dd3ae10d7d564d8ae (diff) | |
download | PeerTube-419b520ca4434d17f3505013174e195c3a316716.tar.gz PeerTube-419b520ca4434d17f3505013174e195c3a316716.tar.zst PeerTube-419b520ca4434d17f3505013174e195c3a316716.zip |
Add ability to cancel & delete video imports
Diffstat (limited to 'server/controllers/api/videos')
-rw-r--r-- | server/controllers/api/videos/import.ts | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/server/controllers/api/videos/import.ts b/server/controllers/api/videos/import.ts index 08d69827b..8cbfd3286 100644 --- a/server/controllers/api/videos/import.ts +++ b/server/controllers/api/videos/import.ts | |||
@@ -19,7 +19,15 @@ import { | |||
19 | MVideoWithBlacklistLight | 19 | MVideoWithBlacklistLight |
20 | } from '@server/types/models' | 20 | } from '@server/types/models' |
21 | import { MVideoImportFormattable } from '@server/types/models/video/video-import' | 21 | import { MVideoImportFormattable } from '@server/types/models/video/video-import' |
22 | import { ServerErrorCode, ThumbnailType, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '@shared/models' | 22 | import { |
23 | HttpStatusCode, | ||
24 | ServerErrorCode, | ||
25 | ThumbnailType, | ||
26 | VideoImportCreate, | ||
27 | VideoImportState, | ||
28 | VideoPrivacy, | ||
29 | VideoState | ||
30 | } from '@shared/models' | ||
23 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' | 31 | import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' |
24 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' | 32 | import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' |
25 | import { isArray } from '../../../helpers/custom-validators/misc' | 33 | import { isArray } from '../../../helpers/custom-validators/misc' |
@@ -34,7 +42,14 @@ import { getLocalVideoActivityPubUrl } from '../../../lib/activitypub/url' | |||
34 | import { JobQueue } from '../../../lib/job-queue/job-queue' | 42 | import { JobQueue } from '../../../lib/job-queue/job-queue' |
35 | import { updateVideoMiniatureFromExisting, updateVideoMiniatureFromUrl } from '../../../lib/thumbnail' | 43 | import { updateVideoMiniatureFromExisting, updateVideoMiniatureFromUrl } from '../../../lib/thumbnail' |
36 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' | 44 | import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' |
37 | import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' | 45 | import { |
46 | asyncMiddleware, | ||
47 | asyncRetryTransactionMiddleware, | ||
48 | authenticate, | ||
49 | videoImportAddValidator, | ||
50 | videoImportCancelValidator, | ||
51 | videoImportDeleteValidator | ||
52 | } from '../../../middlewares' | ||
38 | import { VideoModel } from '../../../models/video/video' | 53 | import { VideoModel } from '../../../models/video/video' |
39 | import { VideoCaptionModel } from '../../../models/video/video-caption' | 54 | import { VideoCaptionModel } from '../../../models/video/video-caption' |
40 | import { VideoImportModel } from '../../../models/video/video-import' | 55 | import { VideoImportModel } from '../../../models/video/video-import' |
@@ -59,6 +74,18 @@ videoImportsRouter.post('/imports', | |||
59 | asyncRetryTransactionMiddleware(addVideoImport) | 74 | asyncRetryTransactionMiddleware(addVideoImport) |
60 | ) | 75 | ) |
61 | 76 | ||
77 | videoImportsRouter.post('/imports/:id/cancel', | ||
78 | authenticate, | ||
79 | asyncMiddleware(videoImportCancelValidator), | ||
80 | asyncRetryTransactionMiddleware(cancelVideoImport) | ||
81 | ) | ||
82 | |||
83 | videoImportsRouter.delete('/imports/:id', | ||
84 | authenticate, | ||
85 | asyncMiddleware(videoImportDeleteValidator), | ||
86 | asyncRetryTransactionMiddleware(deleteVideoImport) | ||
87 | ) | ||
88 | |||
62 | // --------------------------------------------------------------------------- | 89 | // --------------------------------------------------------------------------- |
63 | 90 | ||
64 | export { | 91 | export { |
@@ -67,6 +94,23 @@ export { | |||
67 | 94 | ||
68 | // --------------------------------------------------------------------------- | 95 | // --------------------------------------------------------------------------- |
69 | 96 | ||
97 | async function deleteVideoImport (req: express.Request, res: express.Response) { | ||
98 | const videoImport = res.locals.videoImport | ||
99 | |||
100 | await videoImport.destroy() | ||
101 | |||
102 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
103 | } | ||
104 | |||
105 | async function cancelVideoImport (req: express.Request, res: express.Response) { | ||
106 | const videoImport = res.locals.videoImport | ||
107 | |||
108 | videoImport.state = VideoImportState.CANCELLED | ||
109 | await videoImport.save() | ||
110 | |||
111 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
112 | } | ||
113 | |||
70 | function addVideoImport (req: express.Request, res: express.Response) { | 114 | function addVideoImport (req: express.Request, res: express.Response) { |
71 | if (req.body.targetUrl) return addYoutubeDLImport(req, res) | 115 | if (req.body.targetUrl) return addYoutubeDLImport(req, res) |
72 | 116 | ||