node-datalith 0.1.2 → 0.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/lib/file.d.ts +5 -5
- package/lib/file.js +1 -1
- package/lib/lib.js +47 -49
- package/package.json +12 -9
package/lib/file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TimeoutResponse } from "fetch-helper-x";
|
|
2
|
-
import { ImageSize } from "./image.js";
|
|
1
|
+
import type { TimeoutResponse } from "fetch-helper-x";
|
|
2
|
+
import type { ImageSize } from "./image.js";
|
|
3
3
|
/**
|
|
4
4
|
* Represents a file resource with metadata such as ETag, content type, and size.
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@ 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
14
|
readonly contentDisposition: string;
|
|
@@ -19,14 +19,14 @@ export declare class File {
|
|
|
19
19
|
*
|
|
20
20
|
* @param {TimeoutResponse} resource The response from `timeoutFetch`.
|
|
21
21
|
* @param {string} etag The unique identifier for the file, typically used for caching.
|
|
22
|
-
* @param {Date}
|
|
22
|
+
* @param {Date} string The date and time when the file was created.
|
|
23
23
|
* @param {string} contentType The MIME type of the file.
|
|
24
24
|
* @param {number} contentLength The size of the file in bytes.
|
|
25
25
|
* @param {string} contentDisposition The file name and the expected usage.
|
|
26
26
|
* @param {ReadableStream} data The file content as a readable stream.
|
|
27
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.
|
|
28
28
|
*/
|
|
29
|
-
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);
|
|
30
30
|
/**
|
|
31
31
|
* If you want to cancel the data, use this function instead of `data.cancel()` or `data.getReader().cancel()`.
|
|
32
32
|
*/
|
package/lib/file.js
CHANGED
|
@@ -17,7 +17,7 @@ export class File {
|
|
|
17
17
|
*
|
|
18
18
|
* @param {TimeoutResponse} resource The response from `timeoutFetch`.
|
|
19
19
|
* @param {string} etag The unique identifier for the file, typically used for caching.
|
|
20
|
-
* @param {Date}
|
|
20
|
+
* @param {Date} string The date and time when the file was created.
|
|
21
21
|
* @param {string} contentType The MIME type of the file.
|
|
22
22
|
* @param {number} contentLength The size of the file in bytes.
|
|
23
23
|
* @param {string} contentDisposition The file name and the expected usage.
|
package/lib/lib.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Readable } from "node:stream";
|
|
2
2
|
import { nodeReadableToWebReadableStream, timeoutFetch } from "fetch-helper-x";
|
|
3
|
-
import { BadRequestError, NotFoundError, PayloadTooLargeError } from "./errors.js";
|
|
3
|
+
import { BadRequestError, NotFoundError, PayloadTooLargeError, } from "./errors.js";
|
|
4
4
|
import { File } from "./file.js";
|
|
5
5
|
import { Image } from "./image.js";
|
|
6
6
|
import { Resource } from "./resource.js";
|
|
@@ -169,22 +169,21 @@ export class Datalith {
|
|
|
169
169
|
idleTimeout: typeof options.idleTimeout !== "undefined" ? options.idleTimeout : DEFAULT_IDLE_TIMEOUT,
|
|
170
170
|
});
|
|
171
171
|
switch (response.status) {
|
|
172
|
-
case 200:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
172
|
+
case 200: {
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
174
|
+
const etag = response.headers.get("etag");
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
176
|
+
const date = response.headers.get("date");
|
|
177
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
178
|
+
const contentType = response.headers.get("content-type");
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
180
|
+
const contentLength = parseInt(response.headers.get("content-length"));
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
182
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
184
|
+
const body = response.body;
|
|
185
|
+
return new File(response, etag, date, contentType, contentLength, contentDisposition, body);
|
|
186
|
+
}
|
|
188
187
|
case 400:
|
|
189
188
|
await response.cancelBody();
|
|
190
189
|
throw new BadRequestError();
|
|
@@ -220,38 +219,37 @@ export class Datalith {
|
|
|
220
219
|
idleTimeout: typeof options.idleTimeout !== "undefined" ? options.idleTimeout : DEFAULT_IDLE_TIMEOUT,
|
|
221
220
|
});
|
|
222
221
|
switch (response.status) {
|
|
223
|
-
case 200:
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
return parseInt(s);
|
|
243
|
-
};
|
|
244
|
-
const imageWidth = getNullableNumber("x-image-width");
|
|
245
|
-
const imageHeight = getNullableNumber("x-image-height");
|
|
246
|
-
let imageSize = null;
|
|
247
|
-
if (imageWidth !== null && imageHeight !== null) {
|
|
248
|
-
imageSize = {
|
|
249
|
-
width: imageWidth,
|
|
250
|
-
height: imageHeight,
|
|
251
|
-
};
|
|
222
|
+
case 200: {
|
|
223
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
224
|
+
const etag = response.headers.get("etag");
|
|
225
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
226
|
+
const date = response.headers.get("date");
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
228
|
+
const contentType = response.headers.get("content-type");
|
|
229
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
230
|
+
const contentLength = parseInt(response.headers.get("content-length"));
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
232
|
+
const contentDisposition = response.headers.get("content-disposition");
|
|
233
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
234
|
+
const body = response.body;
|
|
235
|
+
const getNullableNumber = (fieldName) => {
|
|
236
|
+
const s = response.headers.get(fieldName);
|
|
237
|
+
if (s === null) {
|
|
238
|
+
return null;
|
|
252
239
|
}
|
|
253
|
-
return
|
|
240
|
+
return parseInt(s);
|
|
241
|
+
};
|
|
242
|
+
const imageWidth = getNullableNumber("x-image-width");
|
|
243
|
+
const imageHeight = getNullableNumber("x-image-height");
|
|
244
|
+
let imageSize = null;
|
|
245
|
+
if (imageWidth !== null && imageHeight !== null) {
|
|
246
|
+
imageSize = {
|
|
247
|
+
width: imageWidth,
|
|
248
|
+
height: imageHeight,
|
|
249
|
+
};
|
|
254
250
|
}
|
|
251
|
+
return new File(response, etag, date, contentType, contentLength, contentDisposition, body, imageSize);
|
|
252
|
+
}
|
|
255
253
|
case 400:
|
|
256
254
|
await response.cancelBody();
|
|
257
255
|
throw new BadRequestError();
|
|
@@ -357,7 +355,7 @@ export const validateCenterCrop = (centerCrop) => {
|
|
|
357
355
|
if (typeof centerCrop === "undefined") {
|
|
358
356
|
return true;
|
|
359
357
|
}
|
|
360
|
-
return (/^-?\d+\.?\d*:-?\d+\.?\d*$/).test(centerCrop);
|
|
358
|
+
return (/^-?\d+\.?\d*:-?\d+\.?\d*$/u).test(centerCrop);
|
|
361
359
|
};
|
|
362
360
|
/**
|
|
363
361
|
* Validates if the given resolution is either `undefined`, `"original"`, or follows the format of `"<positive integer>x"`.
|
|
@@ -369,5 +367,5 @@ export const validateResolution = (resolution) => {
|
|
|
369
367
|
if (resolution === "original") {
|
|
370
368
|
return true;
|
|
371
369
|
}
|
|
372
|
-
return (/^[1-9][0-9]*x$/).test(resolution);
|
|
370
|
+
return (/^[1-9][0-9]*x$/u).test(resolution);
|
|
373
371
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-datalith",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|
|
@@ -42,20 +42,23 @@
|
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://magiclen.org/datalith/",
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@types/node": "^22.
|
|
46
|
-
"fetch-helper-x": "^0.1.
|
|
45
|
+
"@types/node": "^22.7.7",
|
|
46
|
+
"fetch-helper-x": "^0.1.6"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
49
|
+
"@eslint/js": "^9.13.0",
|
|
50
|
+
"@stylistic/eslint-plugin": "^2.9.0",
|
|
51
|
+
"@types/eslint__js": "^8.42.3",
|
|
52
|
+
"@types/jest": "^29.5.13",
|
|
53
|
+
"eslint": "^9.13.0",
|
|
53
54
|
"eslint-import-resolver-typescript": "^3.6.3",
|
|
54
|
-
"eslint-plugin-import": "^2.
|
|
55
|
+
"eslint-plugin-import": "^2.31.0",
|
|
56
|
+
"globals": "^15.11.0",
|
|
55
57
|
"jest": "^29.7.0",
|
|
56
58
|
"rimraf": "^6.0.1",
|
|
57
59
|
"ts-jest": "^29.2.5",
|
|
58
|
-
"typescript": "
|
|
60
|
+
"typescript": "~5.5.4",
|
|
61
|
+
"typescript-eslint": "^8.10.0",
|
|
59
62
|
"web-streams-polyfill": "^4.0.0"
|
|
60
63
|
}
|
|
61
64
|
}
|