]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/object-storage/shared/client.ts
Translated using Weblate (Persian)
[github/Chocobozzz/PeerTube.git] / server / lib / object-storage / shared / client.ts
index 85682c4926e397c877764e52e29b79c98dadf9b0..d5cb074df8ebff3447767882bf912c26664be0c9 100644 (file)
@@ -1,8 +1,22 @@
 import { S3Client } from '@aws-sdk/client-s3'
+import { NodeHttpHandler } from '@aws-sdk/node-http-handler'
 import { logger } from '@server/helpers/logger'
+import { isProxyEnabled } from '@server/helpers/proxy'
+import { getAgent } from '@server/helpers/requests'
 import { CONFIG } from '@server/initializers/config'
 import { lTags } from './logger'
 
+function getProxyRequestHandler () {
+  if (!isProxyEnabled()) return null
+
+  const { agent } = getAgent()
+
+  return new NodeHttpHandler({
+    httpAgent: agent.http,
+    httpsAgent: agent.https
+  })
+}
+
 let endpointParsed: URL
 function getEndpointParsed () {
   if (endpointParsed) return endpointParsed
@@ -26,23 +40,10 @@ function getClient () {
         accessKeyId: OBJECT_STORAGE.CREDENTIALS.ACCESS_KEY_ID,
         secretAccessKey: OBJECT_STORAGE.CREDENTIALS.SECRET_ACCESS_KEY
       }
-      : undefined
+      : undefined,
+    requestHandler: getProxyRequestHandler()
   })
 
-  // FIXME: https://github.com/aws/aws-sdk-js-v3/issues/2445 workaround
-  s3Client.middlewareStack.add(
-    (next, _context) => (args: any) => {
-      if (typeof args.request?.body === 'string' && args.request.body.includes('CompletedMultipartUpload')) {
-        args.request.body = args.request.body.replace(/CompletedMultipartUpload/g, 'CompleteMultipartUpload')
-      }
-      return next(args)
-    },
-    {
-      step: 'build',
-      priority: 'high'
-    }
-  )
-
   logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION, lTags())
 
   return s3Client