fix: s3 upload compatibility (#14445)

fix #14432 

#### PR Dependency Tree


* **PR #14445** 👈

This tree was auto-generated by
[Charcoal](https://github.com/danerwilliams/charcoal)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Improved file upload handling to ensure consistent support for
different data formats during object and multipart uploads.
* Enhanced type safety throughout storage and workflow components by
removing unnecessary type assertions.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2026-02-15 19:16:36 +08:00
committed by GitHub
parent 9a1f600fc9
commit 9d7f4acaf1
3 changed files with 15 additions and 4 deletions

View File

@@ -175,7 +175,7 @@ export class R2StorageProvider extends S3StorageProvider {
body: Readable | Buffer | Uint8Array | string,
options: { contentType?: string; contentLength?: number } = {}
) {
return this.client.putObject(key, body as any, {
return this.client.putObject(key, this.normalizeBody(body), {
contentType: options.contentType,
contentLength: options.contentLength,
});
@@ -192,13 +192,24 @@ export class R2StorageProvider extends S3StorageProvider {
key,
uploadId,
partNumber,
body as any,
this.normalizeBody(body),
{ contentLength: options.contentLength }
);
return result.etag;
}
private normalizeBody(body: Readable | Buffer | Uint8Array | string) {
// s3mini does not accept Node.js Readable directly.
// Convert it to Web ReadableStream for compatibility.
if (body instanceof Readable) {
return Readable.toWeb(body);
} else if (typeof body === 'string') {
return this.encoder.encode(body);
}
return body;
}
override async get(
key: string,
signedUrl?: boolean

View File

@@ -281,7 +281,7 @@ export class S3StorageProvider implements StorageProvider {
this.logger.verbose(`Read object \`${key}\``);
return {
body: Readable.fromWeb(obj.body as any),
body: Readable.fromWeb(obj.body),
metadata: {
contentType: contentType ?? 'application/octet-stream',
contentLength: contentLength ?? 0,

View File

@@ -560,7 +560,7 @@ export class CopilotController implements BeforeApplicationShutdown {
status: data.status,
id: data.node.id,
type: data.node.config.nodeType,
} as any,
},
};
}
})