mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
Add config option to keep original video file (basic first version) (#6157)
* testing not removing old file and adding columb to db * implement feature * remove unnecessary config changes * use only keptOriginalFileName, change keptOriginalFileName to keptOriginalFilename for consistency with with videoFile table, slight refactor with basename() * save original video files to dedicated directory original-video-files * begin implementing object storage (bucket) support --------- Co-authored-by: chagai.friedlander <chagai.friedlander@fairkom.eu> Co-authored-by: Ian <ian.kraft@hotmail.com> Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
parent
ae31e90c30
commit
e57c3024f4
75 changed files with 1653 additions and 801 deletions
|
@ -1,12 +1,14 @@
|
|||
import cors from 'cors'
|
||||
import express from 'express'
|
||||
import { forceNumber } from '@peertube/peertube-core-utils'
|
||||
import { FileStorage, HttpStatusCode, VideoStreamingPlaylistType } from '@peertube/peertube-models'
|
||||
import { logger } from '@server/helpers/logger.js'
|
||||
import { VideoTorrentsSimpleFileCache } from '@server/lib/files-cache/index.js'
|
||||
import {
|
||||
generateHLSFilePresignedUrl,
|
||||
generateOriginalFilePresignedUrl,
|
||||
generateUserExportPresignedUrl,
|
||||
generateWebVideoPresignedUrl
|
||||
} from '@server/lib/object-storage/index.js'
|
||||
import { getFSUserExportFilePath } from '@server/lib/paths.js'
|
||||
import { Hooks } from '@server/lib/plugins/hooks.js'
|
||||
import { VideoPathManager } from '@server/lib/video-path-manager.js'
|
||||
import {
|
||||
|
@ -17,15 +19,16 @@ import {
|
|||
MVideoFile,
|
||||
MVideoFullLight
|
||||
} from '@server/types/models/index.js'
|
||||
import { forceNumber } from '@peertube/peertube-core-utils'
|
||||
import { HttpStatusCode, FileStorage, VideoStreamingPlaylistType } from '@peertube/peertube-models'
|
||||
import { MVideoSource } from '@server/types/models/video/video-source.js'
|
||||
import cors from 'cors'
|
||||
import express from 'express'
|
||||
import { STATIC_DOWNLOAD_PATHS } from '../initializers/constants.js'
|
||||
import {
|
||||
asyncMiddleware, optionalAuthenticate,
|
||||
originalVideoFileDownloadValidator,
|
||||
userExportDownloadValidator,
|
||||
videosDownloadValidator
|
||||
} from '../middlewares/index.js'
|
||||
import { getFSUserExportFilePath } from '@server/lib/paths.js'
|
||||
|
||||
const downloadRouter = express.Router()
|
||||
|
||||
|
@ -40,7 +43,7 @@ downloadRouter.use(
|
|||
STATIC_DOWNLOAD_PATHS.VIDEOS + ':id-:resolution([0-9]+).:extension',
|
||||
optionalAuthenticate,
|
||||
asyncMiddleware(videosDownloadValidator),
|
||||
asyncMiddleware(downloadVideoFile)
|
||||
asyncMiddleware(downloadWebVideoFile)
|
||||
)
|
||||
|
||||
downloadRouter.use(
|
||||
|
@ -51,11 +54,18 @@ downloadRouter.use(
|
|||
)
|
||||
|
||||
downloadRouter.use(
|
||||
STATIC_DOWNLOAD_PATHS.USER_EXPORT + ':filename',
|
||||
STATIC_DOWNLOAD_PATHS.USER_EXPORTS + ':filename',
|
||||
asyncMiddleware(userExportDownloadValidator), // Include JWT token authentication
|
||||
asyncMiddleware(downloadUserExport)
|
||||
)
|
||||
|
||||
downloadRouter.use(
|
||||
STATIC_DOWNLOAD_PATHS.ORIGINAL_VIDEO_FILE + ':filename',
|
||||
optionalAuthenticate,
|
||||
asyncMiddleware(originalVideoFileDownloadValidator),
|
||||
asyncMiddleware(downloadOriginalFile)
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
|
@ -91,7 +101,7 @@ async function downloadTorrent (req: express.Request, res: express.Response) {
|
|||
return res.download(result.path, result.downloadName)
|
||||
}
|
||||
|
||||
async function downloadVideoFile (req: express.Request, res: express.Response) {
|
||||
async function downloadWebVideoFile (req: express.Request, res: express.Response) {
|
||||
const video = res.locals.videoAll
|
||||
|
||||
const videoFile = getVideoFile(req, video.VideoFiles)
|
||||
|
@ -184,6 +194,19 @@ function downloadUserExport (req: express.Request, res: express.Response) {
|
|||
return Promise.resolve()
|
||||
}
|
||||
|
||||
function downloadOriginalFile (req: express.Request, res: express.Response) {
|
||||
const videoSource = res.locals.videoSource
|
||||
|
||||
const downloadFilename = videoSource.inputFilename
|
||||
|
||||
if (videoSource.storage === FileStorage.OBJECT_STORAGE) {
|
||||
return redirectOriginalFileToObjectStorage({ res, videoSource, downloadFilename })
|
||||
}
|
||||
|
||||
res.download(VideoPathManager.Instance.getFSOriginalVideoFilePath(videoSource.keptOriginalFilename), downloadFilename)
|
||||
return Promise.resolve()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getVideoFile (req: express.Request, files: MVideoFile[]) {
|
||||
|
@ -262,3 +285,17 @@ async function redirectUserExportToObjectStorage (options: {
|
|||
|
||||
return res.redirect(url)
|
||||
}
|
||||
|
||||
async function redirectOriginalFileToObjectStorage (options: {
|
||||
res: express.Response
|
||||
downloadFilename: string
|
||||
videoSource: MVideoSource
|
||||
}) {
|
||||
const { res, downloadFilename, videoSource } = options
|
||||
|
||||
const url = await generateOriginalFilePresignedUrl({ videoSource, downloadFilename })
|
||||
|
||||
logger.debug('Generating pre-signed URL %s for original video file %s', url, videoSource.keptOriginalFilename)
|
||||
|
||||
return res.redirect(url)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue