diskio-api 1.1.0 → 1.2.1

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.
package/README.md CHANGED
@@ -43,6 +43,37 @@ import { DiskioAPIClient } from 'diskio-api';
43
43
  import { DiskioAPIClient } from 'diskio-api';
44
44
  ```
45
45
 
46
+ ## Instance
47
+ ```js
48
+ const client = new DiskioAPIClient('http://localhost:8080');
49
+ ```
50
+
51
+ ## Health Check
52
+ Get information about the server
53
+ ```js
54
+ const response = await client.healthCheck();
55
+ console.log(response.data.response.diskio.size); // 10737418240
56
+ ```
57
+
58
+ ## Upload
59
+ ```ts
60
+ const file: File = new File(['Hello world!'], 'hello.txt');
61
+ const response = await client.upload([ file ]);
62
+ const path = response.data.response[0];
63
+ ```
64
+
65
+ ## Download
66
+ ```js
67
+ const file = await client.download(path, type: 'arrayBuffer' | 'stream') // default download is 'arrayBuffer'
68
+ // Work with the file
69
+ console.log(typeof file) // 'arraybuffer' | 'stream'
70
+ ```
71
+
72
+ ## Delete
73
+ ```js
74
+ await client.delete('/path/to/file');
75
+ ```
76
+
46
77
  ## 📝 License
47
78
 
48
79
  This project is licensed under the `GNU AFFERO GENERAL PUBLIC LICENSE` - see the [LICENSE](LICENSE) file for details
package/cjs/index.d.ts CHANGED
@@ -49,130 +49,56 @@ export declare class DiskioAPIClient {
49
49
  };
50
50
  };
51
51
  }> | undefined, `${string}/${string}`>>;
52
- diskio: {
53
- upload: (files: File[]) => Promise<import("openapi-fetch").FetchResponse<{
54
- parameters: {
55
- query?: never;
56
- header?: never;
57
- path?: never;
58
- cookie?: never;
59
- };
60
- requestBody: {
61
- content: {
62
- "multipart/form-data": {
63
- files: string[];
64
- };
65
- };
66
- };
67
- responses: {
68
- 200: {
69
- headers: {
70
- [name: string]: unknown;
71
- };
72
- content: {
73
- "application/json": components["schemas"]["response.model"] & {
74
- response: string[];
75
- };
76
- };
77
- };
78
- };
79
- }, {
80
- body: {
81
- files: any;
52
+ upload(files: (File | Blob)[]): Promise<({
53
+ code: number;
54
+ timestamp: number;
55
+ } & {
56
+ response: string[];
57
+ }) | undefined>;
58
+ download(name: string, type?: 'arrayBuffer' | 'stream'): Promise<ArrayBuffer | ReadableStream<Uint8Array> | null | undefined>;
59
+ delete(name: string): Promise<import("openapi-fetch").FetchResponse<{
60
+ parameters: {
61
+ query?: never;
62
+ header?: never;
63
+ path: {
64
+ name: string;
82
65
  };
83
- }, `${string}/${string}`>>;
84
- download: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
85
- parameters: {
86
- query?: never;
87
- header?: never;
88
- path: {
89
- name: string;
66
+ cookie?: never;
67
+ };
68
+ requestBody?: never;
69
+ responses: {
70
+ 200: {
71
+ headers: {
72
+ [name: string]: unknown;
90
73
  };
91
- cookie?: never;
74
+ content?: never;
92
75
  };
93
- requestBody?: never;
94
- responses: {
95
- 200: {
96
- headers: {
97
- [name: string]: unknown;
98
- };
99
- content: {
100
- "application/octet-stream": string;
101
- };
102
- };
103
- 404: {
104
- headers: {
105
- [name: string]: unknown;
106
- };
107
- content: {
108
- "application/json": components["schemas"]["not-found-response.model"] & {
109
- response: string;
110
- };
111
- };
76
+ 404: {
77
+ headers: {
78
+ [name: string]: unknown;
112
79
  };
113
- 500: {
114
- headers: {
115
- [name: string]: unknown;
116
- };
117
- content: {
118
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
119
- response: string;
120
- };
80
+ content: {
81
+ "application/json": components["schemas"]["not-found-response.model"] & {
82
+ response: string;
121
83
  };
122
84
  };
123
85
  };
124
- }, {
125
- params: {
126
- path: {
127
- name: string;
128
- };
129
- };
130
- responseType: string;
131
- }, `${string}/${string}`>>;
132
- delete: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
133
- parameters: {
134
- query?: never;
135
- header?: never;
136
- path: {
137
- name: string;
138
- };
139
- cookie?: never;
140
- };
141
- requestBody?: never;
142
- responses: {
143
- 200: {
144
- headers: {
145
- [name: string]: unknown;
146
- };
147
- content?: never;
148
- };
149
- 404: {
150
- headers: {
151
- [name: string]: unknown;
152
- };
153
- content: {
154
- "application/json": components["schemas"]["not-found-response.model"] & {
155
- response: string;
156
- };
157
- };
86
+ 500: {
87
+ headers: {
88
+ [name: string]: unknown;
158
89
  };
159
- 500: {
160
- headers: {
161
- [name: string]: unknown;
162
- };
163
- content: {
164
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
165
- response: string;
166
- };
90
+ content: {
91
+ "application/json": components["schemas"]["internal-server-error-response.model"] & {
92
+ response: string;
167
93
  };
168
94
  };
169
95
  };
170
- }, {
171
- params: {
172
- path: {
173
- name: string;
174
- };
96
+ };
97
+ }, {
98
+ params: {
99
+ path: {
100
+ name: string;
175
101
  };
176
- }, `${string}/${string}`>>;
177
- };
102
+ };
103
+ }, `${string}/${string}`>>;
178
104
  }
package/cjs/index.js CHANGED
@@ -23,22 +23,24 @@ class DiskioAPIClient {
23
23
  return this.authentication;
24
24
  }
25
25
  };
26
- this.diskio = {
27
- upload: (files) => {
28
- return this.client.POST('/diskio', { body: { files: files } });
29
- },
30
- download: (name) => {
31
- return this.client.GET('/diskio/{name}', { params: { path: { name } }, responseType: 'arraybuffer' });
32
- },
33
- delete: (name) => {
34
- return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
35
- }
36
- };
37
26
  this.client = (0, openapi_fetch_1.default)({ baseUrl, headers: { Bearer: 'access_token' } });
38
27
  this.client.use(this.authenticate);
39
28
  }
40
29
  healthCheck() {
41
30
  return this.client.GET('/health-check');
42
31
  }
32
+ async upload(files) {
33
+ const formData = new FormData();
34
+ files.forEach((file) => formData.append('files', file));
35
+ const response = this.client.POST('/diskio', { body: formData });
36
+ return response.data;
37
+ }
38
+ async download(name, type = 'arrayBuffer') {
39
+ const response = this.client.GET('/diskio/{name}', { params: { path: { name } }, parseAs: type });
40
+ return response.data;
41
+ }
42
+ delete(name) {
43
+ return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
44
+ }
43
45
  }
44
46
  exports.DiskioAPIClient = DiskioAPIClient;
package/mjs/index.d.ts CHANGED
@@ -49,130 +49,56 @@ export declare class DiskioAPIClient {
49
49
  };
50
50
  };
51
51
  }> | undefined, `${string}/${string}`>>;
52
- diskio: {
53
- upload: (files: File[]) => Promise<import("openapi-fetch").FetchResponse<{
54
- parameters: {
55
- query?: never;
56
- header?: never;
57
- path?: never;
58
- cookie?: never;
59
- };
60
- requestBody: {
61
- content: {
62
- "multipart/form-data": {
63
- files: string[];
64
- };
65
- };
66
- };
67
- responses: {
68
- 200: {
69
- headers: {
70
- [name: string]: unknown;
71
- };
72
- content: {
73
- "application/json": components["schemas"]["response.model"] & {
74
- response: string[];
75
- };
76
- };
77
- };
78
- };
79
- }, {
80
- body: {
81
- files: any;
52
+ upload(files: (File | Blob)[]): Promise<({
53
+ code: number;
54
+ timestamp: number;
55
+ } & {
56
+ response: string[];
57
+ }) | undefined>;
58
+ download(name: string, type?: 'arrayBuffer' | 'stream'): Promise<ArrayBuffer | ReadableStream<Uint8Array> | null | undefined>;
59
+ delete(name: string): Promise<import("openapi-fetch").FetchResponse<{
60
+ parameters: {
61
+ query?: never;
62
+ header?: never;
63
+ path: {
64
+ name: string;
82
65
  };
83
- }, `${string}/${string}`>>;
84
- download: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
85
- parameters: {
86
- query?: never;
87
- header?: never;
88
- path: {
89
- name: string;
66
+ cookie?: never;
67
+ };
68
+ requestBody?: never;
69
+ responses: {
70
+ 200: {
71
+ headers: {
72
+ [name: string]: unknown;
90
73
  };
91
- cookie?: never;
74
+ content?: never;
92
75
  };
93
- requestBody?: never;
94
- responses: {
95
- 200: {
96
- headers: {
97
- [name: string]: unknown;
98
- };
99
- content: {
100
- "application/octet-stream": string;
101
- };
102
- };
103
- 404: {
104
- headers: {
105
- [name: string]: unknown;
106
- };
107
- content: {
108
- "application/json": components["schemas"]["not-found-response.model"] & {
109
- response: string;
110
- };
111
- };
76
+ 404: {
77
+ headers: {
78
+ [name: string]: unknown;
112
79
  };
113
- 500: {
114
- headers: {
115
- [name: string]: unknown;
116
- };
117
- content: {
118
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
119
- response: string;
120
- };
80
+ content: {
81
+ "application/json": components["schemas"]["not-found-response.model"] & {
82
+ response: string;
121
83
  };
122
84
  };
123
85
  };
124
- }, {
125
- params: {
126
- path: {
127
- name: string;
128
- };
129
- };
130
- responseType: string;
131
- }, `${string}/${string}`>>;
132
- delete: (name: string) => Promise<import("openapi-fetch").FetchResponse<{
133
- parameters: {
134
- query?: never;
135
- header?: never;
136
- path: {
137
- name: string;
138
- };
139
- cookie?: never;
140
- };
141
- requestBody?: never;
142
- responses: {
143
- 200: {
144
- headers: {
145
- [name: string]: unknown;
146
- };
147
- content?: never;
148
- };
149
- 404: {
150
- headers: {
151
- [name: string]: unknown;
152
- };
153
- content: {
154
- "application/json": components["schemas"]["not-found-response.model"] & {
155
- response: string;
156
- };
157
- };
86
+ 500: {
87
+ headers: {
88
+ [name: string]: unknown;
158
89
  };
159
- 500: {
160
- headers: {
161
- [name: string]: unknown;
162
- };
163
- content: {
164
- "application/json": components["schemas"]["internal-server-error-response.model"] & {
165
- response: string;
166
- };
90
+ content: {
91
+ "application/json": components["schemas"]["internal-server-error-response.model"] & {
92
+ response: string;
167
93
  };
168
94
  };
169
95
  };
170
- }, {
171
- params: {
172
- path: {
173
- name: string;
174
- };
96
+ };
97
+ }, {
98
+ params: {
99
+ path: {
100
+ name: string;
175
101
  };
176
- }, `${string}/${string}`>>;
177
- };
102
+ };
103
+ }, `${string}/${string}`>>;
178
104
  }
package/mjs/index.js CHANGED
@@ -17,21 +17,23 @@ export class DiskioAPIClient {
17
17
  return this.authentication;
18
18
  }
19
19
  };
20
- this.diskio = {
21
- upload: (files) => {
22
- return this.client.POST('/diskio', { body: { files: files } });
23
- },
24
- download: (name) => {
25
- return this.client.GET('/diskio/{name}', { params: { path: { name } }, responseType: 'arraybuffer' });
26
- },
27
- delete: (name) => {
28
- return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
29
- }
30
- };
31
20
  this.client = createClient({ baseUrl, headers: { Bearer: 'access_token' } });
32
21
  this.client.use(this.authenticate);
33
22
  }
34
23
  healthCheck() {
35
24
  return this.client.GET('/health-check');
36
25
  }
26
+ async upload(files) {
27
+ const formData = new FormData();
28
+ files.forEach((file) => formData.append('files', file));
29
+ const response = await this.client.POST('/diskio', { body: formData });
30
+ return response.data;
31
+ }
32
+ async download(name, type = 'arrayBuffer') {
33
+ const response = await this.client.GET('/diskio/{name}', { params: { path: { name } }, parseAs: type });
34
+ return response.data;
35
+ }
36
+ delete(name) {
37
+ return this.client.DELETE('/diskio/{name}', { params: { path: { name } } });
38
+ }
37
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diskio-api",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "An API Client for diskio-server",
5
5
  "type": "module",
6
6
  "main": "cjs/index.js",