@aeriajs/builtins 0.0.180 → 0.0.182
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/dist/collections/file/description.d.ts +1 -1
- package/dist/collections/file/description.js +1 -0
- package/dist/collections/file/description.mjs +2 -1
- package/dist/collections/file/download.d.ts +7 -0
- package/dist/collections/file/download.js +16 -3
- package/dist/collections/file/download.mjs +15 -2
- package/dist/collections/file/index.d.ts +7 -3
- package/dist/collections/file/insert.d.ts +1 -1
- package/dist/index.d.ts +7 -3
- package/package.json +6 -6
|
@@ -3,7 +3,7 @@ export declare const description: {
|
|
|
3
3
|
readonly icon: "paperclip";
|
|
4
4
|
readonly owned: "always";
|
|
5
5
|
readonly presets: readonly ["owned"];
|
|
6
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
6
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
7
7
|
readonly properties: {
|
|
8
8
|
readonly type: {
|
|
9
9
|
readonly type: "string";
|
|
@@ -2,6 +2,9 @@ import type { Context } from '@aeriajs/types';
|
|
|
2
2
|
import type { description } from './description.js';
|
|
3
3
|
import { HTTPStatus, ACError } from '@aeriajs/types';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
|
+
export declare enum DownloadError {
|
|
6
|
+
RangeNotSatisfiable = "RANGE_NOT_SATISFIABLE"
|
|
7
|
+
}
|
|
5
8
|
export declare const download: (payload: {
|
|
6
9
|
fileId: string;
|
|
7
10
|
options: readonly ("picture" | "download")[];
|
|
@@ -10,4 +13,8 @@ export declare const download: (payload: {
|
|
|
10
13
|
readonly code: ACError.ResourceNotFound;
|
|
11
14
|
} & {
|
|
12
15
|
httpStatus: HTTPStatus.NotFound;
|
|
16
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
17
|
+
readonly code: DownloadError;
|
|
18
|
+
} & {
|
|
19
|
+
httpStatus: HTTPStatus.RangeNotSatisfiable;
|
|
13
20
|
}> | fs.ReadStream>;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.download = void 0;
|
|
3
|
+
exports.download = exports.DownloadError = void 0;
|
|
4
4
|
const types_1 = require("@aeriajs/types");
|
|
5
5
|
const core_1 = require("@aeriajs/core");
|
|
6
6
|
const fs = require("fs");
|
|
7
|
+
var DownloadError;
|
|
8
|
+
(function (DownloadError) {
|
|
9
|
+
DownloadError["RangeNotSatisfiable"] = "RANGE_NOT_SATISFIABLE";
|
|
10
|
+
})(DownloadError || (exports.DownloadError = DownloadError = {}));
|
|
7
11
|
const download = async (payload, context) => {
|
|
8
12
|
const { fileId, options = [] } = payload;
|
|
9
13
|
const file = await context.collection.model.findOne({
|
|
@@ -17,7 +21,7 @@ const download = async (payload, context) => {
|
|
|
17
21
|
});
|
|
18
22
|
if (!file) {
|
|
19
23
|
if (!payload.noHeaders) {
|
|
20
|
-
context.response.writeHead(
|
|
24
|
+
context.response.writeHead(types_1.HTTPStatus.NotFound, {
|
|
21
25
|
'content-type': 'application/json',
|
|
22
26
|
});
|
|
23
27
|
}
|
|
@@ -44,6 +48,15 @@ const download = async (payload, context) => {
|
|
|
44
48
|
const end = parts[1]
|
|
45
49
|
? parseInt(parts[1])
|
|
46
50
|
: stat.size - 1;
|
|
51
|
+
if (start >= stat.size || end >= stat.size) {
|
|
52
|
+
context.response.writeHead(types_1.HTTPStatus.RangeNotSatisfiable, {
|
|
53
|
+
'content-type': 'application/json',
|
|
54
|
+
'content-range': `bytes */${stat.size}`,
|
|
55
|
+
});
|
|
56
|
+
return context.error(types_1.HTTPStatus.RangeNotSatisfiable, {
|
|
57
|
+
code: DownloadError.RangeNotSatisfiable,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
47
60
|
const chunkSize = (end - start) + 1;
|
|
48
61
|
if (!payload.noHeaders) {
|
|
49
62
|
context.response.writeHead(206, {
|
|
@@ -62,7 +75,7 @@ const download = async (payload, context) => {
|
|
|
62
75
|
});
|
|
63
76
|
}
|
|
64
77
|
if (!payload.noHeaders) {
|
|
65
|
-
context.response.writeHead(
|
|
78
|
+
context.response.writeHead(types_1.HTTPStatus.Ok, {
|
|
66
79
|
'content-type': file.type,
|
|
67
80
|
'content-disposition': `${options.includes('download')
|
|
68
81
|
? 'attachment; '
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
import { HTTPStatus, ACError } from "@aeriajs/types";
|
|
3
3
|
import { ObjectId } from "@aeriajs/core";
|
|
4
4
|
import * as fs from "fs";
|
|
5
|
+
export var DownloadError = /* @__PURE__ */ ((DownloadError2) => {
|
|
6
|
+
DownloadError2["RangeNotSatisfiable"] = "RANGE_NOT_SATISFIABLE";
|
|
7
|
+
return DownloadError2;
|
|
8
|
+
})(DownloadError || {});
|
|
5
9
|
export const download = async (payload, context) => {
|
|
6
10
|
const { fileId, options = [] } = payload;
|
|
7
11
|
const file = await context.collection.model.findOne({
|
|
@@ -15,7 +19,7 @@ export const download = async (payload, context) => {
|
|
|
15
19
|
});
|
|
16
20
|
if (!file) {
|
|
17
21
|
if (!payload.noHeaders) {
|
|
18
|
-
context.response.writeHead(
|
|
22
|
+
context.response.writeHead(HTTPStatus.NotFound, {
|
|
19
23
|
"content-type": "application/json"
|
|
20
24
|
});
|
|
21
25
|
}
|
|
@@ -39,6 +43,15 @@ export const download = async (payload, context) => {
|
|
|
39
43
|
const parts = range.replace(/bytes=/, "").split("-");
|
|
40
44
|
const start = parseInt(parts[0]);
|
|
41
45
|
const end = parts[1] ? parseInt(parts[1]) : stat.size - 1;
|
|
46
|
+
if (start >= stat.size || end >= stat.size) {
|
|
47
|
+
context.response.writeHead(HTTPStatus.RangeNotSatisfiable, {
|
|
48
|
+
"content-type": "application/json",
|
|
49
|
+
"content-range": `bytes */${stat.size}`
|
|
50
|
+
});
|
|
51
|
+
return context.error(HTTPStatus.RangeNotSatisfiable, {
|
|
52
|
+
code: "RANGE_NOT_SATISFIABLE" /* RangeNotSatisfiable */
|
|
53
|
+
});
|
|
54
|
+
}
|
|
42
55
|
const chunkSize = end - start + 1;
|
|
43
56
|
if (!payload.noHeaders) {
|
|
44
57
|
context.response.writeHead(206, {
|
|
@@ -55,7 +68,7 @@ export const download = async (payload, context) => {
|
|
|
55
68
|
});
|
|
56
69
|
}
|
|
57
70
|
if (!payload.noHeaders) {
|
|
58
|
-
context.response.writeHead(
|
|
71
|
+
context.response.writeHead(HTTPStatus.Ok, {
|
|
59
72
|
"content-type": file.type,
|
|
60
73
|
"content-disposition": `${options.includes("download") ? "attachment; " : ""}name=${encodeURI(file.name)}`
|
|
61
74
|
});
|
|
@@ -71,7 +71,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
71
71
|
readonly icon: "paperclip";
|
|
72
72
|
readonly owned: "always";
|
|
73
73
|
readonly presets: readonly ["owned"];
|
|
74
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
74
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
75
75
|
readonly properties: {
|
|
76
76
|
readonly type: {
|
|
77
77
|
readonly type: "string";
|
|
@@ -122,7 +122,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
122
122
|
readonly icon: "paperclip";
|
|
123
123
|
readonly owned: "always";
|
|
124
124
|
readonly presets: readonly ["owned"];
|
|
125
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
125
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
126
126
|
readonly properties: {
|
|
127
127
|
readonly type: {
|
|
128
128
|
readonly type: "string";
|
|
@@ -179,7 +179,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
179
179
|
readonly icon: "paperclip";
|
|
180
180
|
readonly owned: "always";
|
|
181
181
|
readonly presets: readonly ["owned"];
|
|
182
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
182
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
183
183
|
readonly properties: {
|
|
184
184
|
readonly type: {
|
|
185
185
|
readonly type: "string";
|
|
@@ -233,6 +233,10 @@ export declare const file: Omit<import("@aeriajs/types").Collection<never>, "fun
|
|
|
233
233
|
readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
|
|
234
234
|
} & {
|
|
235
235
|
httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
|
|
236
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
237
|
+
readonly code: import("./download.js").DownloadError;
|
|
238
|
+
} & {
|
|
239
|
+
httpStatus: import("@aeriajs/types").HTTPStatus.RangeNotSatisfiable;
|
|
236
240
|
}> | import("fs").ReadStream>;
|
|
237
241
|
remove: (payload: import("@aeriajs/types").RemovePayload<import("@aeriajs/types").SchemaWithId<typeof description>>, context: import("@aeriajs/types").Context<typeof description>) => Promise<{
|
|
238
242
|
readonly _tag: "Result";
|
|
@@ -9,7 +9,7 @@ export declare const insert: (payload: {
|
|
|
9
9
|
readonly icon: "paperclip";
|
|
10
10
|
readonly owned: "always";
|
|
11
11
|
readonly presets: readonly ["owned"];
|
|
12
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
12
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
13
13
|
readonly properties: {
|
|
14
14
|
readonly type: {
|
|
15
15
|
readonly type: "string";
|
package/dist/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const collections: {
|
|
|
15
15
|
readonly icon: "paperclip";
|
|
16
16
|
readonly owned: "always";
|
|
17
17
|
readonly presets: readonly ["owned"];
|
|
18
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
18
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
19
19
|
readonly properties: {
|
|
20
20
|
readonly type: {
|
|
21
21
|
readonly type: "string";
|
|
@@ -66,7 +66,7 @@ export declare const collections: {
|
|
|
66
66
|
readonly icon: "paperclip";
|
|
67
67
|
readonly owned: "always";
|
|
68
68
|
readonly presets: readonly ["owned"];
|
|
69
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
69
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
70
70
|
readonly properties: {
|
|
71
71
|
readonly type: {
|
|
72
72
|
readonly type: "string";
|
|
@@ -123,7 +123,7 @@ export declare const collections: {
|
|
|
123
123
|
readonly icon: "paperclip";
|
|
124
124
|
readonly owned: "always";
|
|
125
125
|
readonly presets: readonly ["owned"];
|
|
126
|
-
readonly indexes: readonly ["name", "link", "type"];
|
|
126
|
+
readonly indexes: readonly ["name", "link", "type", "size"];
|
|
127
127
|
readonly properties: {
|
|
128
128
|
readonly type: {
|
|
129
129
|
readonly type: "string";
|
|
@@ -177,6 +177,10 @@ export declare const collections: {
|
|
|
177
177
|
readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
|
|
178
178
|
} & {
|
|
179
179
|
httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
|
|
180
|
+
}> | import("@aeriajs/types").Result.Error<{
|
|
181
|
+
readonly code: import("./collections/file/download.js").DownloadError;
|
|
182
|
+
} & {
|
|
183
|
+
httpStatus: import("@aeriajs/types").HTTPStatus.RangeNotSatisfiable;
|
|
180
184
|
}> | import("fs").ReadStream>;
|
|
181
185
|
remove: (payload: import("@aeriajs/types").RemovePayload<import("@aeriajs/types").SchemaWithId<typeof import("./collections/file/description.js").description>>, context: import("@aeriajs/types").Context<typeof import("./collections/file/description.js").description>) => Promise<{
|
|
182
186
|
readonly _tag: "Result";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/builtins",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.182",
|
|
4
4
|
"description": "## Installation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"mongodb": "^6.5.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@aeriajs/core": "^0.0.
|
|
49
|
-
"@aeriajs/common": "^0.0.
|
|
50
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
51
|
-
"@aeriajs/types": "^0.0.
|
|
52
|
-
"@aeriajs/validation": "^0.0.
|
|
48
|
+
"@aeriajs/core": "^0.0.182",
|
|
49
|
+
"@aeriajs/common": "^0.0.112",
|
|
50
|
+
"@aeriajs/entrypoint": "^0.0.115",
|
|
51
|
+
"@aeriajs/types": "^0.0.95",
|
|
52
|
+
"@aeriajs/validation": "^0.0.115"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"test": "echo skipping",
|