Skip to content

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

Don't crash on invalid endpoint URL

Chocobozzz8a797a5e0683
diff --git a/server/core/lib/object-storage/shared/client.ts b/server/core/lib/object-storage/shared/client.ts
index 9f3605af00..3e6093ba72 100644
--- a/server/core/lib/object-storage/shared/client.ts
+++ b/server/core/lib/object-storage/shared/client.ts
@@ -5,30 +5,8 @@ import { getProxyAgent } from '@server/helpers/requests.js'
import { CONFIG } from '@server/initializers/config.js'
import { lTags } from './logger.js'
-async function getProxyRequestHandler () {
- if (!isProxyEnabled()) return null
-
- const { agent } = getProxyAgent()
-
- const { NodeHttpHandler } = await import('@smithy/node-http-handler')
-
- return new NodeHttpHandler({
- httpAgent: agent.http,
- httpsAgent: agent.https
- })
-}
-
-let endpointParsed: URL
-function getEndpointParsed () {
- if (endpointParsed) return endpointParsed
-
- endpointParsed = new URL(getEndpoint())
-
- return endpointParsed
-}
-
let s3ClientPromise: Promise<S3Client>
-function getClient () {
+export function getClient () {
if (s3ClientPromise !== undefined) return s3ClientPromise
s3ClientPromise = (async () => {
@@ -62,17 +40,8 @@ function getClient () {
return s3ClientPromise
}
-// ---------------------------------------------------------------------------
-
-export {
- getEndpointParsed,
- getClient
-}
-
-// ---------------------------------------------------------------------------
-
let endpoint: string
-function getEndpoint () {
+export function getEndpoint () {
if (endpoint) return endpoint
const endpointConfig = CONFIG.OBJECT_STORAGE.ENDPOINT
@@ -82,3 +51,20 @@ function getEndpoint () {
return endpoint
}
+
+// ---------------------------------------------------------------------------
+// Private
+// ---------------------------------------------------------------------------
+
+async function getProxyRequestHandler () {
+ if (!isProxyEnabled()) return null
+
+ const { agent } = getProxyAgent()
+
+ const { NodeHttpHandler } = await import('@smithy/node-http-handler')
+
+ return new NodeHttpHandler({
+ httpAgent: agent.http,
+ httpsAgent: agent.https
+ })
+}
diff --git a/server/core/lib/object-storage/urls.ts b/server/core/lib/object-storage/urls.ts
index d967a8e284..3e986c4596 100644
--- a/server/core/lib/object-storage/urls.ts
+++ b/server/core/lib/object-storage/urls.ts
@@ -1,7 +1,8 @@
+import { logger } from '@server/helpers/logger.js'
import { CONFIG } from '@server/initializers/config.js'
import { OBJECT_STORAGE_PROXY_PATHS, WEBSERVER } from '@server/initializers/constants.js'
import { MVideoUUID } from '@server/types/models/index.js'
-import { BucketInfo, buildKey, getEndpointParsed } from './shared/index.js'
+import { BucketInfo, buildKey, getEndpoint, lTags } from './shared/index.js'
// ---------------------------------------------------------------------------
@@ -26,17 +27,41 @@ export function buildObjectStorageWebVideoPrivateFileUrl (filename: string) {
// Private
// ---------------------------------------------------------------------------
+let baseUrl: string
function buildBaseUrl (bucketInfo: BucketInfo) {
+ if (baseUrl) return baseUrl
+
+ baseUrl = _buildBaseUrl(bucketInfo)
+
+ return baseUrl
+}
+
+function _buildBaseUrl (bucketInfo: BucketInfo) {
+ let endpointParsed: URL
+
+ try {
+ endpointParsed = new URL(getEndpoint())
+ } catch (error) {
+ logger.error(
+ `Invalid object storage endpoint URL: ${getEndpoint()}. ` +
+ `If you enabled object storage, ensure object_storage.endpoint is correctly configured. ` +
+ `Otherwise, check that you have correctly moved all your videos to your local filesystem.`,
+ lTags()
+ )
+
+ return ''
+ }
+
let baseUrlConfig = bucketInfo.BASE_URL
if (baseUrlConfig && !baseUrlConfig.endsWith('/')) baseUrlConfig += '/'
if (CONFIG.OBJECT_STORAGE.FORCE_PATH_STYLE) {
- const baseUrl = baseUrlConfig || `${getEndpointParsed().protocol}//${getEndpointParsed().host}/`
+ const baseUrl = baseUrlConfig || `${endpointParsed.protocol}//${endpointParsed.host}/`
return baseUrl + `${bucketInfo.BUCKET_NAME}/`
}
if (baseUrlConfig) return baseUrlConfig
- return `${getEndpointParsed().protocol}//${bucketInfo.BUCKET_NAME}.${getEndpointParsed().host}/`
+ return `${endpointParsed.protocol}//${bucketInfo.BUCKET_NAME}.${endpointParsed.host}/`
}