mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-06 03:50:26 +02:00
Always specify s3 content type
This commit is contained in:
parent
fb9d678f7f
commit
4739b117e8
7 changed files with 57 additions and 36 deletions
|
@ -2,7 +2,7 @@ import { logger } from '@server/helpers/logger.js'
|
|||
import { CONFIG } from '@server/initializers/config.js'
|
||||
import { MStreamingPlaylistVideo, MStreamingPlaylistVideoUUID, MVideo, MVideoCaption, MVideoFile } from '@server/types/models/index.js'
|
||||
import { MVideoSource } from '@server/types/models/video/video-source.js'
|
||||
import { basename, join } from 'path'
|
||||
import { basename, extname, join } from 'path'
|
||||
import { getHLSDirectory } from '../paths.js'
|
||||
import { VideoPathManager } from '../video-path-manager.js'
|
||||
import {
|
||||
|
@ -25,6 +25,7 @@ import {
|
|||
updateObjectACL,
|
||||
updatePrefixACL
|
||||
} from './shared/index.js'
|
||||
import { MIMETYPES } from '@server/initializers/constants.js'
|
||||
|
||||
export function listHLSFileKeysOf (playlist: MStreamingPlaylistVideo) {
|
||||
return listKeysOfPrefix(generateHLSObjectBaseStorageKey(playlist), CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS)
|
||||
|
@ -37,35 +38,38 @@ export function storeHLSFileFromFilename (playlist: MStreamingPlaylistVideo, fil
|
|||
inputPath: join(getHLSDirectory(playlist.Video), filename),
|
||||
objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
|
||||
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
||||
isPrivate: playlist.Video.hasPrivateStaticPath()
|
||||
isPrivate: playlist.Video.hasPrivateStaticPath(),
|
||||
contentType: getObjectStorageContentType(filename)
|
||||
})
|
||||
}
|
||||
|
||||
export function storeHLSFileFromPath (playlist: MStreamingPlaylistVideo, path: string) {
|
||||
const filename = basename(path)
|
||||
|
||||
return storeObject({
|
||||
inputPath: path,
|
||||
objectStorageKey: generateHLSObjectStorageKey(playlist, basename(path)),
|
||||
objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
|
||||
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
||||
isPrivate: playlist.Video.hasPrivateStaticPath()
|
||||
isPrivate: playlist.Video.hasPrivateStaticPath(),
|
||||
contentType: getObjectStorageContentType(filename)
|
||||
})
|
||||
}
|
||||
|
||||
export function storeHLSFileFromContent (
|
||||
options: {
|
||||
playlist: MStreamingPlaylistVideo
|
||||
pathOrFilename: string
|
||||
content: string
|
||||
contentType: string
|
||||
}
|
||||
) {
|
||||
const { playlist, pathOrFilename, content, contentType } = options
|
||||
export function storeHLSFileFromContent (options: {
|
||||
playlist: MStreamingPlaylistVideo
|
||||
pathOrFilename: string
|
||||
content: string
|
||||
}) {
|
||||
const { playlist, pathOrFilename, content } = options
|
||||
|
||||
const filename = basename(pathOrFilename)
|
||||
|
||||
return storeContent({
|
||||
content,
|
||||
objectStorageKey: generateHLSObjectStorageKey(playlist, basename(pathOrFilename)),
|
||||
objectStorageKey: generateHLSObjectStorageKey(playlist, filename),
|
||||
bucketInfo: CONFIG.OBJECT_STORAGE.STREAMING_PLAYLISTS,
|
||||
isPrivate: playlist.Video.hasPrivateStaticPath(),
|
||||
contentType
|
||||
contentType: getObjectStorageContentType(filename)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -76,7 +80,8 @@ export function storeWebVideoFile (video: MVideo, file: MVideoFile) {
|
|||
inputPath: VideoPathManager.Instance.getFSVideoFileOutputPath(video, file),
|
||||
objectStorageKey: generateWebVideoObjectStorageKey(file.filename),
|
||||
bucketInfo: CONFIG.OBJECT_STORAGE.WEB_VIDEOS,
|
||||
isPrivate: video.hasPrivateStaticPath()
|
||||
isPrivate: video.hasPrivateStaticPath(),
|
||||
contentType: getObjectStorageContentType(file.filename)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -88,7 +93,7 @@ export function storeVideoCaption (inputPath: string, filename: string) {
|
|||
objectStorageKey: generateCaptionObjectStorageKey(filename),
|
||||
bucketInfo: CONFIG.OBJECT_STORAGE.CAPTIONS,
|
||||
isPrivate: false,
|
||||
contentType: 'text/vtt; charset=UTF-8'
|
||||
contentType: getObjectStorageContentType(filename)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -99,7 +104,8 @@ export function storeOriginalVideoFile (inputPath: string, filename: string) {
|
|||
inputPath,
|
||||
objectStorageKey: generateOriginalVideoObjectStorageKey(filename),
|
||||
bucketInfo: CONFIG.OBJECT_STORAGE.ORIGINAL_VIDEO_FILES,
|
||||
isPrivate: true
|
||||
isPrivate: true,
|
||||
contentType: getObjectStorageContentType(filename)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -279,3 +285,25 @@ export function getCaptionReadStream (options: {
|
|||
rangeHeader
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Private
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function getObjectStorageContentType (filename: string) {
|
||||
if (filename.endsWith('.m3u8')) {
|
||||
return 'application/x-mpegURL; charset=utf-8'
|
||||
}
|
||||
|
||||
if (filename.endsWith('.json')) {
|
||||
return 'application/json; charset=utf-8'
|
||||
}
|
||||
|
||||
if (filename.endsWith('.vtt')) {
|
||||
return 'text/vtt; charset=utf-8'
|
||||
}
|
||||
|
||||
const ext = extname(filename).toLowerCase()
|
||||
|
||||
return MIMETYPES.VIDEO.EXT_MIMETYPE[ext] || MIMETYPES.AUDIO.EXT_MIMETYPE[ext]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue