mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Add ability to delete a specific video file
This commit is contained in:
parent
12d84abeca
commit
1bb4c9ab2e
23 changed files with 678 additions and 209 deletions
|
@ -2,6 +2,7 @@ import express from 'express'
|
|||
import toInt from 'validator/lib/toInt'
|
||||
import { logger, loggerTagsFactory } from '@server/helpers/logger'
|
||||
import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
|
||||
import { removeAllWebTorrentFiles, removeHLSFile, removeHLSPlaylist, removeWebTorrentFile } from '@server/lib/video-file'
|
||||
import { VideoFileModel } from '@server/models/video/video-file'
|
||||
import { HttpStatusCode, UserRight } from '@shared/models'
|
||||
import {
|
||||
|
@ -9,10 +10,13 @@ import {
|
|||
authenticate,
|
||||
ensureUserHasRight,
|
||||
videoFileMetadataGetValidator,
|
||||
videoFilesDeleteHLSFileValidator,
|
||||
videoFilesDeleteHLSValidator,
|
||||
videoFilesDeleteWebTorrentFileValidator,
|
||||
videoFilesDeleteWebTorrentValidator,
|
||||
videosGetValidator
|
||||
} from '../../../middlewares'
|
||||
import { updatePlaylistAfterFileChange } from '@server/lib/hls'
|
||||
|
||||
const lTags = loggerTagsFactory('api', 'video')
|
||||
const filesRouter = express.Router()
|
||||
|
@ -27,14 +31,26 @@ filesRouter.delete('/:id/hls',
|
|||
authenticate,
|
||||
ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
|
||||
asyncMiddleware(videoFilesDeleteHLSValidator),
|
||||
asyncMiddleware(removeHLSPlaylist)
|
||||
asyncMiddleware(removeHLSPlaylistController)
|
||||
)
|
||||
filesRouter.delete('/:id/hls/:videoFileId',
|
||||
authenticate,
|
||||
ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
|
||||
asyncMiddleware(videoFilesDeleteHLSFileValidator),
|
||||
asyncMiddleware(removeHLSFileController)
|
||||
)
|
||||
|
||||
filesRouter.delete('/:id/webtorrent',
|
||||
authenticate,
|
||||
ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
|
||||
asyncMiddleware(videoFilesDeleteWebTorrentValidator),
|
||||
asyncMiddleware(removeWebTorrentFiles)
|
||||
asyncMiddleware(removeAllWebTorrentFilesController)
|
||||
)
|
||||
filesRouter.delete('/:id/webtorrent/:videoFileId',
|
||||
authenticate,
|
||||
ensureUserHasRight(UserRight.MANAGE_VIDEO_FILES),
|
||||
asyncMiddleware(videoFilesDeleteWebTorrentFileValidator),
|
||||
asyncMiddleware(removeWebTorrentFileController)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -51,33 +67,53 @@ async function getVideoFileMetadata (req: express.Request, res: express.Response
|
|||
return res.json(videoFile.metadata)
|
||||
}
|
||||
|
||||
async function removeHLSPlaylist (req: express.Request, res: express.Response) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function removeHLSPlaylistController (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
|
||||
logger.info('Deleting HLS playlist of %s.', video.url, lTags(video.uuid))
|
||||
|
||||
const hls = video.getHLSPlaylist()
|
||||
await video.removeStreamingPlaylistFiles(hls)
|
||||
await hls.destroy()
|
||||
|
||||
video.VideoStreamingPlaylists = video.VideoStreamingPlaylists.filter(p => p.id !== hls.id)
|
||||
await removeHLSPlaylist(video)
|
||||
|
||||
await federateVideoIfNeeded(video, false, undefined)
|
||||
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
async function removeWebTorrentFiles (req: express.Request, res: express.Response) {
|
||||
async function removeHLSFileController (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
const videoFileId = +req.params.videoFileId
|
||||
|
||||
logger.info('Deleting HLS file %d of %s.', videoFileId, video.url, lTags(video.uuid))
|
||||
|
||||
const playlist = await removeHLSFile(video, videoFileId)
|
||||
if (playlist) await updatePlaylistAfterFileChange(video, playlist)
|
||||
|
||||
await federateVideoIfNeeded(video, false, undefined)
|
||||
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
async function removeAllWebTorrentFilesController (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
|
||||
logger.info('Deleting WebTorrent files of %s.', video.url, lTags(video.uuid))
|
||||
|
||||
for (const file of video.VideoFiles) {
|
||||
await video.removeWebTorrentFileAndTorrent(file)
|
||||
await file.destroy()
|
||||
}
|
||||
|
||||
video.VideoFiles = []
|
||||
await removeAllWebTorrentFiles(video)
|
||||
await federateVideoIfNeeded(video, false, undefined)
|
||||
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
}
|
||||
|
||||
async function removeWebTorrentFileController (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
|
||||
const videoFileId = +req.params.videoFileId
|
||||
logger.info('Deleting WebTorrent file %d of %s.', videoFileId, video.url, lTags(video.uuid))
|
||||
|
||||
await removeWebTorrentFile(video, videoFileId)
|
||||
await federateVideoIfNeeded(video, false, undefined)
|
||||
|
||||
return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue