Table,
UpdatedAt
} from 'sequelize-typescript'
-import { getHLSPublicFileUrl } from '@server/lib/object-storage'
+import { CONFIG } from '@server/initializers/config'
+import { getHLSPrivateFileUrl, getHLSPublicFileUrl } from '@server/lib/object-storage'
import { generateHLSMasterPlaylistFilename, generateHlsSha256SegmentsFilename } from '@server/lib/paths'
+import { isVideoInPrivateDirectory } from '@server/lib/video-privacy'
import { VideoFileModel } from '@server/models/video/video-file'
import { MStreamingPlaylist, MStreamingPlaylistFilesVideo, MVideo } from '@server/types/models'
import { sha1 } from '@shared/extra-utils'
WEBSERVER
} from '../../initializers/constants'
import { VideoRedundancyModel } from '../redundancy/video-redundancy'
-import { doesExist } from '../shared'
-import { throwIfNotValid } from '../utils'
+import { doesExist, throwIfNotValid } from '../shared'
import { VideoModel } from './video'
@Table({
static doesInfohashExist (infoHash: string) {
const query = 'SELECT 1 FROM "videoStreamingPlaylist" WHERE $infoHash = ANY("p2pMediaLoaderInfohashes") LIMIT 1'
- return doesExist(query, { infoHash })
+ return doesExist(this.sequelize, query, { infoHash })
}
static buildP2PMediaLoaderInfoHashes (playlistUrl: string, files: unknown[]) {
`AND "video"."remote" IS FALSE AND "video"."uuid" = $videoUUID ` +
`AND "storage" = ${VideoStorage.FILE_SYSTEM} LIMIT 1`
- return doesExist(query, { videoUUID })
+ return doesExist(this.sequelize, query, { videoUUID })
}
assignP2PMediaLoaderInfoHashes (video: MVideo, files: unknown[]) {
this.p2pMediaLoaderInfohashes = VideoStreamingPlaylistModel.buildP2PMediaLoaderInfoHashes(masterPlaylistUrl, files)
}
+ // ---------------------------------------------------------------------------
+
getMasterPlaylistUrl (video: MVideo) {
if (video.isOwned()) {
if (this.storage === VideoStorage.OBJECT_STORAGE) {
- return getHLSPublicFileUrl(this.playlistUrl)
+ return this.getMasterPlaylistObjectStorageUrl(video)
}
- return WEBSERVER.URL + this.getMasterPlaylistStaticPath(video.uuid)
+ return WEBSERVER.URL + this.getMasterPlaylistStaticPath(video)
}
return this.playlistUrl
}
+ private getMasterPlaylistObjectStorageUrl (video: MVideo) {
+ if (video.hasPrivateStaticPath() && CONFIG.OBJECT_STORAGE.PROXY.PROXIFY_PRIVATE_FILES === true) {
+ return getHLSPrivateFileUrl(video, this.playlistFilename)
+ }
+
+ return getHLSPublicFileUrl(this.playlistUrl)
+ }
+
+ // ---------------------------------------------------------------------------
+
getSha256SegmentsUrl (video: MVideo) {
if (video.isOwned()) {
if (this.storage === VideoStorage.OBJECT_STORAGE) {
- return getHLSPublicFileUrl(this.segmentsSha256Url)
+ return this.getSha256SegmentsObjectStorageUrl(video)
}
- return WEBSERVER.URL + this.getSha256SegmentsStaticPath(video.uuid)
+ return WEBSERVER.URL + this.getSha256SegmentsStaticPath(video)
}
return this.segmentsSha256Url
}
+ private getSha256SegmentsObjectStorageUrl (video: MVideo) {
+ if (video.hasPrivateStaticPath() && CONFIG.OBJECT_STORAGE.PROXY.PROXIFY_PRIVATE_FILES === true) {
+ return getHLSPrivateFileUrl(video, this.segmentsSha256Filename)
+ }
+
+ return getHLSPublicFileUrl(this.segmentsSha256Url)
+ }
+
+ // ---------------------------------------------------------------------------
+
getStringType () {
if (this.type === VideoStreamingPlaylistType.HLS) return 'hls'
return Object.assign(this, { Video: video })
}
- private getMasterPlaylistStaticPath (videoUUID: string) {
- return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, this.playlistFilename)
+ private getMasterPlaylistStaticPath (video: MVideo) {
+ if (isVideoInPrivateDirectory(video.privacy)) {
+ return join(STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS, video.uuid, this.playlistFilename)
+ }
+
+ return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, video.uuid, this.playlistFilename)
}
- private getSha256SegmentsStaticPath (videoUUID: string) {
- return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, videoUUID, this.segmentsSha256Filename)
+ private getSha256SegmentsStaticPath (video: MVideo) {
+ if (isVideoInPrivateDirectory(video.privacy)) {
+ return join(STATIC_PATHS.STREAMING_PLAYLISTS.PRIVATE_HLS, video.uuid, this.segmentsSha256Filename)
+ }
+
+ return join(STATIC_PATHS.STREAMING_PLAYLISTS.HLS, video.uuid, this.segmentsSha256Filename)
}
}