Support alternative web videos CDN base url

This commit is contained in:
Rin Cat (鈴猫) 2023-11-30 21:18:18 -05:00
parent f51bafb3fa
commit d0086e1636
No known key found for this signature in database
GPG Key ID: 2F3A6F9E2721BF2A
6 changed files with 22 additions and 1 deletions

View File

@ -227,6 +227,9 @@ object_storage:
prefix: '' prefix: ''
base_url: '' base_url: ''
cdn:
web_videos_base_url: ''
log: log:
level: 'info' # 'debug' | 'info' | 'warn' | 'error' level: 'info' # 'debug' | 'info' | 'warn' | 'error'

View File

@ -225,6 +225,9 @@ object_storage:
prefix: '' prefix: ''
base_url: '' base_url: ''
cdn:
web_videos_base_url: '' # Example: 'https://mirror.example.com'
log: log:
level: 'info' # 'debug' | 'info' | 'warn' | 'error' level: 'info' # 'debug' | 'info' | 'warn' | 'error'

View File

@ -65,6 +65,7 @@ function checkMissedConfig () {
'object_storage.credentials.secret_access_key', 'object_storage.max_upload_part', 'object_storage.streaming_playlists.bucket_name', 'object_storage.credentials.secret_access_key', 'object_storage.max_upload_part', 'object_storage.streaming_playlists.bucket_name',
'object_storage.streaming_playlists.prefix', 'object_storage.streaming_playlists.base_url', 'object_storage.web_videos.bucket_name', 'object_storage.streaming_playlists.prefix', 'object_storage.streaming_playlists.base_url', 'object_storage.web_videos.bucket_name',
'object_storage.web_videos.prefix', 'object_storage.web_videos.base_url', 'object_storage.web_videos.prefix', 'object_storage.web_videos.base_url',
'cdn.web_videos_base_url',
'theme.default', 'theme.default',
'feeds.videos.count', 'feeds.comments.count', 'feeds.videos.count', 'feeds.comments.count',
'geo_ip.enabled', 'geo_ip.country.database_url', 'geo_ip.enabled', 'geo_ip.country.database_url',

View File

@ -155,6 +155,9 @@ const CONFIG = {
BASE_URL: config.get<string>('object_storage.streaming_playlists.base_url') BASE_URL: config.get<string>('object_storage.streaming_playlists.base_url')
} }
}, },
CDN: {
WEB_VIDEOS_BASE_URL: config.get<string>('cdn.web_videos_base_url')
},
WEBSERVER: { WEBSERVER: {
SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http', SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws', WS: config.get<boolean>('webserver.https') === true ? 'wss' : 'ws',

View File

@ -540,6 +540,8 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
if (video.isOwned()) { if (video.isOwned()) {
if (this.storage === VideoStorage.OBJECT_STORAGE) { if (this.storage === VideoStorage.OBJECT_STORAGE) {
return this.getObjectStorageUrl(video) return this.getObjectStorageUrl(video)
} else if (CONFIG.CDN.WEB_VIDEOS_BASE_URL) {
return CONFIG.CDN.WEB_VIDEOS_BASE_URL + this.getFileStaticPath(video)
} }
return WEBSERVER.URL + this.getFileStaticPath(video) return WEBSERVER.URL + this.getFileStaticPath(video)
@ -579,7 +581,12 @@ export class VideoFileModel extends Model<Partial<AttributesOnly<VideoFileModel>
? join(STATIC_DOWNLOAD_PATHS.HLS_VIDEOS, `${video.uuid}-${this.resolution}-fragmented${this.extname}`) ? join(STATIC_DOWNLOAD_PATHS.HLS_VIDEOS, `${video.uuid}-${this.resolution}-fragmented${this.extname}`)
: join(STATIC_DOWNLOAD_PATHS.VIDEOS, `${video.uuid}-${this.resolution}${this.extname}`) : join(STATIC_DOWNLOAD_PATHS.VIDEOS, `${video.uuid}-${this.resolution}${this.extname}`)
if (video.isOwned()) return WEBSERVER.URL + path if (video.isOwned()) {
if (CONFIG.CDN.WEB_VIDEOS_BASE_URL) {
return CONFIG.CDN.WEB_VIDEOS_BASE_URL + path
}
return WEBSERVER.URL + path
}
// FIXME: don't guess remote URL // FIXME: don't guess remote URL
return buildRemoteVideoBaseUrl(video, path) return buildRemoteVideoBaseUrl(video, path)

View File

@ -256,6 +256,8 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
if (video.isOwned()) { if (video.isOwned()) {
if (this.storage === VideoStorage.OBJECT_STORAGE) { if (this.storage === VideoStorage.OBJECT_STORAGE) {
return this.getMasterPlaylistObjectStorageUrl(video) return this.getMasterPlaylistObjectStorageUrl(video)
} else if (CONFIG.CDN.WEB_VIDEOS_BASE_URL) {
return CONFIG.CDN.WEB_VIDEOS_BASE_URL + this.getMasterPlaylistStaticPath(video)
} }
return WEBSERVER.URL + this.getMasterPlaylistStaticPath(video) return WEBSERVER.URL + this.getMasterPlaylistStaticPath(video)
@ -278,6 +280,8 @@ export class VideoStreamingPlaylistModel extends Model<Partial<AttributesOnly<Vi
if (video.isOwned()) { if (video.isOwned()) {
if (this.storage === VideoStorage.OBJECT_STORAGE) { if (this.storage === VideoStorage.OBJECT_STORAGE) {
return this.getSha256SegmentsObjectStorageUrl(video) return this.getSha256SegmentsObjectStorageUrl(video)
} else if (CONFIG.CDN.WEB_VIDEOS_BASE_URL) {
return CONFIG.CDN.WEB_VIDEOS_BASE_URL + this.getSha256SegmentsStaticPath(video)
} }
return WEBSERVER.URL + this.getSha256SegmentsStaticPath(video) return WEBSERVER.URL + this.getSha256SegmentsStaticPath(video)