1 import express from 'express'
2 import { MVideo } from '@server/types/models'
3 import { HttpStatusCode } from '@shared/models'
4 import { logger } from '../../../helpers/logger'
5 import { areValidationErrors, doesVideoExist, isValidVideoIdParam } from '../shared'
7 const videoFilesDeleteWebTorrentValidator = [
8 isValidVideoIdParam('id'),
10 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
11 logger.debug('Checking videoFilesDeleteWebTorrent parameters', { parameters: req.params })
13 if (areValidationErrors(req, res)) return
14 if (!await doesVideoExist(req.params.id, res)) return
16 const video = res.locals.videoAll
18 if (!checkLocalVideo(video, res)) return
20 if (!video.hasWebTorrentFiles()) {
22 status: HttpStatusCode.BAD_REQUEST_400,
23 message: 'This video does not have WebTorrent files'
27 if (!video.getHLSPlaylist()) {
29 status: HttpStatusCode.BAD_REQUEST_400,
30 message: 'Cannot delete WebTorrent files since this video does not have HLS playlist'
38 const videoFilesDeleteHLSValidator = [
39 isValidVideoIdParam('id'),
41 async (req: express.Request, res: express.Response, next: express.NextFunction) => {
42 logger.debug('Checking videoFilesDeleteHLS parameters', { parameters: req.params })
44 if (areValidationErrors(req, res)) return
45 if (!await doesVideoExist(req.params.id, res)) return
47 const video = res.locals.videoAll
49 if (!checkLocalVideo(video, res)) return
51 if (!video.getHLSPlaylist()) {
53 status: HttpStatusCode.BAD_REQUEST_400,
54 message: 'This video does not have HLS files'
58 if (!video.hasWebTorrentFiles()) {
60 status: HttpStatusCode.BAD_REQUEST_400,
61 message: 'Cannot delete HLS playlist since this video does not have WebTorrent files'
70 videoFilesDeleteWebTorrentValidator,
71 videoFilesDeleteHLSValidator
74 // ---------------------------------------------------------------------------
76 function checkLocalVideo (video: MVideo, res: express.Response) {
79 status: HttpStatusCode.BAD_REQUEST_400,
80 message: 'Cannot delete files of remote video'