Skip to content

Commit 0cae5ca

Browse files
committed
Fix file path encoding
1 parent 12e8a14 commit 0cae5ca

File tree

8 files changed

+106
-68
lines changed

8 files changed

+106
-68
lines changed

src/private/FilePathUtils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export class FilePathUtils {
2+
static encodeFilePath(filePath: string): string {
3+
// To convert a Bytescale File Path into a Bytescale File URL:
4+
// a) Call encodeURIComponent() on the file path. (This allows file paths to contain ANY character.)
5+
// b) Replace all occurrences of "%2F" with "/". (Allows file paths to appear as hierarchical paths on the URL.)
6+
// c) Replace all occurrences of "!" with "%21". (Prevents file paths with "!" inside being treated as "query bangs".)
7+
// SYNC: FileUrlUtils.makeFileUrl (internal)
8+
return encodeURIComponent(filePath).replace(/%2F/g, "/").replace(/!/g, "%21");
9+
}
10+
}

src/public/shared/UrlBuilder.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "./UrlBuilderTypes";
1010
import { BytescaleApiClientConfigUtils, encodeBytescaleQuerystringKVP } from "./generated";
1111
import { isDefinedEntry } from "../../private/TypeUtils";
12+
import { FilePathUtils } from "../../private/FilePathUtils";
1213

1314
export class UrlBuilder {
1415
/**
@@ -57,12 +58,7 @@ export class UrlBuilder {
5758

5859
private static getBaseUrl(params: UrlBuilderParams, prefix: string): string {
5960
const cdnUrl = params.options?.cdnUrl ?? BytescaleApiClientConfigUtils.defaultCdnUrl;
60-
// To convert a Bytescale File Path into a Bytescale File URL:
61-
// a) Call encodeURIComponent() on the file path. (This allows file paths to contain ANY character.)
62-
// b) Replace all occurrences of "%2F" with "/". (Allows file paths to appear as hierarchical paths on the URL.)
63-
// c) Replace all occurrences of "!" with "%21". (Prevents file paths with "!" inside being treated as "query bangs".)
64-
// SYNC: FileUrlUtils.makeFileUrl (internal)
65-
const filePathEncoded = encodeURIComponent(params.filePath).replace(/%2F/g, "/").replace(/!/g, "%21");
61+
const filePathEncoded = FilePathUtils.encodeFilePath(params.filePath);
6662
return `${cdnUrl}/${params.accountId}/${prefix}${filePathEncoded}`;
6763
}
6864

src/public/shared/generated/apis/CacheApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class CacheApi extends runtime.BaseAPI {
4848
path: `/v2/accounts/{accountId}/cache/reset`.replace(
4949
`{${"accountId"}}`,
5050
// @ts-ignore
51-
this.encodeParam("accountId", params.accountId)
51+
this.encodePathParam("accountId", params.accountId)
5252
),
5353
method: "POST",
5454
headers,

src/public/shared/generated/apis/FileApi.ts

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ export interface DownloadFileParams {
8989
*/
9090
cacheTtl404?: number;
9191

92+
/**
93+
* Expires the URL at the given Unix epoch timestamp.
94+
*
95+
* The value can be provided in either milliseconds or seconds since January 1, 1970, 00:00:00 UTC.
96+
*
97+
* Must less than 7 days in the future.
98+
*
99+
* See: Secure URLs
100+
*/
101+
exp?: number;
102+
92103
/**
93104
* Downloads the latest version of your file (if you have overwritten it) when added to the URL with a unique value.
94105
*
@@ -115,6 +126,19 @@ export interface ProcessFileParams {
115126
*/
116127
transformation: string;
117128

129+
/**
130+
* Each File Processing API requires additional query string parameters to specify the desired transformation behavior.
131+
*
132+
* For details, refer to the relevant documentation:
133+
*
134+
* - https://www.bytescale.com/docs/image-processing-api
135+
* - https://www.bytescale.com/docs/video-processing-api
136+
* - https://www.bytescale.com/docs/audio-processing-api
137+
* - https://www.bytescale.com/docs/archive-processing-api
138+
* - https://www.bytescale.com/docs/antivirus-api
139+
*/
140+
transformationParams?: TransformationParams;
141+
118142
/**
119143
* Some transformations output multiple files, called artifacts.
120144
*
@@ -127,7 +151,7 @@ export interface ProcessFileParams {
127151
*
128152
* If set to `false` the transformation will be executed on every request.
129153
*
130-
* *Recommendation:* instead of disabling the cache, a more performant solution is to use the `version` parameter and to increment it each time you require an updated result.
154+
* *Recommendation:* instead of disabling the cache, a more performant solution is to use the `version` or `v` parameter and to increment it each time you require an updated result.
131155
*
132156
* Default: true
133157
*/
@@ -151,7 +175,7 @@ export interface ProcessFileParams {
151175
*
152176
* When `cache=false` this parameter is automatically set to `false`.
153177
*
154-
* When `cache_perm=auto` the perma-cache will only be used for files that take more than 1000ms to process.
178+
* When `cache-perm=auto` the perma-cache will only be used for files that take more than 500ms to process.
155179
*
156180
* When the perma-cache is used, approximately 200ms of latency is added to the initial request. Thereafter, files will be served from the Bytescale CDN's edge cache or perma-cache, so will have minimal latency.
157181
*
@@ -166,7 +190,7 @@ export interface ProcessFileParams {
166190
*
167191
* If the file is not perma-cached, then the file will be reprocessed on edge cache misses.
168192
*
169-
* For more information on perma-caching, see: `cache_perm`
193+
* For more information on perma-caching, see: `cache-perm`
170194
*
171195
* Default: Please refer to your account's default cache settings in the Bytescale Dashboard.
172196
*/
@@ -180,16 +204,15 @@ export interface ProcessFileParams {
180204
cacheTtl404?: number;
181205

182206
/**
183-
* Parameters to submit to the File Processing API (e.g. the Image Processing API).
207+
* Expires the URL at the given Unix epoch timestamp.
184208
*
185-
* Please see the documentation for each File Processing API to determine which values can appear here:
209+
* The value can be provided in either milliseconds or seconds since January 1, 1970, 00:00:00 UTC.
186210
*
187-
* - https://www.bytescale.com/docs/image-processing-api
188-
* - https://www.bytescale.com/docs/video-processing-api
189-
* - https://www.bytescale.com/docs/audio-processing-api
190-
* - https://www.bytescale.com/docs/archive-processing-api
211+
* Must less than 7 days in the future.
212+
*
213+
* See: Secure URLs
191214
*/
192-
transformationParams?: TransformationParams;
215+
exp?: number;
193216

194217
/**
195218
* Add this parameter and increment its value to force the file to be reprocessed.
@@ -219,14 +242,15 @@ export interface ProcessFileAndSaveOperationParams {
219242
processFileAndSaveRequest: ProcessFileAndSaveRequest;
220243

221244
/**
222-
* Parameters to submit to the File Processing API (e.g. the Image Processing API).
245+
* Each File Processing API requires additional query string parameters to specify the desired transformation behavior.
223246
*
224-
* Please see the documentation for each File Processing API to determine which values can appear here:
247+
* For details, refer to the relevant documentation:
225248
*
226249
* - https://www.bytescale.com/docs/image-processing-api
227250
* - https://www.bytescale.com/docs/video-processing-api
228251
* - https://www.bytescale.com/docs/audio-processing-api
229252
* - https://www.bytescale.com/docs/archive-processing-api
253+
* - https://www.bytescale.com/docs/antivirus-api
230254
*/
231255
transformationParams?: TransformationParams;
232256
}
@@ -246,7 +270,7 @@ export class FileApi extends runtime.BaseAPI {
246270
path: `/v2/accounts/{accountId}/files/copy`.replace(
247271
`{${"accountId"}}`,
248272
// @ts-ignore
249-
this.encodeParam("accountId", params.accountId)
273+
this.encodePathParam("accountId", params.accountId)
250274
),
251275
method: "POST",
252276
headers,
@@ -274,7 +298,7 @@ export class FileApi extends runtime.BaseAPI {
274298
path: `/v2/accounts/{accountId}/files/copy/batch`.replace(
275299
`{${"accountId"}}`,
276300
// @ts-ignore
277-
this.encodeParam("accountId", params.accountId)
301+
this.encodePathParam("accountId", params.accountId)
278302
),
279303
method: "POST",
280304
headers,
@@ -304,7 +328,7 @@ export class FileApi extends runtime.BaseAPI {
304328
path: `/v2/accounts/{accountId}/files`.replace(
305329
`{${"accountId"}}`,
306330
// @ts-ignore
307-
this.encodeParam("accountId", params.accountId)
331+
this.encodePathParam("accountId", params.accountId)
308332
),
309333
method: "DELETE",
310334
headers,
@@ -331,7 +355,7 @@ export class FileApi extends runtime.BaseAPI {
331355
path: `/v2/accounts/{accountId}/files/batch`.replace(
332356
`{${"accountId"}}`,
333357
// @ts-ignore
334-
this.encodeParam("accountId", params.accountId)
358+
this.encodePathParam("accountId", params.accountId)
335359
),
336360
method: "DELETE",
337361
headers,
@@ -355,11 +379,15 @@ export class FileApi extends runtime.BaseAPI {
355379
}
356380

357381
if (params.cacheTtl !== undefined) {
358-
query["cache_ttl"] = params.cacheTtl;
382+
query["cache-ttl"] = params.cacheTtl;
359383
}
360384

361385
if (params.cacheTtl404 !== undefined) {
362-
query["cache_ttl_404"] = params.cacheTtl404;
386+
query["cache-ttl-404"] = params.cacheTtl404;
387+
}
388+
389+
if (params.exp !== undefined) {
390+
query["exp"] = params.exp;
363391
}
364392

365393
if (params.version !== undefined) {
@@ -374,12 +402,12 @@ export class FileApi extends runtime.BaseAPI {
374402
.replace(
375403
`{${"accountId"}}`,
376404
// @ts-ignore
377-
this.encodeParam("accountId", params.accountId)
405+
this.encodePathParam("accountId", params.accountId)
378406
)
379407
.replace(
380408
`{${"filePath"}}`,
381409
// @ts-ignore
382-
this.encodeParam("filePath", params.filePath)
410+
this.encodePathParam("filePath", params.filePath)
383411
),
384412
method: "GET",
385413
headers,
@@ -408,7 +436,7 @@ export class FileApi extends runtime.BaseAPI {
408436
path: `/v2/accounts/{accountId}/files/details`.replace(
409437
`{${"accountId"}}`,
410438
// @ts-ignore
411-
this.encodeParam("accountId", params.accountId)
439+
this.encodePathParam("accountId", params.accountId)
412440
),
413441
method: "GET",
414442
headers,
@@ -426,6 +454,10 @@ export class FileApi extends runtime.BaseAPI {
426454
*/
427455
async processFile(params: ProcessFileParams): Promise<runtime.BinaryResult> {
428456
const query: any = {};
457+
if (params.transformationParams !== undefined) {
458+
query["&lt;transformation-params&gt;"] = params.transformationParams;
459+
}
460+
429461
if (params.artifact !== undefined) {
430462
query["artifact"] = params.artifact;
431463
}
@@ -435,23 +467,23 @@ export class FileApi extends runtime.BaseAPI {
435467
}
436468

437469
if (params.cacheOnly !== undefined) {
438-
query["cache_only"] = params.cacheOnly;
470+
query["cache-only"] = params.cacheOnly;
439471
}
440472

441473
if (params.cachePerm !== undefined) {
442-
query["cache_perm"] = params.cachePerm;
474+
query["cache-perm"] = params.cachePerm;
443475
}
444476

445477
if (params.cacheTtl !== undefined) {
446-
query["cache_ttl"] = params.cacheTtl;
478+
query["cache-ttl"] = params.cacheTtl;
447479
}
448480

449481
if (params.cacheTtl404 !== undefined) {
450-
query["cache_ttl_404"] = params.cacheTtl404;
482+
query["cache-ttl-404"] = params.cacheTtl404;
451483
}
452484

453-
if (params.transformationParams !== undefined) {
454-
query["transformationParams"] = params.transformationParams;
485+
if (params.exp !== undefined) {
486+
query["exp"] = params.exp;
455487
}
456488

457489
if (params.version !== undefined) {
@@ -466,17 +498,17 @@ export class FileApi extends runtime.BaseAPI {
466498
.replace(
467499
`{${"accountId"}}`,
468500
// @ts-ignore
469-
this.encodeParam("accountId", params.accountId)
501+
this.encodePathParam("accountId", params.accountId)
470502
)
471503
.replace(
472504
`{${"filePath"}}`,
473505
// @ts-ignore
474-
this.encodeParam("filePath", params.filePath)
506+
this.encodePathParam("filePath", params.filePath)
475507
)
476508
.replace(
477509
`{${"transformation"}}`,
478510
// @ts-ignore
479-
this.encodeParam("transformation", params.transformation)
511+
this.encodePathParam("transformation", params.transformation)
480512
),
481513
method: "GET",
482514
headers,
@@ -495,7 +527,7 @@ export class FileApi extends runtime.BaseAPI {
495527
async processFileAndSave(params: ProcessFileAndSaveOperationParams): Promise<ProcessFileAndSaveResponse> {
496528
const query: any = {};
497529
if (params.transformationParams !== undefined) {
498-
query["transformationParams"] = params.transformationParams;
530+
query["&lt;transformation-params&gt;"] = params.transformationParams;
499531
}
500532

501533
const headers: runtime.HTTPHeaders = {};
@@ -508,17 +540,17 @@ export class FileApi extends runtime.BaseAPI {
508540
.replace(
509541
`{${"accountId"}}`,
510542
// @ts-ignore
511-
this.encodeParam("accountId", params.accountId)
543+
this.encodePathParam("accountId", params.accountId)
512544
)
513545
.replace(
514546
`{${"filePath"}}`,
515547
// @ts-ignore
516-
this.encodeParam("filePath", params.filePath)
548+
this.encodePathParam("filePath", params.filePath)
517549
)
518550
.replace(
519551
`{${"transformation"}}`,
520552
// @ts-ignore
521-
this.encodeParam("transformation", params.transformation)
553+
this.encodePathParam("transformation", params.transformation)
522554
),
523555
method: "POST",
524556
headers,

src/public/shared/generated/apis/FolderApi.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class FolderApi extends runtime.BaseAPI {
112112
path: `/v2/accounts/{accountId}/folders/copy`.replace(
113113
`{${"accountId"}}`,
114114
// @ts-ignore
115-
this.encodeParam("accountId", params.accountId)
115+
this.encodePathParam("accountId", params.accountId)
116116
),
117117
method: "POST",
118118
headers,
@@ -140,7 +140,7 @@ export class FolderApi extends runtime.BaseAPI {
140140
path: `/v2/accounts/{accountId}/folders/copy/batch`.replace(
141141
`{${"accountId"}}`,
142142
// @ts-ignore
143-
this.encodeParam("accountId", params.accountId)
143+
this.encodePathParam("accountId", params.accountId)
144144
),
145145
method: "POST",
146146
headers,
@@ -168,7 +168,7 @@ export class FolderApi extends runtime.BaseAPI {
168168
path: `/v2/accounts/{accountId}/folders`.replace(
169169
`{${"accountId"}}`,
170170
// @ts-ignore
171-
this.encodeParam("accountId", params.accountId)
171+
this.encodePathParam("accountId", params.accountId)
172172
),
173173
method: "DELETE",
174174
headers,
@@ -196,7 +196,7 @@ export class FolderApi extends runtime.BaseAPI {
196196
path: `/v2/accounts/{accountId}/folders/batch`.replace(
197197
`{${"accountId"}}`,
198198
// @ts-ignore
199-
this.encodeParam("accountId", params.accountId)
199+
this.encodePathParam("accountId", params.accountId)
200200
),
201201
method: "DELETE",
202202
headers,
@@ -226,7 +226,7 @@ export class FolderApi extends runtime.BaseAPI {
226226
path: `/v2/accounts/{accountId}/folders`.replace(
227227
`{${"accountId"}}`,
228228
// @ts-ignore
229-
this.encodeParam("accountId", params.accountId)
229+
this.encodePathParam("accountId", params.accountId)
230230
),
231231
method: "GET",
232232
headers,
@@ -287,7 +287,7 @@ export class FolderApi extends runtime.BaseAPI {
287287
path: `/v2/accounts/{accountId}/folders/list`.replace(
288288
`{${"accountId"}}`,
289289
// @ts-ignore
290-
this.encodeParam("accountId", params.accountId)
290+
this.encodePathParam("accountId", params.accountId)
291291
),
292292
method: "GET",
293293
headers,
@@ -314,7 +314,7 @@ export class FolderApi extends runtime.BaseAPI {
314314
path: `/v2/accounts/{accountId}/folders`.replace(
315315
`{${"accountId"}}`,
316316
// @ts-ignore
317-
this.encodeParam("accountId", params.accountId)
317+
this.encodePathParam("accountId", params.accountId)
318318
),
319319
method: "PUT",
320320
headers,

0 commit comments

Comments
 (0)