Skip to content

Commit 6e99777

Browse files
committed
refactor: streamline transformation string handling in URL construction
1 parent edfb797 commit 6e99777

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/resources/helper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ export class Helper extends APIResource {
6565

6666
var transformationString = this.buildTransformationString(opts.transformation);
6767

68+
const addAsQuery = transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL;
69+
6870
if (transformationString && transformationString.length) {
69-
if (!transformationUtils.addAsQueryParameter(opts) && !isSrcParameterUsedForURL) {
71+
if (!addAsQuery) {
7072
urlObj.pathname = pathJoin([
7173
TRANSFORMATION_PARAMETER + transformationUtils.getChainTransformDelimiter() + transformationString,
7274
urlObj.pathname,
@@ -86,11 +88,9 @@ export class Helper extends APIResource {
8688
// Add transformation parameter manually to avoid URL encoding
8789
// URLSearchParams.set() would encode commas and colons in transformation string,
8890
// It would work correctly but not very readable e.g., "w-300,h-400" is better than "w-300%2Ch-400"
89-
if (transformationString && transformationString.length) {
90-
if (transformationUtils.addAsQueryParameter(opts) || isSrcParameterUsedForURL) {
91-
const separator = urlObj.searchParams.toString() ? '&' : '?';
92-
finalUrl = `${finalUrl}${separator}${TRANSFORMATION_PARAMETER}=${transformationString}`;
93-
}
91+
if (transformationString && transformationString.length && addAsQuery) {
92+
const separator = urlObj.searchParams.toString() ? '&' : '?';
93+
finalUrl = `${finalUrl}${separator}${TRANSFORMATION_PARAMETER}=${transformationString}`;
9494
}
9595

9696
// Then sign the URL if needed

0 commit comments

Comments
 (0)