aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos
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/api/videos
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/api/videos')
-rw-r--r--server/controllers/api/videos/import.ts48
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'
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