Skip to content

Commit

Permalink
Use base url instead of url template
Browse files Browse the repository at this point in the history
  • Loading branch information
pingiun committed Aug 2, 2021
1 parent 42fec67 commit 03c6d12
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
11 changes: 2 additions & 9 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,11 @@ s3:
streaming_playlists_bucket: ''
# Allows setting all buckets to the same value but with a different prefix
streaming_playlists_prefix: ''
# Optional, use to overide the default url generation that just gives the public url to s3
# Use the string %path% in place where the (full) path to the file should be. The path
# does not include the streaming_playlists_prefix, so you should add it to your template if needed.
# For example:
# https://my-videos-cache.example.com/cdn-cache/%path%?thing=true
# Would turn into:
# https://my-videos-cache.example.com/cdn-cache/hls/9ffceb57-cbe3-41c5-80e4-dbb7e97c3958/b27d1892-9c5c-4bef-8bce-f68e54fb1208-240-fragmented.mp4?thing=true
streaming_playlists_url_template: ''
streaming_playlists_base_url: ''
# Same settings but for webtorrent videos
videos_bucket: ''
videos_prefix: ''
videos_url_template: ''
videos_url_base_url: ''

log:
level: 'info' # 'debug' | 'info' | 'warn' | 'error'
Expand Down
7 changes: 0 additions & 7 deletions server/initializers/checker-after-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,6 @@ function checkConfig () {
return 'Object storage bucket prefixes should be set to different values when the same bucket is used for both types of video.'
}
}
if (
(CONFIG.S3.VIDEOS_BUCKETINFO.url_template !== '' &&
!CONFIG.S3.VIDEOS_BUCKETINFO.url_template.includes('%path%')) ||
(CONFIG.S3.STREAMING_PLAYLISTS_BUCKETINFO.url_template !== '' &&
!CONFIG.S3.STREAMING_PLAYLISTS_BUCKETINFO.url_template.includes('%path%'))) {
return 'Object storage url templates should include `%path%\' in place where the file path needs to be inserted.'
}
}

return null
Expand Down
4 changes: 2 additions & 2 deletions server/initializers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ const CONFIG = {
VIDEOS_BUCKETINFO: {
bucket: config.get<string>('s3.videos_bucket'),
prefix: config.get<string>('s3.videos_prefix'),
url_template: config.get<string>('s3.videos_url_template')
base_url: config.get<string>('s3.videos_base_url')
},
STREAMING_PLAYLISTS_BUCKETINFO: {
bucket: config.get<string>('s3.streaming_playlists_bucket'),
prefix: config.get<string>('s3.streaming_playlists_prefix'),
url_template: config.get<string>('s3.streaming_playlists_url_template')
base_url: config.get<string>('s3.streaming_playlists_base_url')
}
},
WEBSERVER: {
Expand Down
6 changes: 3 additions & 3 deletions server/lib/object-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DeleteObjectCommand, DeleteObjectsCommand, ListObjectsV2Command, PutObj
import { CONFIG } from "@server/initializers/config"
import { logger } from '@server/helpers/logger'

type BucketInfo = {bucket: string, prefix?: string, url_template?: string}
type BucketInfo = {bucket: string, prefix?: string, base_url?: string}

function getS3Client () {
return new S3Client({ endpoint: `https://${CONFIG.S3.ENDPOINT}` })
Expand Down Expand Up @@ -65,8 +65,8 @@ export async function removePrefix (prefix: string, bucketInfo: BucketInfo) {
}

export function generateUrl (filename: string, bucketInfo: BucketInfo) {
if (!bucketInfo.url_template) {
if (!bucketInfo.base_url) {
return `https://${bucketInfo.bucket}.${CONFIG.S3.ENDPOINT}/${bucketInfo.prefix}${filename}`
}
return bucketInfo.url_template.replace('%path%', filename)
return bucketInfo.base_url + filename
}

0 comments on commit 03c6d12

Please sign in to comment.