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 | |
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')
-rw-r--r-- | server/controllers/api/jobs.ts | 26 | ||||
-rw-r--r-- | server/controllers/api/videos/import.ts | 48 |
2 files changed, 71 insertions, 3 deletions
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts index eebd195b0..c61b7362f 100644 --- a/server/controllers/api/jobs.ts +++ b/server/controllers/api/jobs.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { Job, JobState, JobType, ResultList, UserRight } from '@shared/models' | 2 | import { HttpStatusCode, Job, JobState, JobType, ResultList, UserRight } from '@shared/models' |
3 | import { isArray } from '../../helpers/custom-validators/misc' | 3 | import { isArray } from '../../helpers/custom-validators/misc' |
4 | import { JobQueue } from '../../lib/job-queue' | 4 | import { JobQueue } from '../../lib/job-queue' |
5 | import { | 5 | import { |
@@ -16,6 +16,18 @@ import { listJobsValidator } from '../../middlewares/validators/jobs' | |||
16 | 16 | ||
17 | const jobsRouter = express.Router() | 17 | const jobsRouter = express.Router() |
18 | 18 | ||
19 | jobsRouter.post('/pause', | ||
20 | authenticate, | ||
21 | ensureUserHasRight(UserRight.MANAGE_JOBS), | ||
22 | asyncMiddleware(pauseJobQueue) | ||
23 | ) | ||
24 | |||
25 | jobsRouter.post('/resume', | ||
26 | authenticate, | ||
27 | ensureUserHasRight(UserRight.MANAGE_JOBS), | ||
28 | asyncMiddleware(resumeJobQueue) | ||
29 | ) | ||
30 | |||
19 | jobsRouter.get('/:state?', | 31 | jobsRouter.get('/:state?', |
20 | openapiOperationDoc({ operationId: 'getJobs' }), | 32 | openapiOperationDoc({ operationId: 'getJobs' }), |
21 | authenticate, | 33 | authenticate, |
@@ -36,6 +48,18 @@ export { | |||
36 | 48 | ||
37 | // --------------------------------------------------------------------------- | 49 | // --------------------------------------------------------------------------- |
38 | 50 | ||
51 | async function pauseJobQueue (req: express.Request, res: express.Response) { | ||
52 | await JobQueue.Instance.pause() | ||
53 | |||
54 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
55 | } | ||
56 | |||
57 | async function resumeJobQueue (req: express.Request, res: express.Response) { | ||
58 | await JobQueue.Instance.resume() | ||
59 | |||
60 | return res.sendStatus(HttpStatusCode.NO_CONTENT_204) | ||
61 | } | ||
62 | |||
39 | async function listJobs (req: express.Request, res: express.Response) { | 63 | async function listJobs (req: express.Request, res: express.Response) { |
40 | const state = req.params.state as JobState | 64 | const state = req.params.state as JobState |
41 | const asc = req.query.sort === 'createdAt' | 65 | const asc = req.query.sort === 'createdAt' |
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 | ||