polfan-server-js-client 0.2.37 → 0.2.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ export interface File {
10
10
  }
11
11
  export declare class FilesClient extends AbstractRestClient {
12
12
  protected defaultUrl: string;
13
- uploadFile(file: Parameters<typeof FormData.prototype.append>[1]): Promise<RestClientResponse<File>>;
13
+ uploadFile(file: globalThis.File | Blob): Promise<RestClientResponse<File>>;
14
14
  getFileMeta(id: string): Promise<RestClientResponse<File>>;
15
15
  getFileMetaBulk(ids: string[]): Promise<RestClientResponse<File[]>>;
16
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polfan-server-js-client",
3
- "version": "0.2.37",
3
+ "version": "0.2.39",
4
4
  "description": "JavaScript client library for handling communication with Polfan chat server.",
5
5
  "author": "Jarosław Żak",
6
6
  "license": "MIT",
@@ -11,26 +11,32 @@ export interface File {
11
11
  }
12
12
 
13
13
  export class FilesClient extends AbstractRestClient {
14
- protected defaultUrl: string = 'https://files.devana.pl/files';
15
-
16
- public async uploadFile(file: Parameters<typeof FormData.prototype.append>[1]): Promise<RestClientResponse<File>> {
17
- const formData = new FormData();
18
- formData.append('file', file);
19
-
20
- let headers = {...this.getAuthHeaders(), Accept: 'application/json'};
21
-
22
- const response = await fetch(this.defaultUrl, {method: 'POST', body: formData, headers});
14
+ protected defaultUrl: string = 'https://files.devana.pl';
15
+
16
+ public async uploadFile(file: globalThis.File | Blob): Promise<RestClientResponse<File>> {
17
+ let headers = {
18
+ ...this.getAuthHeaders(),
19
+ Accept: 'application/json',
20
+ 'Content-Disposition': `attachment; filename="${(file as globalThis.File).name ?? ''}"`,
21
+ 'Content-Length': file.size
22
+ };
23
+
24
+ const response = await fetch(this.getUrl('files'), {
25
+ method: 'POST',
26
+ body: file,
27
+ headers
28
+ });
23
29
 
24
30
  return this.convertFetchResponse<File>(response);
25
31
  }
26
32
 
27
33
  public async getFileMeta(id: string): Promise<RestClientResponse<File>> {
28
- return this.send('GET', '/' + id);
34
+ return this.send('GET', 'files/' + id);
29
35
  }
30
36
 
31
37
  public async getFileMetaBulk(ids: string[]): Promise<RestClientResponse<File[]>> {
32
38
  const searchParams = new URLSearchParams();
33
39
  ids.forEach(id => searchParams.append('id[]', id));
34
- return this.send('GET', '?' + searchParams);
40
+ return this.send('GET', 'files?' + searchParams);
35
41
  }
36
42
  }