Compare commits

...

1 Commits

Author SHA1 Message Date
James
b3cf0a387e fix(storage-s3): attempts to solve open socket issue 2025-03-06 10:30:13 -05:00
2 changed files with 12 additions and 5 deletions

View File

@@ -64,11 +64,11 @@ export type S3StorageOptions = {
type S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin
let storageClient: AWS.S3 | null = null
export const s3Storage: S3StoragePlugin =
(s3StorageOptions: S3StorageOptions) =>
(incomingConfig: Config): Config => {
let storageClient: AWS.S3 | null = null
const getStorageClient: () => AWS.S3 = () => {
if (storageClient) {
return storageClient

View File

@@ -28,10 +28,17 @@ const isNodeReadableStream = (body: unknown): body is Readable => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const streamToBuffer = async (readableStream: any) => {
const chunks = []
for await (const chunk of readableStream) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
try {
for await (const chunk of readableStream) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)
}
return Buffer.concat(chunks)
} finally {
// Ensure the stream is always closed
if (typeof readableStream.destroy === 'function') {
readableStream.destroy()
}
}
return Buffer.concat(chunks)
}
export const getHandler = ({ bucket, collection, getStorageClient }: Args): StaticHandler => {