mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Implement user import/export in server
This commit is contained in:
parent
4d63e6f577
commit
8573e5a80a
196 changed files with 5661 additions and 722 deletions
|
@ -1,32 +1,40 @@
|
|||
import { join } from 'path'
|
||||
import { CONFIG } from '@server/initializers/config.js'
|
||||
import { DIRECTORIES, VIDEO_LIVE } from '@server/initializers/constants.js'
|
||||
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models/index.js'
|
||||
import {
|
||||
isStreamingPlaylist,
|
||||
MStreamingPlaylistVideo,
|
||||
MUserExport,
|
||||
MUserImport,
|
||||
MVideo,
|
||||
MVideoFile,
|
||||
MVideoUUID
|
||||
} from '@server/types/models/index.js'
|
||||
import { removeFragmentedMP4Ext } from '@peertube/peertube-core-utils'
|
||||
import { buildUUID } from '@peertube/peertube-node-utils'
|
||||
import { isVideoInPrivateDirectory } from './video-privacy.js'
|
||||
|
||||
// ################## Video file name ##################
|
||||
|
||||
function generateWebVideoFilename (resolution: number, extname: string) {
|
||||
export function generateWebVideoFilename (resolution: number, extname: string) {
|
||||
return buildUUID() + '-' + resolution + extname
|
||||
}
|
||||
|
||||
function generateHLSVideoFilename (resolution: number) {
|
||||
export function generateHLSVideoFilename (resolution: number) {
|
||||
return `${buildUUID()}-${resolution}-fragmented.mp4`
|
||||
}
|
||||
|
||||
// ################## Streaming playlist ##################
|
||||
|
||||
function getLiveDirectory (video: MVideo) {
|
||||
export function getLiveDirectory (video: MVideo) {
|
||||
return getHLSDirectory(video)
|
||||
}
|
||||
|
||||
function getLiveReplayBaseDirectory (video: MVideo) {
|
||||
export function getLiveReplayBaseDirectory (video: MVideo) {
|
||||
return join(getLiveDirectory(video), VIDEO_LIVE.REPLAY_DIRECTORY)
|
||||
}
|
||||
|
||||
function getHLSDirectory (video: MVideo) {
|
||||
export function getHLSDirectory (video: MVideo) {
|
||||
if (isVideoInPrivateDirectory(video.privacy)) {
|
||||
return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PRIVATE, video.uuid)
|
||||
}
|
||||
|
@ -34,22 +42,22 @@ function getHLSDirectory (video: MVideo) {
|
|||
return join(DIRECTORIES.HLS_STREAMING_PLAYLIST.PUBLIC, video.uuid)
|
||||
}
|
||||
|
||||
function getHLSRedundancyDirectory (video: MVideoUUID) {
|
||||
export function getHLSRedundancyDirectory (video: MVideoUUID) {
|
||||
return join(DIRECTORIES.HLS_REDUNDANCY, video.uuid)
|
||||
}
|
||||
|
||||
function getHlsResolutionPlaylistFilename (videoFilename: string) {
|
||||
export function getHlsResolutionPlaylistFilename (videoFilename: string) {
|
||||
// Video file name already contain resolution
|
||||
return removeFragmentedMP4Ext(videoFilename) + '.m3u8'
|
||||
}
|
||||
|
||||
function generateHLSMasterPlaylistFilename (isLive = false) {
|
||||
export function generateHLSMasterPlaylistFilename (isLive = false) {
|
||||
if (isLive) return 'master.m3u8'
|
||||
|
||||
return buildUUID() + '-master.m3u8'
|
||||
}
|
||||
|
||||
function generateHlsSha256SegmentsFilename (isLive = false) {
|
||||
export function generateHlsSha256SegmentsFilename (isLive = false) {
|
||||
if (isLive) return 'segments-sha256.json'
|
||||
|
||||
return buildUUID() + '-segments-sha256.json'
|
||||
|
@ -57,7 +65,7 @@ function generateHlsSha256SegmentsFilename (isLive = false) {
|
|||
|
||||
// ################## Torrents ##################
|
||||
|
||||
function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
|
||||
export function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVideo, resolution: number) {
|
||||
const extension = '.torrent'
|
||||
const uuid = buildUUID()
|
||||
|
||||
|
@ -68,25 +76,16 @@ function generateTorrentFileName (videoOrPlaylist: MVideo | MStreamingPlaylistVi
|
|||
return uuid + '-' + resolution + extension
|
||||
}
|
||||
|
||||
function getFSTorrentFilePath (videoFile: MVideoFile) {
|
||||
export function getFSTorrentFilePath (videoFile: MVideoFile) {
|
||||
return join(CONFIG.STORAGE.TORRENTS_DIR, videoFile.torrentFilename)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
generateHLSVideoFilename,
|
||||
generateWebVideoFilename,
|
||||
|
||||
generateTorrentFileName,
|
||||
getFSTorrentFilePath,
|
||||
|
||||
getHLSDirectory,
|
||||
getLiveDirectory,
|
||||
getLiveReplayBaseDirectory,
|
||||
getHLSRedundancyDirectory,
|
||||
|
||||
generateHLSMasterPlaylistFilename,
|
||||
generateHlsSha256SegmentsFilename,
|
||||
getHlsResolutionPlaylistFilename
|
||||
export function getFSUserExportFilePath (userExport: MUserExport) {
|
||||
return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, userExport.filename)
|
||||
}
|
||||
|
||||
export function getFSUserImportFilePath (userImport: MUserImport) {
|
||||
return join(CONFIG.STORAGE.TMP_PERSISTENT_DIR, userImport.filename)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue