Skip to content

Commit 7857f26

Browse files
committed
Update files.upload.v2 internals due to server-side improvements
1 parent 89b109d commit 7857f26

File tree

4 files changed

+61
-28
lines changed

4 files changed

+61
-28
lines changed

packages/web-api/src/WebClient.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,8 @@ describe('WebClient', function () {
15401540
}]
15411541
});
15421542

1543-
it('is called when request_file_info is true or undefined', async () => {
1543+
// since v7, the behavior has been changed
1544+
it('is not called when request_file_info is true or undefined', async () => {
15441545
client.getFileInfo = sinon.spy();
15451546
// set initial files upload arguments with request_file_info true
15461547
const withRequestFileInfoTrue = {
@@ -1549,14 +1550,16 @@ describe('WebClient', function () {
15491550
request_file_info: true,
15501551
};
15511552
await client.filesUploadV2(withRequestFileInfoTrue);
1552-
assert.equal(client.getFileInfo.called, true);
1553+
// since v7, the behavior has been changed
1554+
assert.equal(client.getFileInfo.called, false);
15531555

15541556
const withRequestFileInfoOmitted = {
15551557
file: Buffer.from('test'),
15561558
filename: 'test.txt',
15571559
}
15581560
await client.filesUploadV2(withRequestFileInfoOmitted);
1559-
assert.equal(client.getFileInfo.calledTwice, true);
1561+
// since v7, the behavior has been changed
1562+
assert.equal(client.getFileInfo.calledTwice, false);
15601563
});
15611564
it('is not called when request_file_info is set as false', async () => {
15621565
client.getFileInfo = sinon.spy();

packages/web-api/src/WebClient.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ export class WebClient extends Methods {
408408
*
409409
* **#3**: Complete uploads {@link https://api.slack.com/methods/files.completeUploadExternal files.completeUploadExternal}
410410
*
411-
* **#4**: Unless `request_file_info` set to false, call {@link https://api.slack.com/methods/files.info files.info} for
412-
* each file uploaded and returns that data. Requires that your app have `files:read` scope.
413411
* @param options
414412
*/
415413
public async filesUploadV2(options: FilesUploadV2Arguments): Promise<WebAPICallResult> {
@@ -429,13 +427,7 @@ export class WebClient extends Methods {
429427
// 3
430428
const completion = await this.completeFileUploads(fileUploads);
431429

432-
// 4
433-
let res = completion;
434-
if (options.request_file_info ?? true) {
435-
res = await this.getFileInfo(fileUploads);
436-
}
437-
438-
return { ok: true, files: res };
430+
return { ok: true, files: completion };
439431
}
440432

441433
/**
@@ -472,19 +464,6 @@ export class WebClient extends Methods {
472464
);
473465
}
474466

475-
/**
476-
* Call {@link https://api.slack.com/methods/files.info files.info} for
477-
* each file uploaded and returns relevant data. Requires that your app have `files:read` scope, to
478-
* turn off, set `request_file_info` set to false.
479-
* @param fileUploads
480-
* @returns
481-
*/
482-
private async getFileInfo(fileUploads: FileUploadV2Job[]):
483-
Promise<Array<WebAPICallResult>> {
484-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
485-
return Promise.all(fileUploads.map((job) => this.files.info({ file: job.file_id! })));
486-
}
487-
488467
/**
489468
* for each returned file upload URL, upload corresponding file
490469
* @param fileUploads

packages/web-api/src/methods.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ interface FileUpload {
18841884

18851885
export interface FilesUploadV2Arguments extends FileUploadV2, WebAPICallOptions, TokenOverridable {
18861886
file_uploads?: Omit<FileUploadV2, 'channel_id' | 'channels' | 'initial_comment' | 'thread_ts'>[];
1887-
request_file_info?: boolean;
1887+
request_file_info?: boolean; // since v7, this flag is no longer used
18881888
}
18891889

18901890
export type FileUploadV2 = FileUpload & {

packages/web-api/src/response/FilesCompleteUploadExternalResponse.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,57 @@ export type FilesCompleteUploadExternalResponse = WebAPICallResult & {
1818
};
1919

2020
export interface File {
21-
id?: string;
22-
title?: string;
21+
channels?: string[];
22+
comments_count?: number;
23+
created?: number;
24+
display_as_bot?: boolean;
25+
edit_link?: string;
26+
editable?: boolean;
27+
external_type?: string;
28+
file_access?: string;
29+
filetype?: string;
30+
groups?: string[];
31+
has_more_shares?: boolean;
32+
has_rich_preview?: boolean;
33+
id?: string;
34+
ims?: string[];
35+
is_external?: boolean;
36+
is_public?: boolean;
37+
is_starred?: boolean;
38+
lines?: number;
39+
lines_more?: number;
40+
media_display_type?: string;
41+
mimetype?: string;
42+
mode?: string;
43+
name?: string;
44+
permalink?: string;
45+
permalink_public?: string;
46+
pretty_type?: string;
47+
preview?: string;
48+
preview_highlight?: string;
49+
preview_is_truncated?: boolean;
50+
public_url_shared?: boolean;
51+
shares?: Shares;
52+
size?: number;
53+
timestamp?: number;
54+
title?: string;
55+
url_private?: string;
56+
url_private_download?: string;
57+
user?: string;
58+
user_team?: string;
59+
username?: string;
60+
}
61+
62+
export interface Shares {
63+
public?: { [key: string]: Public[] };
64+
}
65+
66+
export interface Public {
67+
channel_name?: string;
68+
reply_count?: number;
69+
reply_users?: string[];
70+
reply_users_count?: number;
71+
share_user_id?: string;
72+
team_id?: string;
73+
ts?: string;
2374
}

0 commit comments

Comments
 (0)