aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-01-19 14:23:00 +0100
committerChocobozzz <me@florianbigard.com>2022-01-19 14:31:05 +0100
commit419b520ca4434d17f3505013174e195c3a316716 (patch)
tree24dbf663c4e11e970cb780f96e6eb3efe023b222 /server/controllers
parent52435e467a0b30175a10af1dd3ae10d7d564d8ae (diff)
downloadPeerTube-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.ts26
-rw-r--r--server/controllers/api/videos/import.ts48
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 @@
1import express from 'express' 1import express from 'express'
2import { Job, JobState, JobType, ResultList, UserRight } from '@shared/models' 2import { HttpStatusCode, Job, JobState, JobType, ResultList, UserRight } from '@shared/models'
3import { isArray } from '../../helpers/custom-validators/misc' 3import { isArray } from '../../helpers/custom-validators/misc'
4import { JobQueue } from '../../lib/job-queue' 4import { JobQueue } from '../../lib/job-queue'
5import { 5import {
@@ -16,6 +16,18 @@ import { listJobsValidator } from '../../middlewares/validators/jobs'
16 16
17const jobsRouter = express.Router() 17const jobsRouter = express.Router()
18 18
19jobsRouter.post('/pause',
20 authenticate,
21 ensureUserHasRight(UserRight.MANAGE_JOBS),
22 asyncMiddleware(pauseJobQueue)
23)
24
25jobsRouter.post('/resume',
26 authenticate,
27 ensureUserHasRight(UserRight.MANAGE_JOBS),
28 asyncMiddleware(resumeJobQueue)
29)
30
19jobsRouter.get('/:state?', 31jobsRouter.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
51async function pauseJobQueue (req: express.Request, res: express.Response) {
52 await JobQueue.Instance.pause()
53
54 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
55}
56
57async function resumeJobQueue (req: express.Request, res: express.Response) {
58 await JobQueue.Instance.resume()
59
60 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
61}
62
39async function listJobs (req: express.Request, res: express.Response) { 63async 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'
21import { MVideoImportFormattable } from '@server/types/models/video/video-import' 21import { MVideoImportFormattable } from '@server/types/models/video/video-import'
22import { ServerErrorCode, ThumbnailType, VideoImportCreate, VideoImportState, VideoPrivacy, VideoState } from '@shared/models' 22import {
23 HttpStatusCode,
24 ServerErrorCode,
25 ThumbnailType,
26 VideoImportCreate,
27 VideoImportState,
28 VideoPrivacy,
29 VideoState
30} from '@shared/models'
23import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger' 31import { auditLoggerFactory, getAuditIdFromRes, VideoImportAuditView } from '../../../helpers/audit-logger'
24import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils' 32import { moveAndProcessCaptionFile } from '../../../helpers/captions-utils'
25import { isArray } from '../../../helpers/custom-validators/misc' 33import { isArray } from '../../../helpers/custom-validators/misc'
@@ -34,7 +42,14 @@ import { getLocalVideoActivityPubUrl } from '../../../lib/activitypub/url'
34import { JobQueue } from '../../../lib/job-queue/job-queue' 42import { JobQueue } from '../../../lib/job-queue/job-queue'
35import { updateVideoMiniatureFromExisting, updateVideoMiniatureFromUrl } from '../../../lib/thumbnail' 43import { updateVideoMiniatureFromExisting, updateVideoMiniatureFromUrl } from '../../../lib/thumbnail'
36import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist' 44import { autoBlacklistVideoIfNeeded } from '../../../lib/video-blacklist'
37import { asyncMiddleware, asyncRetryTransactionMiddleware, authenticate, videoImportAddValidator } from '../../../middlewares' 45import {
46 asyncMiddleware,
47 asyncRetryTransactionMiddleware,
48 authenticate,
49 videoImportAddValidator,
50 videoImportCancelValidator,
51 videoImportDeleteValidator
52} from '../../../middlewares'
38import { VideoModel } from '../../../models/video/video' 53import { VideoModel } from '../../../models/video/video'
39import { VideoCaptionModel } from '../../../models/video/video-caption' 54import { VideoCaptionModel } from '../../../models/video/video-caption'
40import { VideoImportModel } from '../../../models/video/video-import' 55import { VideoImportModel } from '../../../models/video/video-import'
@@ -59,6 +74,18 @@ videoImportsRouter.post('/imports',
59 asyncRetryTransactionMiddleware(addVideoImport) 74 asyncRetryTransactionMiddleware(addVideoImport)
60) 75)
61 76
77videoImportsRouter.post('/imports/:id/cancel',
78 authenticate,
79 asyncMiddleware(videoImportCancelValidator),
80 asyncRetryTransactionMiddleware(cancelVideoImport)
81)
82
83videoImportsRouter.delete('/imports/:id',
84 authenticate,
85 asyncMiddleware(videoImportDeleteValidator),
86 asyncRetryTransactionMiddleware(deleteVideoImport)
87)
88
62// --------------------------------------------------------------------------- 89// ---------------------------------------------------------------------------
63 90
64export { 91export {
@@ -67,6 +94,23 @@ export {
67 94
68// --------------------------------------------------------------------------- 95// ---------------------------------------------------------------------------
69 96
97async 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
105async 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
70function addVideoImport (req: express.Request, res: express.Response) { 114function 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