Skip to content

Commit dfe9722

Browse files
author
Marius Kleidl
committed
Allow duplicate parameters
1 parent 900fbdc commit dfe9722

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/Transloadit.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,22 @@ export class Transloadit {
639639
const inputField = encodeURIComponent(opts.input)
640640
const expiresIn = opts.expiresIn || 60 * 60 * 1000 // 1 hour
641641

642-
// Convert urlParams to Record<string, string>
643-
const stringifiedParams: Record<string, string> = {}
642+
const queryParams = new URLSearchParams()
644643
for (const [key, value] of Object.entries(opts.urlParams || {})) {
645-
stringifiedParams[key] = `${value}`
644+
if (Array.isArray(value)) {
645+
for (const val of value) {
646+
queryParams.append(key, `${val}`)
647+
}
648+
} else {
649+
queryParams.append(key, `${value}`)
650+
}
646651
}
647652

648-
const queryParams = new URLSearchParams(stringifiedParams)
649653
queryParams.set('auth_key', this._authKey)
650654
queryParams.set('exp', `${Date.now() + expiresIn}`)
651-
// The signature changes depending on the order of the query parameters. We therefore sort them on the client- and server-side to ensure that we do not get mismatching signatures if a proxy changes the order of query parameters or implementations handle query parameters ordering differently.
655+
// The signature changes depending on the order of the query parameters. We therefore sort them on the client-
656+
// and server-side to ensure that we do not get mismatching signatures if a proxy changes the order of query
657+
// parameters or implementations handle query parameters ordering differently.
652658
queryParams.sort()
653659

654660
const stringToSign = `${workspaceSlug}/${templateSlug}/${inputField}?${queryParams}`
@@ -1011,7 +1017,7 @@ export interface SmartCDNUrlOptions {
10111017
/**
10121018
* Additional parameters for the URL query string
10131019
*/
1014-
urlParams?: Record<string, boolean | number | string>
1020+
urlParams?: Record<string, boolean | number | string | (boolean | number | string)[]>
10151021
/**
10161022
* Expiration time of the signature in milliseconds. Defaults to 1 hour.
10171023
*/

test/unit/test-transloadit-client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ describe('Transloadit', () => {
363363
input: 'foo/input',
364364
urlParams: {
365365
foo: 'bar',
366-
aaa: 42, // Should be sorted as first param
366+
aaa: [42, 21], // Should be sorted before `foo`.
367367
},
368368
})
369369

370370
expect(url).toBe(
371-
'https://foo_workspace.tlcdn.com/foo_template/foo%2Finput?aaa=42&auth_key=foo_key&exp=1714525200000&foo=bar&sig=sha256:995dd1aae135fb77fa98b0e6946bd9768e0443a6028eba0361c03807e8fb68a5'
371+
'https://foo_workspace.tlcdn.com/foo_template/foo%2Finput?aaa=42&aaa=21&auth_key=foo_key&exp=1714525200000&foo=bar&sig=sha256%3A9a8df3bb28eea621b46ec808a250b7903b2546be7e66c048956d4f30b8da7519'
372372
)
373373
})
374374
})

0 commit comments

Comments
 (0)