Skip to content

Commit 1cb4d5d

Browse files
feat: Support getting file download URL and file thumbnail URL (box/box-codegen#617) (#435)
1 parent fa1ff3b commit 1cb4d5d

File tree

137 files changed

+2010
-1494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+2010
-1494
lines changed

.codegen.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "d435f50", "specHash": "544d370", "version": "1.7.0" }
1+
{ "engineHash": "f073ce3", "specHash": "544d370", "version": "1.7.0" }

docs/downloads.md

+25-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ Downloads module is used to download files from Box.
55
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
66
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
77

8-
- [Download a File](#download-a-file)
8+
- [Downloads](#downloads)
9+
- [Download a File](#download-a-file)
10+
- [Get download URL](#get-download-url)
11+
- [Arguments](#arguments)
12+
- [Returns](#returns)
913

1014
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1115

@@ -23,3 +27,23 @@ const fileContent = await client.downloads.downloadFile('123456789');
2327
const fileWriteStream = fs.createWriteStream('file.pdf');
2428
fileContent.pipe(fileWriteStream);
2529
```
30+
31+
## Get download URL
32+
33+
Get a URL to download a file
34+
35+
This operation is performed by calling function `getDownloadFileUrl`.
36+
37+
```ts
38+
await client.downloads.getDownloadFileUrl(uploadedFile.id);
39+
```
40+
41+
### Arguments
42+
43+
- fileId `string`
44+
- The unique identifier that represents a file. The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the `file_id` is `123`. Example: "12345"
45+
- ## optionalsInput `GetDownloadFileUrlOptionalsInput`
46+
47+
### Returns
48+
49+
This function returns a value of type `string`.

docs/files.md

+42
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- [Update file](#update-file)
55
- [Delete file](#delete-file)
66
- [Copy file](#copy-file)
7+
- [Get file thumbnail URL](#get-file-thumbnail-url)
78
- [Get file thumbnail](#get-file-thumbnail)
89

910
## Get file information
@@ -147,6 +148,47 @@ Not all available fields are returned by default. Use the
147148
[fields](#param-fields) query parameter to explicitly request
148149
any specific fields.
149150

151+
## Get file thumbnail URL
152+
153+
Get the download URL without downloading the content.
154+
155+
This operation is performed by calling function `getFileThumbnailUrl`.
156+
157+
See the endpoint docs at
158+
[API Reference](https://developer.box.com/reference/get-files-id-thumbnail-id/).
159+
160+
<!-- sample get_files_id_thumbnail_id -->
161+
162+
```ts
163+
await client.files.getFileThumbnailUrl(
164+
thumbnailFile.id,
165+
'png' as GetFileThumbnailUrlExtension,
166+
);
167+
```
168+
169+
### Arguments
170+
171+
- fileId `string`
172+
- The unique identifier that represents a file. The ID for any file can be determined by visiting a file in the web application and copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the `file_id` is `123`. Example: "12345"
173+
- extension `GetFileThumbnailUrlExtension`
174+
- The file format for the thumbnail Example: "png"
175+
- optionalsInput `GetFileThumbnailUrlOptionalsInput`
176+
-
177+
178+
### Returns
179+
180+
This function returns a value of type `string`.
181+
182+
When a thumbnail can be created the thumbnail data will be
183+
returned in the body of the response.Sometimes generating a thumbnail can take a few seconds. In these
184+
situations the API returns a `Location`-header pointing to a
185+
placeholder graphic for this file type.
186+
187+
The placeholder graphic can be used in a user interface until the
188+
thumbnail generation has completed. The `Retry-After`-header indicates
189+
when to the thumbnail will be ready. At that time, retry this endpoint
190+
to retrieve the thumbnail.
191+
150192
## Get file thumbnail
151193

152194
Retrieves a thumbnail, or smaller image representation, of a file.

src/box/ccgAuth.generated.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ export class CcgConfig {
3030
fields: Omit<CcgConfig, 'tokenStorage'> &
3131
Partial<Pick<CcgConfig, 'tokenStorage'>>,
3232
) {
33-
if (fields.clientId) {
33+
if (fields.clientId !== undefined) {
3434
this.clientId = fields.clientId;
3535
}
36-
if (fields.clientSecret) {
36+
if (fields.clientSecret !== undefined) {
3737
this.clientSecret = fields.clientSecret;
3838
}
39-
if (fields.enterpriseId) {
39+
if (fields.enterpriseId !== undefined) {
4040
this.enterpriseId = fields.enterpriseId;
4141
}
42-
if (fields.userId) {
42+
if (fields.userId !== undefined) {
4343
this.userId = fields.userId;
4444
}
45-
if (fields.tokenStorage) {
45+
if (fields.tokenStorage !== undefined) {
4646
this.tokenStorage = fields.tokenStorage;
4747
}
4848
}
@@ -92,7 +92,7 @@ export class BoxCcgAuth implements Authentication {
9292
| 'revokeToken'
9393
>,
9494
) {
95-
if (fields.config) {
95+
if (fields.config !== undefined) {
9696
this.config = fields.config;
9797
}
9898
this.tokenStorage = this.config.tokenStorage;

src/box/developerTokenAuth.generated.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ export class BoxDeveloperTokenAuth implements Authentication {
3434
> &
3535
Partial<Pick<BoxDeveloperTokenAuth, 'config'>>,
3636
) {
37-
if (fields.token) {
37+
if (fields.token !== undefined) {
3838
this.token = fields.token;
3939
}
40-
if (fields.config) {
40+
if (fields.config !== undefined) {
4141
this.config = fields.config;
4242
}
4343
this.tokenStorage = new InMemoryTokenStorage({

src/box/jwtAuth.generated.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,31 @@ export class JwtConfig {
9292
> &
9393
Partial<Pick<JwtConfig, 'algorithm' | 'tokenStorage'>>,
9494
) {
95-
if (fields.clientId) {
95+
if (fields.clientId !== undefined) {
9696
this.clientId = fields.clientId;
9797
}
98-
if (fields.clientSecret) {
98+
if (fields.clientSecret !== undefined) {
9999
this.clientSecret = fields.clientSecret;
100100
}
101-
if (fields.jwtKeyId) {
101+
if (fields.jwtKeyId !== undefined) {
102102
this.jwtKeyId = fields.jwtKeyId;
103103
}
104-
if (fields.privateKey) {
104+
if (fields.privateKey !== undefined) {
105105
this.privateKey = fields.privateKey;
106106
}
107-
if (fields.privateKeyPassphrase) {
107+
if (fields.privateKeyPassphrase !== undefined) {
108108
this.privateKeyPassphrase = fields.privateKeyPassphrase;
109109
}
110-
if (fields.enterpriseId) {
110+
if (fields.enterpriseId !== undefined) {
111111
this.enterpriseId = fields.enterpriseId;
112112
}
113-
if (fields.userId) {
113+
if (fields.userId !== undefined) {
114114
this.userId = fields.userId;
115115
}
116-
if (fields.algorithm) {
116+
if (fields.algorithm !== undefined) {
117117
this.algorithm = fields.algorithm;
118118
}
119-
if (fields.tokenStorage) {
119+
if (fields.tokenStorage !== undefined) {
120120
this.tokenStorage = fields.tokenStorage;
121121
}
122122
}
@@ -225,7 +225,7 @@ export class BoxJwtAuth implements Authentication {
225225
| 'revokeToken'
226226
>,
227227
) {
228-
if (fields.config) {
228+
if (fields.config !== undefined) {
229229
this.config = fields.config;
230230
}
231231
this.tokenStorage = this.config.tokenStorage;

src/box/oauth.generated.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ export class OAuthConfig {
2020
fields: Omit<OAuthConfig, 'tokenStorage'> &
2121
Partial<Pick<OAuthConfig, 'tokenStorage'>>,
2222
) {
23-
if (fields.clientId) {
23+
if (fields.clientId !== undefined) {
2424
this.clientId = fields.clientId;
2525
}
26-
if (fields.clientSecret) {
26+
if (fields.clientSecret !== undefined) {
2727
this.clientSecret = fields.clientSecret;
2828
}
29-
if (fields.tokenStorage) {
29+
if (fields.tokenStorage !== undefined) {
3030
this.tokenStorage = fields.tokenStorage;
3131
}
3232
}
@@ -73,7 +73,7 @@ export class BoxOAuth implements Authentication {
7373
| 'downscopeToken'
7474
>,
7575
) {
76-
if (fields.config) {
76+
if (fields.config !== undefined) {
7777
this.config = fields.config;
7878
}
7979
this.tokenStorage = this.config.tokenStorage;

src/box/tokenStorage.generated.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class InMemoryTokenStorage implements TokenStorage {
2020
fields: Omit<InMemoryTokenStorage, 'token' | 'store' | 'get' | 'clear'> &
2121
Partial<Pick<InMemoryTokenStorage, 'token'>>,
2222
) {
23-
if (fields.token) {
23+
if (fields.token !== undefined) {
2424
this.token = fields.token;
2525
}
2626
}

src/client.generated.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ export class BoxClient {
248248
> &
249249
Partial<Pick<BoxClient, 'networkSession'>>,
250250
) {
251-
if (fields.auth) {
251+
if (fields.auth !== undefined) {
252252
this.auth = fields.auth;
253253
}
254-
if (fields.networkSession) {
254+
if (fields.networkSession !== undefined) {
255255
this.networkSession = fields.networkSession;
256256
}
257257
this.authorization = new AuthorizationManager({
@@ -562,6 +562,7 @@ export class BoxClient {
562562
auth: fetchOptionsInput.auth,
563563
networkSession: fetchOptionsInput.networkSession,
564564
cancellationToken: fetchOptionsInput.cancellationToken,
565+
followRedirects: fetchOptionsInput.followRedirects,
565566
});
566567
const auth: Authentication =
567568
fetchOptions.auth == void 0 ? this.auth : fetchOptions.auth!;
@@ -581,6 +582,7 @@ export class BoxClient {
581582
multipartData: fetchOptions.multipartData,
582583
contentType: fetchOptions.contentType,
583584
responseFormat: fetchOptions.responseFormat,
585+
followRedirects: fetchOptions.followRedirects,
584586
});
585587
return (await fetch(enrichedFetchOptions)) as FetchResponse;
586588
}

src/internal/utils.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Buffer } from 'buffer';
22
import type { Readable } from 'stream';
33
import { v4 as uuidv4 } from 'uuid';
44
import { SignJWT, importPKCS8 } from 'jose';
5-
import { sdIsMap, SerializedData } from '../serialization/json';
65

76
export function isBrowser() {
87
return (
@@ -23,7 +22,7 @@ export function hexToBase64(data: string): string {
2322
}
2423

2524
export { Buffer, Readable as ByteStream };
26-
export type { CancellationToken };
25+
export type { CancellationController, CancellationToken };
2726
export type Iterator<T = any> = AsyncIterator<T>;
2827
export type AgentOptions = any;
2928
export type Agent = any;
@@ -293,6 +292,7 @@ export function toString(value: any): string {
293292
return String(value);
294293
}
295294

295+
type CancellationController = AbortController;
296296
type CancellationToken = AbortSignal;
297297

298298
/**
@@ -446,3 +446,10 @@ export function getValueFromObjectRawData(obj: any, key: string): any {
446446
export function createNull(): null {
447447
return null;
448448
}
449+
450+
/**
451+
* Create a cancellation controller.
452+
*/
453+
export function createCancellationController(): CancellationController {
454+
return new AbortController();
455+
}

0 commit comments

Comments
 (0)