update comments , update type casing and update examples based on feedback

This commit is contained in:
prakash 2026-06-20 01:56:45 +05:30
parent 5585a796af
commit 9f88450929
No known key found for this signature in database
6 changed files with 10 additions and 12 deletions

View file

@ -24,8 +24,8 @@ app.get('/', (req, res) => {
if (err) return res.status(500).send('Error loading page')
// Inject bucket/region config so the client can read them.
const config = `<script>
window.UPPY_S3_BUCKET = "${process.env.COMPANION_AWS_BUCKET}";
window.UPPY_S3_REGION = "${process.env.COMPANION_AWS_REGION}";
window.UPPY_S3_BUCKET = ${JSON.stringify(process.env.COMPANION_AWS_BUCKET)};
window.UPPY_S3_REGION = ${JSON.stringify(process.env.COMPANION_AWS_REGION)};
</script>`
res.setHeader('Content-Type', 'text/html')
res.send(html.replace('</head>', `${config}</head>`))

View file

@ -90,8 +90,6 @@
height: 400,
})
.use(AwsS3, {
bucket: window.UPPY_S3_BUCKET,
region: window.UPPY_S3_REGION,
signRequest: async (request) => {
const response = await fetch('/s3/presign', {
method: 'POST',

View file

@ -92,7 +92,7 @@ class S3mini extends S3Client {
private _createCredentialBasedSigner(): IT.SignRequestFn {
return async (
request: IT.PresignableRequest,
): Promise<IT.presignedResponse> => {
): Promise<IT.PresignedResponse> => {
const creds = await this._getCachedCredentials()
if (this.endpoint == null) {
throw new Error('Endpoint is required for credential-based signing')

View file

@ -1,4 +1,4 @@
// Export the S3 class as default export and named export
// Public exports for the S3 client.
export { S3mini } from './S3mini.js'
// Re-export types
export type {

View file

@ -5,7 +5,7 @@
*/
import * as C from './consts.js'
import type { PresignableRequest, presignedResponse } from './types.js'
import type { PresignableRequest, PresignedResponse } from './types.js'
import * as U from './utils.js'
export interface SignerConfig {
@ -46,7 +46,7 @@ export function createSigV4Presigner(config: SignerConfig) {
return async function presign(
request: PresignableRequest,
): Promise<presignedResponse> {
): Promise<PresignedResponse> {
const { method, key, expiresIn = DEFAULT_EXPIRES_IN } = request
// Build the URL - need to track encoded path separately because URL object decodes it

View file

@ -41,14 +41,14 @@ export type PresignableRequest =
| UploadPartRequest
/** Response with the pre-signed URL */
export type presignedResponse = {
export type PresignedResponse = {
url: string
}
/** Function that generates a pre-signed URL for a request */
export type SignRequestFn = (
request: PresignableRequest,
) => Promise<presignedResponse>
) => Promise<PresignedResponse>
/**
* Temporary security credentials from STS or similar service.
@ -92,11 +92,11 @@ type S3ConfigWithSignRequest = S3ConfigBase & {
signRequest: SignRequestFn
}
/** Config when using getCredentials callback (region required for signing) */
/** Config for the getCredentials callback (region optional). */
type S3ConfigWithGetCredentials = Omit<S3ConfigBase, 'region'> & {
/** Function to retrieve temporary credentials for client-side signing. */
getCredentials: GetCredentialsFn
/** AWS region. Required for signing with getCredentials. */
/** AWS region. Optional; falls back to the getCredentials response or 'auto'. */
region?: string
/** Endpoint URL of the S3-compatible service (e.g., 'https://s3.amazonaws.com/bucket-name') */
endpoint: string