2024-04-26 02:58:35 -04:00
|
|
|
import { VideoPrivacy } from '@peertube/peertube-models'
|
2023-07-31 08:34:36 -04:00
|
|
|
import { CONFIG } from '@server/initializers/config.js'
|
|
|
|
import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo } from '@server/types/models/index.js'
|
2024-04-26 02:58:35 -04:00
|
|
|
import { Response } from 'express'
|
2018-09-19 05:16:23 -04:00
|
|
|
|
2024-04-26 02:58:35 -04:00
|
|
|
export function getVideoWithAttributes (res: Response) {
|
2021-06-11 08:09:33 -04:00
|
|
|
return res.locals.videoAPI || res.locals.videoAll || res.locals.onlyVideo
|
2019-08-20 07:52:49 -04:00
|
|
|
}
|
|
|
|
|
2024-04-26 02:58:35 -04:00
|
|
|
export function extractVideo (videoOrPlaylist: MVideo | MStreamingPlaylistVideo) {
|
2020-04-23 03:32:53 -04:00
|
|
|
return isStreamingPlaylist(videoOrPlaylist)
|
|
|
|
? videoOrPlaylist.Video
|
|
|
|
: videoOrPlaylist
|
|
|
|
}
|
|
|
|
|
2024-04-26 02:58:35 -04:00
|
|
|
export function getPrivaciesForFederation () {
|
2020-06-03 03:42:07 -04:00
|
|
|
return (CONFIG.FEDERATION.VIDEOS.FEDERATE_UNLISTED === true)
|
|
|
|
? [ { privacy: VideoPrivacy.PUBLIC }, { privacy: VideoPrivacy.UNLISTED } ]
|
|
|
|
: [ { privacy: VideoPrivacy.PUBLIC } ]
|
|
|
|
}
|
|
|
|
|
2024-04-26 02:58:35 -04:00
|
|
|
export function getExtFromMimetype (mimeTypes: { [id: string]: string | string[] }, mimeType: string) {
|
2020-08-10 08:25:29 -04:00
|
|
|
const value = mimeTypes[mimeType]
|
|
|
|
|
|
|
|
if (Array.isArray(value)) return value[0]
|
|
|
|
|
|
|
|
return value
|
|
|
|
}
|
2024-05-31 05:31:52 -04:00
|
|
|
|
|
|
|
export function peertubeLicenceToSPDX (licence: number) {
|
|
|
|
return {
|
|
|
|
1: 'CC-BY-4.0',
|
|
|
|
2: 'CC-BY-SA-4.0',
|
|
|
|
3: 'CC-BY-ND-4.0',
|
|
|
|
4: 'CC-BY-NC-4.0',
|
|
|
|
5: 'CC-BY-NC-SA-4.0',
|
|
|
|
6: 'CC-BY-NC-ND-4.0',
|
|
|
|
7: 'CC0'
|
|
|
|
}[licence]
|
|
|
|
}
|
|
|
|
|
|
|
|
export function spdxToPeertubeLicence (licence: string) {
|
|
|
|
return {
|
|
|
|
'CC-BY-4.0': 1,
|
|
|
|
'CC-BY-SA-4.0': 2,
|
|
|
|
'CC-BY-ND-4.0': 3,
|
|
|
|
'CC-BY-NC-4.0': 4,
|
|
|
|
'CC-BY-NC-SA-4.0': 5,
|
|
|
|
'CC-BY-NC-ND-4.0': 6,
|
|
|
|
'CC0': 7
|
|
|
|
}[licence]
|
|
|
|
}
|