@aeriajs/builtins 0.0.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/LICENSE +19 -0
- package/README.md +6 -0
- package/dist/collections/file/description.d.ts +50 -0
- package/dist/collections/file/description.js +70 -0
- package/dist/collections/file/description.mjs +258 -0
- package/dist/collections/file/download.d.ts +13 -0
- package/dist/collections/file/download.js +78 -0
- package/dist/collections/file/download.mjs +232 -0
- package/dist/collections/file/index.d.ts +1183 -0
- package/dist/collections/file/index.js +49 -0
- package/dist/collections/file/index.mjs +46 -0
- package/dist/collections/file/insert.d.ts +7 -0
- package/dist/collections/file/insert.js +44 -0
- package/dist/collections/file/insert.mjs +246 -0
- package/dist/collections/file/remove.d.ts +3 -0
- package/dist/collections/file/remove.js +28 -0
- package/dist/collections/file/remove.mjs +184 -0
- package/dist/collections/file/removeAll.d.ts +3 -0
- package/dist/collections/file/removeAll.js +30 -0
- package/dist/collections/file/removeAll.mjs +194 -0
- package/dist/collections/index.d.ts +4 -0
- package/dist/collections/index.js +20 -0
- package/dist/collections/index.mjs +4 -0
- package/dist/collections/log/index.d.ts +458 -0
- package/dist/collections/log/index.js +46 -0
- package/dist/collections/log/index.mjs +45 -0
- package/dist/collections/resourceUsage/index.d.ts +57 -0
- package/dist/collections/resourceUsage/index.js +19 -0
- package/dist/collections/resourceUsage/index.mjs +16 -0
- package/dist/collections/user/activate.d.ts +10 -0
- package/dist/collections/user/activate.js +65 -0
- package/dist/collections/user/activate.mjs +247 -0
- package/dist/collections/user/authenticate.d.ts +24 -0
- package/dist/collections/user/authenticate.js +103 -0
- package/dist/collections/user/authenticate.mjs +398 -0
- package/dist/collections/user/createAccount.d.ts +101 -0
- package/dist/collections/user/createAccount.js +66 -0
- package/dist/collections/user/createAccount.mjs +219 -0
- package/dist/collections/user/description.d.ts +103 -0
- package/dist/collections/user/description.js +146 -0
- package/dist/collections/user/description.mjs +151 -0
- package/dist/collections/user/getActivationLink.d.ts +2 -0
- package/dist/collections/user/getActivationLink.js +15 -0
- package/dist/collections/user/getActivationLink.mjs +156 -0
- package/dist/collections/user/getInfo.d.ts +14 -0
- package/dist/collections/user/getInfo.js +39 -0
- package/dist/collections/user/getInfo.mjs +192 -0
- package/dist/collections/user/index.d.ts +3992 -0
- package/dist/collections/user/index.js +37 -0
- package/dist/collections/user/index.mjs +36 -0
- package/dist/collections/user/insert.d.ts +5 -0
- package/dist/collections/user/insert.js +35 -0
- package/dist/collections/user/insert.mjs +156 -0
- package/dist/functions/describe.d.ts +2 -0
- package/dist/functions/describe.js +54 -0
- package/dist/functions/describe.mjs +302 -0
- package/dist/functions/index.d.ts +1 -0
- package/dist/functions/index.js +17 -0
- package/dist/functions/index.mjs +1 -0
- package/dist/index.d.ts +5701 -0
- package/dist/index.js +39 -0
- package/dist/index.mjs +11 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2023 João Santos (joaosan177@gmail.com)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export declare const description: {
|
|
2
|
+
readonly $id: "file";
|
|
3
|
+
readonly owned: "always";
|
|
4
|
+
readonly presets: readonly ["owned"];
|
|
5
|
+
readonly indexes: readonly ["filename", "link", "mime"];
|
|
6
|
+
readonly properties: {
|
|
7
|
+
readonly mime: {
|
|
8
|
+
readonly type: "string";
|
|
9
|
+
};
|
|
10
|
+
readonly size: {
|
|
11
|
+
readonly type: "number";
|
|
12
|
+
};
|
|
13
|
+
readonly last_modified: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
readonly format: "date-time";
|
|
16
|
+
};
|
|
17
|
+
readonly filename: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
};
|
|
20
|
+
readonly absolute_path: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
};
|
|
23
|
+
readonly relative_path: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
readonly immutable: {
|
|
27
|
+
readonly type: "boolean";
|
|
28
|
+
};
|
|
29
|
+
readonly link: {
|
|
30
|
+
readonly getter: (value: any) => Promise<string>;
|
|
31
|
+
};
|
|
32
|
+
readonly download_link: {
|
|
33
|
+
readonly getter: (value: any) => Promise<string>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
readonly actions: {
|
|
37
|
+
readonly deleteAll: {
|
|
38
|
+
readonly name: "Remover";
|
|
39
|
+
readonly ask: true;
|
|
40
|
+
readonly selection: true;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
readonly individualActions: {
|
|
44
|
+
readonly remove: {
|
|
45
|
+
readonly name: "Remover";
|
|
46
|
+
readonly icon: "trash";
|
|
47
|
+
readonly ask: true;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.description = void 0;
|
|
4
|
+
const api_1 = require("@aeriajs/api");
|
|
5
|
+
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
6
|
+
const link = async (_id) => {
|
|
7
|
+
const config = await (0, entrypoint_1.getConfig)();
|
|
8
|
+
return `${config.apiUrl || ''}/file/${_id}`;
|
|
9
|
+
};
|
|
10
|
+
const timestamp = (lastModified) => lastModified
|
|
11
|
+
? new Date(lastModified).getTime()
|
|
12
|
+
: 'fresh';
|
|
13
|
+
exports.description = (0, api_1.defineDescription)({
|
|
14
|
+
$id: 'file',
|
|
15
|
+
owned: 'always',
|
|
16
|
+
presets: ['owned'],
|
|
17
|
+
indexes: [
|
|
18
|
+
'filename',
|
|
19
|
+
'link',
|
|
20
|
+
'mime',
|
|
21
|
+
],
|
|
22
|
+
properties: {
|
|
23
|
+
mime: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
},
|
|
26
|
+
size: {
|
|
27
|
+
type: 'number',
|
|
28
|
+
},
|
|
29
|
+
last_modified: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
format: 'date-time',
|
|
32
|
+
},
|
|
33
|
+
filename: {
|
|
34
|
+
type: 'string',
|
|
35
|
+
},
|
|
36
|
+
absolute_path: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
},
|
|
39
|
+
relative_path: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
42
|
+
immutable: {
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
},
|
|
45
|
+
link: {
|
|
46
|
+
getter: async (value) => {
|
|
47
|
+
return `${await link(value._id)}/${timestamp(value.last_modified)}`;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
download_link: {
|
|
51
|
+
getter: async (value) => {
|
|
52
|
+
return `${await link(value._id)}/download/${timestamp(value.last_modified)}`;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
actions: {
|
|
57
|
+
deleteAll: {
|
|
58
|
+
name: 'Remover',
|
|
59
|
+
ask: true,
|
|
60
|
+
selection: true,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
individualActions: {
|
|
64
|
+
remove: {
|
|
65
|
+
name: 'Remover',
|
|
66
|
+
icon: 'trash',
|
|
67
|
+
ask: true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g;
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
import { defineDescription } from "@aeriajs/api";
|
|
126
|
+
import { getConfig } from "@aeriajs/entrypoint";
|
|
127
|
+
var link = function() {
|
|
128
|
+
var _ref = _async_to_generator(function(_id) {
|
|
129
|
+
var config;
|
|
130
|
+
return _ts_generator(this, function(_state) {
|
|
131
|
+
switch(_state.label){
|
|
132
|
+
case 0:
|
|
133
|
+
return [
|
|
134
|
+
4,
|
|
135
|
+
getConfig()
|
|
136
|
+
];
|
|
137
|
+
case 1:
|
|
138
|
+
config = _state.sent();
|
|
139
|
+
return [
|
|
140
|
+
2,
|
|
141
|
+
"".concat(config.apiUrl || "", "/file/").concat(_id)
|
|
142
|
+
];
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
return function link(_id) {
|
|
147
|
+
return _ref.apply(this, arguments);
|
|
148
|
+
};
|
|
149
|
+
}();
|
|
150
|
+
var timestamp = function(lastModified) {
|
|
151
|
+
return lastModified ? new Date(lastModified).getTime() : "fresh";
|
|
152
|
+
};
|
|
153
|
+
export var description = defineDescription({
|
|
154
|
+
$id: "file",
|
|
155
|
+
owned: "always",
|
|
156
|
+
presets: [
|
|
157
|
+
"owned"
|
|
158
|
+
],
|
|
159
|
+
indexes: [
|
|
160
|
+
"filename",
|
|
161
|
+
"link",
|
|
162
|
+
"mime"
|
|
163
|
+
],
|
|
164
|
+
properties: {
|
|
165
|
+
mime: {
|
|
166
|
+
type: "string"
|
|
167
|
+
},
|
|
168
|
+
size: {
|
|
169
|
+
type: "number"
|
|
170
|
+
},
|
|
171
|
+
last_modified: {
|
|
172
|
+
type: "string",
|
|
173
|
+
format: "date-time"
|
|
174
|
+
},
|
|
175
|
+
filename: {
|
|
176
|
+
type: "string"
|
|
177
|
+
},
|
|
178
|
+
absolute_path: {
|
|
179
|
+
type: "string"
|
|
180
|
+
},
|
|
181
|
+
relative_path: {
|
|
182
|
+
type: "string"
|
|
183
|
+
},
|
|
184
|
+
immutable: {
|
|
185
|
+
type: "boolean"
|
|
186
|
+
},
|
|
187
|
+
link: {
|
|
188
|
+
getter: function() {
|
|
189
|
+
var _ref = _async_to_generator(function(value) {
|
|
190
|
+
var _, _1;
|
|
191
|
+
return _ts_generator(this, function(_state) {
|
|
192
|
+
switch(_state.label){
|
|
193
|
+
case 0:
|
|
194
|
+
_1 = (_ = "").concat;
|
|
195
|
+
return [
|
|
196
|
+
4,
|
|
197
|
+
link(value._id)
|
|
198
|
+
];
|
|
199
|
+
case 1:
|
|
200
|
+
return [
|
|
201
|
+
2,
|
|
202
|
+
_1.apply(_, [
|
|
203
|
+
_state.sent(),
|
|
204
|
+
"/"
|
|
205
|
+
]).concat(timestamp(value.last_modified))
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
return function(value) {
|
|
211
|
+
return _ref.apply(this, arguments);
|
|
212
|
+
};
|
|
213
|
+
}()
|
|
214
|
+
},
|
|
215
|
+
download_link: {
|
|
216
|
+
getter: function() {
|
|
217
|
+
var _ref = _async_to_generator(function(value) {
|
|
218
|
+
var _, _1;
|
|
219
|
+
return _ts_generator(this, function(_state) {
|
|
220
|
+
switch(_state.label){
|
|
221
|
+
case 0:
|
|
222
|
+
_1 = (_ = "").concat;
|
|
223
|
+
return [
|
|
224
|
+
4,
|
|
225
|
+
link(value._id)
|
|
226
|
+
];
|
|
227
|
+
case 1:
|
|
228
|
+
return [
|
|
229
|
+
2,
|
|
230
|
+
_1.apply(_, [
|
|
231
|
+
_state.sent(),
|
|
232
|
+
"/download/"
|
|
233
|
+
]).concat(timestamp(value.last_modified))
|
|
234
|
+
];
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
return function(value) {
|
|
239
|
+
return _ref.apply(this, arguments);
|
|
240
|
+
};
|
|
241
|
+
}()
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
actions: {
|
|
245
|
+
deleteAll: {
|
|
246
|
+
name: "Remover",
|
|
247
|
+
ask: true,
|
|
248
|
+
selection: true
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
individualActions: {
|
|
252
|
+
remove: {
|
|
253
|
+
name: "Remover",
|
|
254
|
+
icon: "trash",
|
|
255
|
+
ask: true
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Context } from '@aeriajs/types';
|
|
3
|
+
import type { description } from './description.js';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
export declare enum FileReadError {
|
|
6
|
+
DocumentNotFound = "DOCUMENT_NOT_FOUND",
|
|
7
|
+
FileNotFound = "FILE_NOT_FOUND"
|
|
8
|
+
}
|
|
9
|
+
export declare const download: (payload: {
|
|
10
|
+
fileId: string;
|
|
11
|
+
options: readonly ('picture' | 'download')[];
|
|
12
|
+
noHeaders?: boolean;
|
|
13
|
+
}, context: Context<typeof description>) => Promise<import("@aeriajs/types").Left<FileReadError.DocumentNotFound> | import("@aeriajs/types").Left<FileReadError.FileNotFound> | fs.ReadStream>;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.download = exports.FileReadError = void 0;
|
|
7
|
+
const mongodb_1 = require("mongodb");
|
|
8
|
+
const common_1 = require("@aeriajs/common");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
var FileReadError;
|
|
11
|
+
(function (FileReadError) {
|
|
12
|
+
FileReadError["DocumentNotFound"] = "DOCUMENT_NOT_FOUND";
|
|
13
|
+
FileReadError["FileNotFound"] = "FILE_NOT_FOUND";
|
|
14
|
+
})(FileReadError || (exports.FileReadError = FileReadError = {}));
|
|
15
|
+
const download = async (payload, context) => {
|
|
16
|
+
const { fileId, options = [] } = payload;
|
|
17
|
+
const file = await context.collection.model.findOne({
|
|
18
|
+
_id: new mongodb_1.ObjectId(fileId),
|
|
19
|
+
}, {
|
|
20
|
+
projection: {
|
|
21
|
+
absolute_path: 1,
|
|
22
|
+
filename: 1,
|
|
23
|
+
mime: 1,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (!file) {
|
|
27
|
+
if (!payload.noHeaders) {
|
|
28
|
+
context.response.writeHead(404, {
|
|
29
|
+
'content-type': 'application/json',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return (0, common_1.left)(FileReadError.DocumentNotFound);
|
|
33
|
+
}
|
|
34
|
+
let stat;
|
|
35
|
+
try {
|
|
36
|
+
stat = await fs_1.default.promises.stat(file.absolute_path);
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
context.response.writeHead(404, {
|
|
40
|
+
'content-type': 'application/json',
|
|
41
|
+
});
|
|
42
|
+
return (0, common_1.left)(FileReadError.FileNotFound);
|
|
43
|
+
}
|
|
44
|
+
const range = context.request.headers.range;
|
|
45
|
+
if (range) {
|
|
46
|
+
const parts = range.replace(/bytes=/, '').split('-');
|
|
47
|
+
const start = parseInt(parts[0]);
|
|
48
|
+
const end = parts[1]
|
|
49
|
+
? parseInt(parts[1])
|
|
50
|
+
: stat.size - 1;
|
|
51
|
+
const chunkSize = (end - start) + 1;
|
|
52
|
+
if (!payload.noHeaders) {
|
|
53
|
+
context.response.writeHead(206, {
|
|
54
|
+
'accept-ranges': 'bytes',
|
|
55
|
+
'content-range': `bytes ${start}-${end}/${stat.size}`,
|
|
56
|
+
'content-length': chunkSize,
|
|
57
|
+
'content-type': file.mime,
|
|
58
|
+
'content-disposition': `${options.includes('download')
|
|
59
|
+
? 'attachment; '
|
|
60
|
+
: ''}filename=${encodeURI(file.filename)}`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return fs_1.default.createReadStream(file.absolute_path, {
|
|
64
|
+
start,
|
|
65
|
+
end,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!payload.noHeaders) {
|
|
69
|
+
context.response.writeHead(200, {
|
|
70
|
+
'content-type': file.mime,
|
|
71
|
+
'content-disposition': `${options.includes('download')
|
|
72
|
+
? 'attachment; '
|
|
73
|
+
: ''}filename=${encodeURI(file.filename)}`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return fs_1.default.createReadStream(file.absolute_path);
|
|
77
|
+
};
|
|
78
|
+
exports.download = download;
|