Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Fix S3 base url with forced path style

Chocobozzzf0e597a03f54
diff --git a/packages/tests/src/api/object-storage/videos.ts b/packages/tests/src/api/object-storage/videos.ts
index 6fcebb667c..80397825a8 100644
--- a/packages/tests/src/api/object-storage/videos.ts
+++ b/packages/tests/src/api/object-storage/videos.ts
@@ -34,11 +34,7 @@ function buildBaseUrl (options: {
}) {
const { baseMockUrl, bucket, pathStyle } = options
- if (baseMockUrl) {
- if (pathStyle) return `${baseMockUrl}/${bucket}/${bucket}/`
-
- return `${baseMockUrl}/${bucket}/`
- }
+ if (baseMockUrl) return `${baseMockUrl}/${bucket}/`
if (pathStyle) return `http://${ObjectStorageCommand.getMockEndpointHost()}/${bucket}/`
diff --git a/server/core/lib/object-storage/pre-signed-urls.ts b/server/core/lib/object-storage/pre-signed-urls.ts
index 436f7eb6ef..82c857b7ba 100644
--- a/server/core/lib/object-storage/pre-signed-urls.ts
+++ b/server/core/lib/object-storage/pre-signed-urls.ts
@@ -93,9 +93,15 @@ async function generatePresignedUrl (options: {
return getSignedUrl(await getClient(), command, { expiresIn: 3600 * 24 })
}
-const regex = new RegExp('https?://[^/]+')
+const regex = CONFIG.OBJECT_STORAGE.FORCE_PATH_STYLE === true
+ ? new RegExp('https?://[^/]+/[^/]+')
+ : new RegExp('https?://[^/]+')
function replaceByBaseUrl (fileUrl: string, bucket: { BASE_URL: string }) {
if (!bucket.BASE_URL) return fileUrl
- return fileUrl.replace(regex, bucket.BASE_URL)
+ const baseUrl = bucket.BASE_URL.endsWith('/')
+ ? bucket.BASE_URL.slice(0, -1)
+ : bucket.BASE_URL
+
+ return fileUrl.replace(regex, baseUrl)
}
diff --git a/server/core/lib/object-storage/urls.ts b/server/core/lib/object-storage/urls.ts
index 4ccd8c51ac..499bb5f5e8 100644
--- a/server/core/lib/object-storage/urls.ts
+++ b/server/core/lib/object-storage/urls.ts
@@ -31,16 +31,16 @@ function buildBaseUrl (bucketInfo: BucketInfo) {
const endpointParsed = getEndpointParsed()
if (!endpointParsed) return ''
- let baseUrlConfig = bucketInfo.BASE_URL
- if (baseUrlConfig && !baseUrlConfig.endsWith('/')) baseUrlConfig += '/'
+ const baseUrlConfig = bucketInfo.BASE_URL
+ if (baseUrlConfig) {
+ if (!baseUrlConfig.endsWith('/')) return `${baseUrlConfig}/`
- if (CONFIG.OBJECT_STORAGE.FORCE_PATH_STYLE) {
- const baseUrl = baseUrlConfig || `${endpointParsed.protocol}//${endpointParsed.host}/`
-
- return baseUrl + `${bucketInfo.BUCKET_NAME}/`
+ return baseUrlConfig
}
- if (baseUrlConfig) return baseUrlConfig
+ if (CONFIG.OBJECT_STORAGE.FORCE_PATH_STYLE) {
+ return `${endpointParsed.protocol}//${endpointParsed.host}/${bucketInfo.BUCKET_NAME}/`
+ }
return `${endpointParsed.protocol}//${bucketInfo.BUCKET_NAME}.${endpointParsed.host}/`
}