node-datalith 0.1.1 → 0.2.0
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/lib/file.d.ts +5 -3
- package/lib/file.js +5 -2
- package/lib/lib.d.ts +12 -2
- package/lib/lib.js +15 -4
- package/package.json +1 -1
package/lib/file.d.ts
CHANGED
|
@@ -8,9 +8,10 @@ import { ImageSize } from "./image.js";
|
|
|
8
8
|
export declare class File {
|
|
9
9
|
private readonly resource;
|
|
10
10
|
readonly etag: string;
|
|
11
|
-
readonly date:
|
|
11
|
+
readonly date: string;
|
|
12
12
|
readonly contentType: string;
|
|
13
13
|
readonly contentLength: number;
|
|
14
|
+
readonly contentDisposition: string;
|
|
14
15
|
readonly data: ReadableStream;
|
|
15
16
|
readonly imageSize?: (ImageSize | null) | undefined;
|
|
16
17
|
/**
|
|
@@ -18,13 +19,14 @@ export declare class File {
|
|
|
18
19
|
*
|
|
19
20
|
* @param {TimeoutResponse} resource The response from `timeoutFetch`.
|
|
20
21
|
* @param {string} etag The unique identifier for the file, typically used for caching.
|
|
21
|
-
* @param {Date}
|
|
22
|
+
* @param {Date} string The date and time when the file was created.
|
|
22
23
|
* @param {string} contentType The MIME type of the file.
|
|
23
24
|
* @param {number} contentLength The size of the file in bytes.
|
|
25
|
+
* @param {string} contentDisposition The file name and the expected usage.
|
|
24
26
|
* @param {ReadableStream} data The file content as a readable stream.
|
|
25
27
|
* @param {imageSize} [imageSize] (Optional) The size of the image in pixels, or `null` if not applicable, or `undefined` if this file is not an image.
|
|
26
28
|
*/
|
|
27
|
-
constructor(resource: TimeoutResponse, etag: string, date:
|
|
29
|
+
constructor(resource: TimeoutResponse, etag: string, date: string, contentType: string, contentLength: number, contentDisposition: string, data: ReadableStream, imageSize?: (ImageSize | null) | undefined);
|
|
28
30
|
/**
|
|
29
31
|
* If you want to cancel the data, use this function instead of `data.cancel()` or `data.getReader().cancel()`.
|
|
30
32
|
*/
|
package/lib/file.js
CHANGED
|
@@ -9,6 +9,7 @@ export class File {
|
|
|
9
9
|
date;
|
|
10
10
|
contentType;
|
|
11
11
|
contentLength;
|
|
12
|
+
contentDisposition;
|
|
12
13
|
data;
|
|
13
14
|
imageSize;
|
|
14
15
|
/**
|
|
@@ -16,18 +17,20 @@ export class File {
|
|
|
16
17
|
*
|
|
17
18
|
* @param {TimeoutResponse} resource The response from `timeoutFetch`.
|
|
18
19
|
* @param {string} etag The unique identifier for the file, typically used for caching.
|
|
19
|
-
* @param {Date}
|
|
20
|
+
* @param {Date} string The date and time when the file was created.
|
|
20
21
|
* @param {string} contentType The MIME type of the file.
|
|
21
22
|
* @param {number} contentLength The size of the file in bytes.
|
|
23
|
+
* @param {string} contentDisposition The file name and the expected usage.
|
|
22
24
|
* @param {ReadableStream} data The file content as a readable stream.
|
|
23
25
|
* @param {imageSize} [imageSize] (Optional) The size of the image in pixels, or `null` if not applicable, or `undefined` if this file is not an image.
|
|
24
26
|
*/
|
|
25
|
-
constructor(resource, etag, date, contentType, contentLength, data, imageSize) {
|
|
27
|
+
constructor(resource, etag, date, contentType, contentLength, contentDisposition, data, imageSize) {
|
|
26
28
|
this.resource = resource;
|
|
27
29
|
this.etag = etag;
|
|
28
30
|
this.date = date;
|
|
29
31
|
this.contentType = contentType;
|
|
30
32
|
this.contentLength = contentLength;
|
|
33
|
+
this.contentDisposition = contentDisposition;
|
|
31
34
|
this.data = data;
|
|
32
35
|
this.imageSize = imageSize;
|
|
33
36
|
// do nothing
|
package/lib/lib.d.ts
CHANGED
|
@@ -133,9 +133,19 @@ export interface ImagePutOptions extends WithBodyTimeoutOptions {
|
|
|
133
133
|
*/
|
|
134
134
|
idleTimeout?: number | null;
|
|
135
135
|
}
|
|
136
|
-
export
|
|
136
|
+
export interface FileGetOptions extends WithBodyTimeoutOptions {
|
|
137
|
+
/**
|
|
138
|
+
* Whether to download as a file. It will affect the `contentDisposition` field of the returned `File` instance.
|
|
139
|
+
*
|
|
140
|
+
* If not provided (`undefined`), Datalith will default to `false`.
|
|
141
|
+
*
|
|
142
|
+
* @default undefined (Datalith defaults to `false`)
|
|
143
|
+
*/
|
|
144
|
+
download?: boolean;
|
|
145
|
+
}
|
|
146
|
+
export type ResourceGetOptions = FileGetOptions;
|
|
137
147
|
export type Resolution = `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10}x` | "original";
|
|
138
|
-
export interface ImageGetOptions extends
|
|
148
|
+
export interface ImageGetOptions extends FileGetOptions {
|
|
139
149
|
/**
|
|
140
150
|
* The desired resolution of the image.
|
|
141
151
|
*
|
package/lib/lib.js
CHANGED
|
@@ -159,6 +159,10 @@ export class Datalith {
|
|
|
159
159
|
*/
|
|
160
160
|
async getResource(id, options = {}) {
|
|
161
161
|
const url = new URL(id, this._apiFetch);
|
|
162
|
+
const searchParams = url.searchParams;
|
|
163
|
+
if (options.download) {
|
|
164
|
+
searchParams.append("download", "1");
|
|
165
|
+
}
|
|
162
166
|
const response = await timeoutFetch(url, {
|
|
163
167
|
method: "GET",
|
|
164
168
|
requestTimeout: typeof options.reqeustTimeout !== "undefined" ? options.reqeustTimeout : DEFAULT_REQUEST_TIMEOUT,
|
|
@@ -170,14 +174,16 @@ export class Datalith {
|
|
|
170
174
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
171
175
|
const etag = response.headers.get("etag");
|
|
172
176
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
173
|
-
const date =
|
|
177
|
+
const date = response.headers.get("date");
|
|
174
178
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
175
179
|
const contentType = response.headers.get("content-type");
|
|
176
180
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
177
181
|
const contentLength = parseInt(response.headers.get("content-length"));
|
|
178
182
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
183
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
179
185
|
const body = response.body;
|
|
180
|
-
return new File(response, etag, date, contentType, contentLength, body);
|
|
186
|
+
return new File(response, etag, date, contentType, contentLength, contentDisposition, body);
|
|
181
187
|
}
|
|
182
188
|
case 400:
|
|
183
189
|
await response.cancelBody();
|
|
@@ -199,6 +205,9 @@ export class Datalith {
|
|
|
199
205
|
async getImage(id, options = {}) {
|
|
200
206
|
const url = new URL(id, this._apiFetchImage);
|
|
201
207
|
const searchParams = url.searchParams;
|
|
208
|
+
if (options.download) {
|
|
209
|
+
searchParams.append("download", "1");
|
|
210
|
+
}
|
|
202
211
|
if (typeof options.resolution !== "undefined") {
|
|
203
212
|
searchParams.append("resolution", options.resolution);
|
|
204
213
|
}
|
|
@@ -216,12 +225,14 @@ export class Datalith {
|
|
|
216
225
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
217
226
|
const etag = response.headers.get("etag");
|
|
218
227
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
219
|
-
const date =
|
|
228
|
+
const date = response.headers.get("date");
|
|
220
229
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
221
230
|
const contentType = response.headers.get("content-type");
|
|
222
231
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
223
232
|
const contentLength = parseInt(response.headers.get("content-length"));
|
|
224
233
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
234
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
225
236
|
const body = response.body;
|
|
226
237
|
const getNullableNumber = (fieldName) => {
|
|
227
238
|
const s = response.headers.get(fieldName);
|
|
@@ -239,7 +250,7 @@ export class Datalith {
|
|
|
239
250
|
height: imageHeight,
|
|
240
251
|
};
|
|
241
252
|
}
|
|
242
|
-
return new File(response, etag, date, contentType, contentLength, body, imageSize);
|
|
253
|
+
return new File(response, etag, date, contentType, contentLength, contentDisposition, body, imageSize);
|
|
243
254
|
}
|
|
244
255
|
case 400:
|
|
245
256
|
await response.cancelBody();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-datalith",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Datalith is a file management system powered by SQLite for metadata storage and the file system for file storage. This library can help you conmunicate with Datalith in Node.js.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/lib.js",
|