mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
improve Request type
and fix contentType (wasn't being used)
This commit is contained in:
parent
260408fcd5
commit
260408a87f
3 changed files with 47 additions and 20 deletions
|
|
@ -213,7 +213,8 @@ class S3mini {
|
|||
throw new TypeError(`${C.ERROR_PREFIX}fileType must be a string`)
|
||||
}
|
||||
const { response } = await this.request({
|
||||
request: { method: 'POST', key, contentType: fileType },
|
||||
request: { method: 'POST', key },
|
||||
contentType: fileType,
|
||||
})
|
||||
|
||||
const parsed = U.parseXml(response) as Record<string, unknown>
|
||||
|
|
@ -477,9 +478,9 @@ class S3mini {
|
|||
request: {
|
||||
method: 'POST',
|
||||
key,
|
||||
contentType: C.XML_CONTENT_TYPE,
|
||||
uploadId,
|
||||
},
|
||||
contentType: C.XML_CONTENT_TYPE,
|
||||
data: xmlBody,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -47,13 +47,7 @@ export function createSigV4Presigner(config: SignerConfig) {
|
|||
return async function presign(
|
||||
request: PresignableRequest,
|
||||
): Promise<presignedResponse> {
|
||||
const {
|
||||
method,
|
||||
key,
|
||||
uploadId,
|
||||
partNumber,
|
||||
expiresIn = DEFAULT_EXPIRES_IN,
|
||||
} = request
|
||||
const { method, key, expiresIn = DEFAULT_EXPIRES_IN } = request
|
||||
|
||||
// Build the URL - need to track encoded path separately because URL object decodes it
|
||||
const url = new URL(endpoint)
|
||||
|
|
@ -92,15 +86,15 @@ export function createSigV4Presigner(config: SignerConfig) {
|
|||
}
|
||||
|
||||
// Add multipart-specific params
|
||||
if (uploadId) {
|
||||
url.searchParams.set('uploadId', uploadId)
|
||||
if ('uploadId' in request) {
|
||||
url.searchParams.set('uploadId', request.uploadId)
|
||||
}
|
||||
if (partNumber !== undefined) {
|
||||
url.searchParams.set('partNumber', String(partNumber))
|
||||
if ('partNumber' in request) {
|
||||
url.searchParams.set('partNumber', String(request.partNumber))
|
||||
}
|
||||
|
||||
// For CreateMultipartUpload, add uploads param
|
||||
if (method === 'POST' && !uploadId) {
|
||||
if (method === 'POST' && !('uploadId' in request)) {
|
||||
url.searchParams.set('uploads', '')
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,45 @@
|
|||
/** Request data to be pre-signed */
|
||||
export type PresignableRequest = {
|
||||
method: HttpMethod
|
||||
export interface PresignableRequestBase {
|
||||
key: string
|
||||
uploadId?: string
|
||||
partNumber?: number
|
||||
expiresIn?: number
|
||||
contentType?: string
|
||||
}
|
||||
|
||||
export interface PutObjectRequest extends PresignableRequestBase {
|
||||
method: 'PUT'
|
||||
}
|
||||
export interface DeleteObjectRequest extends PresignableRequestBase {
|
||||
method: 'DELETE'
|
||||
}
|
||||
export interface CreateMultipartUploadRequest extends PresignableRequestBase {
|
||||
method: 'POST'
|
||||
}
|
||||
export interface CompleteMultipartUploadRequest extends PresignableRequestBase {
|
||||
method: 'POST'
|
||||
uploadId: string
|
||||
}
|
||||
export interface DeleteMultipartUploadRequest extends PresignableRequestBase {
|
||||
method: 'DELETE'
|
||||
uploadId: string
|
||||
}
|
||||
export interface ListPartsRequest extends PresignableRequestBase {
|
||||
method: 'GET'
|
||||
uploadId: string
|
||||
}
|
||||
export interface UploadPartRequest extends PresignableRequestBase {
|
||||
method: 'PUT'
|
||||
uploadId: string
|
||||
partNumber: number
|
||||
}
|
||||
|
||||
/** Request data to be pre-signed */
|
||||
export type PresignableRequest =
|
||||
| PutObjectRequest
|
||||
| DeleteObjectRequest
|
||||
| CreateMultipartUploadRequest
|
||||
| CompleteMultipartUploadRequest
|
||||
| DeleteMultipartUploadRequest
|
||||
| ListPartsRequest
|
||||
| UploadPartRequest
|
||||
|
||||
/** Response with the pre-signed URL */
|
||||
export type presignedResponse = {
|
||||
url: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue