@webda/fs 4.0.0-beta.3
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 +166 -0
- package/README.md +130 -0
- package/lib/filebinary.service.d.ts +184 -0
- package/lib/filebinary.service.d.ts.map +1 -0
- package/lib/filebinary.service.js +467 -0
- package/lib/filebinary.service.js.map +1 -0
- package/lib/filequeue.service.d.ts +62 -0
- package/lib/filequeue.service.d.ts.map +1 -0
- package/lib/filequeue.service.js +138 -0
- package/lib/filequeue.service.js.map +1 -0
- package/lib/filestore.service.d.ts +133 -0
- package/lib/filestore.service.d.ts.map +1 -0
- package/lib/filestore.service.js +423 -0
- package/lib/filestore.service.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/socketpubsub.service.d.ts +150 -0
- package/lib/socketpubsub.service.d.ts.map +1 -0
- package/lib/socketpubsub.service.js +348 -0
- package/lib/socketpubsub.service.js.map +1 -0
- package/package.json +50 -0
- package/webda.module.json +304 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
import * as fs from "fs";
|
|
36
|
+
import { join } from "path";
|
|
37
|
+
import { BinaryNotFoundError, CloudBinary, CloudBinaryParameters, Inject, MemoryBinaryFile, WebContext, WebdaError } from "@webda/core";
|
|
38
|
+
import { useModelId } from "@webda/core";
|
|
39
|
+
/** Configuration parameters for the filesystem-backed binary storage service. */
|
|
40
|
+
export class FileBinaryParameters extends CloudBinaryParameters {
|
|
41
|
+
/**
|
|
42
|
+
* Define the folder to store objects in
|
|
43
|
+
*/
|
|
44
|
+
folder;
|
|
45
|
+
/**
|
|
46
|
+
* Maximum size to handle
|
|
47
|
+
* @default 10Mb
|
|
48
|
+
*/
|
|
49
|
+
maxSize;
|
|
50
|
+
/**
|
|
51
|
+
* URL to use for direct download
|
|
52
|
+
*/
|
|
53
|
+
url;
|
|
54
|
+
/**
|
|
55
|
+
* Load and normalize parameters, ensuring the folder path has a trailing slash.
|
|
56
|
+
*
|
|
57
|
+
* @param params - raw parameter values
|
|
58
|
+
* @returns this instance for chaining
|
|
59
|
+
*/
|
|
60
|
+
load(params) {
|
|
61
|
+
super.load(params);
|
|
62
|
+
if (this.folder && !this.folder.endsWith("/")) {
|
|
63
|
+
this.folder += "/";
|
|
64
|
+
}
|
|
65
|
+
this.maxSize ??= 10 * 1024 * 1024;
|
|
66
|
+
// Remove trailing /
|
|
67
|
+
if (this.url && this.url.endsWith("/")) {
|
|
68
|
+
this.url = this.url.substring(0, this.url.length - 1);
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* FileBinary handles the storage of binary on a hard drive
|
|
75
|
+
*
|
|
76
|
+
* The structure used for now is
|
|
77
|
+
* /folder/{hash}/data
|
|
78
|
+
* /folder/{hash}/{targetStore}_{uuid}
|
|
79
|
+
* /folder/{hash}/challenge
|
|
80
|
+
*
|
|
81
|
+
* It takes one parameter
|
|
82
|
+
* folder: "path"
|
|
83
|
+
*
|
|
84
|
+
* See Binary the general interface
|
|
85
|
+
* @category CoreServices
|
|
86
|
+
* @WebdaModda
|
|
87
|
+
*/
|
|
88
|
+
let FileBinary = (() => {
|
|
89
|
+
let _classSuper = CloudBinary;
|
|
90
|
+
let _cryptoService_decorators;
|
|
91
|
+
let _cryptoService_initializers = [];
|
|
92
|
+
let _cryptoService_extraInitializers = [];
|
|
93
|
+
return class FileBinary extends _classSuper {
|
|
94
|
+
static {
|
|
95
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
96
|
+
_cryptoService_decorators = [Inject("CryptoService")];
|
|
97
|
+
__esDecorate(null, null, _cryptoService_decorators, { kind: "field", name: "cryptoService", static: false, private: false, access: { has: obj => "cryptoService" in obj, get: obj => obj.cryptoService, set: (obj, value) => { obj.cryptoService = value; } }, metadata: _metadata }, _cryptoService_initializers, _cryptoService_extraInitializers);
|
|
98
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Used for hmac
|
|
102
|
+
*/
|
|
103
|
+
cryptoService = __runInitializers(this, _cryptoService_initializers, void 0);
|
|
104
|
+
/**
|
|
105
|
+
* Load parameters
|
|
106
|
+
*
|
|
107
|
+
* @param params - raw parameter values
|
|
108
|
+
* @returns the loaded parameters
|
|
109
|
+
*/
|
|
110
|
+
loadParameters(params) {
|
|
111
|
+
return new FileBinaryParameters().load(params);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create the storage folder if needed
|
|
115
|
+
*/
|
|
116
|
+
computeParameters() {
|
|
117
|
+
super.computeParameters();
|
|
118
|
+
if (!fs.existsSync(this.parameters.folder)) {
|
|
119
|
+
fs.mkdirSync(this.parameters.folder, { recursive: true });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Register download/upload routes if a public URL is configured.
|
|
124
|
+
*
|
|
125
|
+
* Routes depend on the runtime `parameters.url` + content hash, so they're
|
|
126
|
+
* registered programmatically rather than via `@Route`.
|
|
127
|
+
*
|
|
128
|
+
* @returns this for chaining
|
|
129
|
+
*/
|
|
130
|
+
async init() {
|
|
131
|
+
await super.init();
|
|
132
|
+
// We do not want to expose by default
|
|
133
|
+
if (this.parameters.url === undefined) {
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
// Will redirect to this URL for direct download
|
|
137
|
+
let url = this.parameters.url + "/download/data/{hash}{?token,content-disposition,content-type}";
|
|
138
|
+
const name = this.getOperationName();
|
|
139
|
+
this.addRoute(url, ["GET"], this.downloadBinaryLink, {
|
|
140
|
+
put: {
|
|
141
|
+
operationId: `get${name}Binary`,
|
|
142
|
+
description: "Download a binary to an object after challenge",
|
|
143
|
+
summary: "Download a binary",
|
|
144
|
+
responses: {
|
|
145
|
+
"200": {
|
|
146
|
+
description: "Content of binary"
|
|
147
|
+
},
|
|
148
|
+
"403": {
|
|
149
|
+
description: "Wrong hash"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
url = this.parameters.url + "/upload/data/{hash}{?token}";
|
|
155
|
+
this.addRoute(url, ["PUT"], this.storeBinary, {
|
|
156
|
+
put: {
|
|
157
|
+
operationId: `put${name}Binary`,
|
|
158
|
+
description: "Upload a binary to an object after challenge",
|
|
159
|
+
summary: "Upload a binary",
|
|
160
|
+
responses: {
|
|
161
|
+
"204": {
|
|
162
|
+
description: ""
|
|
163
|
+
},
|
|
164
|
+
"400": {
|
|
165
|
+
description: "Wrong hash"
|
|
166
|
+
},
|
|
167
|
+
"404": {
|
|
168
|
+
description: "Object does not exist or attachment does not exist"
|
|
169
|
+
},
|
|
170
|
+
"412": {
|
|
171
|
+
description: "Provided hash does not match"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Download a binary with a challenge
|
|
180
|
+
*
|
|
181
|
+
* @param ctx - the web context
|
|
182
|
+
*/
|
|
183
|
+
async downloadBinaryLink(ctx) {
|
|
184
|
+
const { hash } = ctx.getParameters();
|
|
185
|
+
// Verify token
|
|
186
|
+
try {
|
|
187
|
+
const dt = await this.cryptoService.jwtVerify(ctx.parameter("token"));
|
|
188
|
+
if (dt.hash !== hash) {
|
|
189
|
+
throw new WebdaError.Forbidden("Wrong hash");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch (err) {
|
|
193
|
+
throw new WebdaError.Forbidden("Incorrect JWT");
|
|
194
|
+
}
|
|
195
|
+
ctx.writeHead(200, {
|
|
196
|
+
"content-disposition": ctx.parameter("content-disposition"),
|
|
197
|
+
"content-type": ctx.parameter("content-type")
|
|
198
|
+
});
|
|
199
|
+
const map = await this.get({ hash });
|
|
200
|
+
// Fake a binary map for this case
|
|
201
|
+
return new Promise(async (resolve, reject) => {
|
|
202
|
+
const stream = await ctx.getOutputStream();
|
|
203
|
+
stream.on("error", reject).on("finish", resolve);
|
|
204
|
+
map.pipe(stream);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @override
|
|
209
|
+
*/
|
|
210
|
+
async _get(info) {
|
|
211
|
+
const path = this._getPath(info.hash, "data");
|
|
212
|
+
if (!fs.existsSync(path)) {
|
|
213
|
+
throw new BinaryNotFoundError(info.hash, this.getName());
|
|
214
|
+
}
|
|
215
|
+
return fs.createReadStream(path);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get signed url to download an element
|
|
219
|
+
*
|
|
220
|
+
* @param map - the binary map
|
|
221
|
+
* @param expires - expiration time in seconds
|
|
222
|
+
* @param context - the web context
|
|
223
|
+
* @returns the signed download URL
|
|
224
|
+
*/
|
|
225
|
+
async getSignedUrlFromMap(map, expires, context) {
|
|
226
|
+
return `${context
|
|
227
|
+
.getHttpContext()
|
|
228
|
+
.getAbsoluteUrl(this.parameters.url + "/download/data/" + map.hash)}?token=${await this.getToken(map.hash, "GET", expires)}&content-type=${map.mimetype}&content-disposition=attachment`;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get storage path for a hash
|
|
232
|
+
*
|
|
233
|
+
* @param hash - the content hash
|
|
234
|
+
* @param postfix - optional path suffix
|
|
235
|
+
* @returns the filesystem path
|
|
236
|
+
*/
|
|
237
|
+
_getPath(hash, postfix = undefined) {
|
|
238
|
+
if (postfix === undefined) {
|
|
239
|
+
return this.parameters.folder + hash;
|
|
240
|
+
}
|
|
241
|
+
return this.parameters.folder + hash + "/" + postfix;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a file if it does not already exist, using the given permission mode.
|
|
245
|
+
*
|
|
246
|
+
* @param filePath - path of the file to create
|
|
247
|
+
* @param mode - file permission mode
|
|
248
|
+
*/
|
|
249
|
+
_touch(filePath, mode = 0o600) {
|
|
250
|
+
try {
|
|
251
|
+
const fd = fs.openSync(filePath, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_RDWR, mode);
|
|
252
|
+
fs.closeSync(fd);
|
|
253
|
+
}
|
|
254
|
+
catch (e) {
|
|
255
|
+
// file existed
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Get token for action
|
|
260
|
+
*
|
|
261
|
+
* @param hash - the content hash
|
|
262
|
+
* @param method - HTTP method (PUT or GET)
|
|
263
|
+
* @param expiresIn - token TTL in seconds
|
|
264
|
+
* @returns the signed JWT token
|
|
265
|
+
*/
|
|
266
|
+
async getToken(hash, method, expiresIn = 60) {
|
|
267
|
+
return this.cryptoService.jwtSign({ hash, method }, {
|
|
268
|
+
expiresIn
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get put URL
|
|
273
|
+
*
|
|
274
|
+
* @param ctx - the operation context
|
|
275
|
+
* @returns the upload URL
|
|
276
|
+
*/
|
|
277
|
+
async getPutUrl(ctx) {
|
|
278
|
+
const body = await ctx.getInput();
|
|
279
|
+
const token = await this.getToken(body.hash, "PUT");
|
|
280
|
+
if (ctx instanceof WebContext) {
|
|
281
|
+
return ctx.getHttpContext().getAbsoluteUrl(this.parameters.url + "/upload/data/" + body.hash + `?token=${token}`);
|
|
282
|
+
}
|
|
283
|
+
return this.parameters.url + "/upload/data/" + body.hash + `?token=${token}`;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Will give you the redirect url
|
|
287
|
+
*
|
|
288
|
+
* @param object - the model instance
|
|
289
|
+
* @param attribute - the binary attribute name
|
|
290
|
+
* @param info - optional binary file info
|
|
291
|
+
* @param context - the operation context
|
|
292
|
+
* @returns the redirect URL and method, or undefined if already stored
|
|
293
|
+
*/
|
|
294
|
+
async putRedirectUrl(object, attribute, info, context) {
|
|
295
|
+
info ??= await context.getInput();
|
|
296
|
+
const result = { url: await this.getPutUrl(context), method: "PUT" };
|
|
297
|
+
const marker = `${useModelId(object.constructor)}_${object.getUUID()}_${attribute}`;
|
|
298
|
+
// Get the target object to add the mapping
|
|
299
|
+
await this.uploadSuccess(object, attribute, info);
|
|
300
|
+
if (fs.existsSync(this._getPath(info.hash, marker))) {
|
|
301
|
+
if (!fs.existsSync(this._getPath(info.hash, "data"))) {
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (!fs.existsSync(this._getPath(info.hash))) {
|
|
307
|
+
fs.mkdirSync(this._getPath(info.hash));
|
|
308
|
+
}
|
|
309
|
+
this._touch(this._getPath(info.hash, marker));
|
|
310
|
+
if (this.challenge(info.hash, info.challenge)) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Store the binary sent
|
|
317
|
+
*
|
|
318
|
+
* @param ctx - the web context
|
|
319
|
+
*/
|
|
320
|
+
async storeBinary(ctx) {
|
|
321
|
+
const body = await ctx.getHttpContext().getRawBody(this.parameters.maxSize);
|
|
322
|
+
const result = await new MemoryBinaryFile(body, {
|
|
323
|
+
mimetype: (ctx.getHttpContext().getUniqueHeader("content-type") || "application/json").split(";")[0],
|
|
324
|
+
name: "",
|
|
325
|
+
size: parseInt(ctx.getHttpContext().getUniqueHeader("content-length"))
|
|
326
|
+
}).getHashes();
|
|
327
|
+
if (ctx.parameter("hash") !== result.hash) {
|
|
328
|
+
this.log("WARN", "Request hash differ", ctx.parameter("hash"), "!==", result.hash);
|
|
329
|
+
throw new WebdaError.BadRequest("Request hash differ");
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
const dt = await this.cryptoService.jwtVerify(ctx.parameter("token"));
|
|
333
|
+
if (dt.hash !== result.hash) {
|
|
334
|
+
this.log("WARN", "JWT hash differ", ctx.parameter("hash"), "!==", result.hash);
|
|
335
|
+
throw new WebdaError.Forbidden("JWT hash differ");
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
catch (err) {
|
|
339
|
+
this.log("WARN", "Invalid JWT token");
|
|
340
|
+
throw new WebdaError.Forbidden("Invalid JWT token");
|
|
341
|
+
}
|
|
342
|
+
if (!fs.existsSync(this._getPath(result.hash))) {
|
|
343
|
+
throw new WebdaError.PreconditionFailed("No folder for hash " + result.hash);
|
|
344
|
+
}
|
|
345
|
+
const path = this._getPath(result.hash, "data");
|
|
346
|
+
if (!fs.existsSync(path)) {
|
|
347
|
+
fs.writeFileSync(path, body);
|
|
348
|
+
}
|
|
349
|
+
this._touch(this._getPath(result.hash, "_" + result.challenge));
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* @override
|
|
353
|
+
*/
|
|
354
|
+
async getUsageCount(hash) {
|
|
355
|
+
const path = this._getPath(hash);
|
|
356
|
+
if (!fs.existsSync(path)) {
|
|
357
|
+
return 0;
|
|
358
|
+
}
|
|
359
|
+
const files = fs.readdirSync(path);
|
|
360
|
+
return files.length - 2;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Delete any usage marker and hash
|
|
364
|
+
*
|
|
365
|
+
* @param hash - the content hash to clean
|
|
366
|
+
*/
|
|
367
|
+
async _cleanHash(hash) {
|
|
368
|
+
const p = this._getPath(hash);
|
|
369
|
+
if (!fs.existsSync(p))
|
|
370
|
+
return;
|
|
371
|
+
try {
|
|
372
|
+
const files = fs.readdirSync(p);
|
|
373
|
+
files.forEach(file => fs.unlinkSync(join(p, file)));
|
|
374
|
+
fs.rmdirSync(p);
|
|
375
|
+
}
|
|
376
|
+
catch (err) { }
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* @override
|
|
380
|
+
*/
|
|
381
|
+
async _cleanUsage(hash, uuid, attribute) {
|
|
382
|
+
const p = this._getPath(hash);
|
|
383
|
+
if (!fs.existsSync(p))
|
|
384
|
+
return;
|
|
385
|
+
uuid = uuid.startsWith("_") ? uuid : `_${uuid}`;
|
|
386
|
+
const files = fs.readdirSync(p);
|
|
387
|
+
files
|
|
388
|
+
.filter(f => f.endsWith(attribute ? `_${attribute}${uuid}` : `${uuid}`))
|
|
389
|
+
.forEach(f => fs.unlinkSync(this._getPath(hash, f)));
|
|
390
|
+
if (files.length == 3) {
|
|
391
|
+
await this._cleanHash(hash);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* @override
|
|
396
|
+
*/
|
|
397
|
+
async delete(object, property, index) {
|
|
398
|
+
const hash = (index !== undefined ? object[property][index] : object[property]).hash;
|
|
399
|
+
await this.deleteSuccess(object, property, index);
|
|
400
|
+
await this._cleanUsage(hash, object.getUUID(), property);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Verify that a binary with the given hash exists and contains the expected challenge marker.
|
|
404
|
+
*
|
|
405
|
+
* @param hash - the content hash
|
|
406
|
+
* @param challenge - the challenge string
|
|
407
|
+
* @returns true if the challenge marker exists
|
|
408
|
+
*/
|
|
409
|
+
challenge(hash, challenge) {
|
|
410
|
+
const path = this._getPath(hash);
|
|
411
|
+
return fs.existsSync(path) && fs.existsSync(`${path}/_${challenge}`);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* @override
|
|
415
|
+
*/
|
|
416
|
+
async cascadeDelete(info, uuid) {
|
|
417
|
+
return this._cleanUsage(info.hash, uuid);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Write a binary file's stream to the local filesystem under its content-hash directory.
|
|
421
|
+
*
|
|
422
|
+
* @param file - the binary file to store
|
|
423
|
+
* @param object - the model instance
|
|
424
|
+
* @param attribute - the binary attribute name
|
|
425
|
+
*/
|
|
426
|
+
async _store(file, object, attribute) {
|
|
427
|
+
fs.mkdirSync(this._getPath(file.hash));
|
|
428
|
+
const map = await file.get();
|
|
429
|
+
await new Promise((resolve, reject) => {
|
|
430
|
+
map
|
|
431
|
+
.pipe(fs.createWriteStream(this._getPath(file.hash, "data")))
|
|
432
|
+
.on("error", reject)
|
|
433
|
+
.on("finish", resolve);
|
|
434
|
+
});
|
|
435
|
+
this._touch(this._getPath(file.hash, "_" + file.challenge));
|
|
436
|
+
this._touch(this._getPath(file.hash, `${useModelId(object.constructor)}_${attribute}_${object.getUUID()}`));
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* @override
|
|
440
|
+
*/
|
|
441
|
+
async store(object, property, file) {
|
|
442
|
+
await file.getHashes();
|
|
443
|
+
const storeName = useModelId(object.constructor);
|
|
444
|
+
const fileInfo = file.toBinaryFileInfo();
|
|
445
|
+
this.checkMap(object, property);
|
|
446
|
+
if (fs.existsSync(this._getPath(file.hash))) {
|
|
447
|
+
this._touch(this._getPath(file.hash, `${storeName}_${property}_${object.getUUID()}`));
|
|
448
|
+
await this.uploadSuccess(object, property, fileInfo);
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
await this._store(file, object, property);
|
|
452
|
+
await this.uploadSuccess(object, property, fileInfo);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Clean all data
|
|
456
|
+
*/
|
|
457
|
+
async ___cleanData() {
|
|
458
|
+
(await import("fs-extra")).emptyDirSync(this.parameters.folder);
|
|
459
|
+
}
|
|
460
|
+
constructor() {
|
|
461
|
+
super(...arguments);
|
|
462
|
+
__runInitializers(this, _cryptoService_extraInitializers);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
})();
|
|
466
|
+
export { FileBinary };
|
|
467
|
+
//# sourceMappingURL=filebinary.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filebinary.service.js","sourceRoot":"","sources":["../src/filebinary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,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAC1D,OAAO;YACT,CAAC;YACD,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YAC1C,MAAM,IAAI,CAAC,aAAa,CAAM,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5D,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,YAAY;YAChB,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAClE,CAAC;;;;;;;SAxYU,UAAU"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Queue, QueueParameters } from "@webda/core";
|
|
2
|
+
import type { MessageReceipt } from "@webda/core";
|
|
3
|
+
/** Configuration parameters for the filesystem-backed FIFO queue. */
|
|
4
|
+
export declare class FileQueueParameters extends QueueParameters {
|
|
5
|
+
/**
|
|
6
|
+
* Number of seconds before dropping message
|
|
7
|
+
*
|
|
8
|
+
* @default 30
|
|
9
|
+
*/
|
|
10
|
+
expire?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Where to store the queue
|
|
13
|
+
*/
|
|
14
|
+
folder: string;
|
|
15
|
+
/** Set default expiration to 30 seconds and convert to milliseconds. */
|
|
16
|
+
default(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* FIFO Queue on filesystem
|
|
20
|
+
* @category CoreServices
|
|
21
|
+
* @WebdaModda
|
|
22
|
+
*/
|
|
23
|
+
export declare class FileQueue<T = any, K extends FileQueueParameters = FileQueueParameters> extends Queue<T, K> {
|
|
24
|
+
/**
|
|
25
|
+
* @override
|
|
26
|
+
*/
|
|
27
|
+
loadParameters(params: any): K;
|
|
28
|
+
/**
|
|
29
|
+
* Create the storage folder if does not exist
|
|
30
|
+
*/
|
|
31
|
+
computeParameters(): void;
|
|
32
|
+
/**
|
|
33
|
+
* @override
|
|
34
|
+
*/
|
|
35
|
+
size(): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Return file
|
|
38
|
+
*
|
|
39
|
+
* @param uid - the message unique identifier
|
|
40
|
+
* @returns the file path
|
|
41
|
+
*/
|
|
42
|
+
getFile(uid: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* @override
|
|
45
|
+
*/
|
|
46
|
+
sendMessage(params: any): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* @override
|
|
49
|
+
*/
|
|
50
|
+
receiveMessage<L>(proto?: {
|
|
51
|
+
new (): L;
|
|
52
|
+
}): Promise<MessageReceipt<L>[]>;
|
|
53
|
+
/**
|
|
54
|
+
* @override
|
|
55
|
+
*/
|
|
56
|
+
deleteMessage(receipt: any): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* @inheritdoc
|
|
59
|
+
*/
|
|
60
|
+
__clean(): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=filequeue.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filequeue.service.d.ts","sourceRoot":"","sources":["../src/filequeue.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,qEAAqE;AACrE,qBAAa,mBAAoB,SAAQ,eAAe;IACtD;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf,wEAAwE;IACxE,OAAO,SAGN;CACF;AAED;;;;GAIG;AACH,qBAAa,SAAS,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CAAE,SAAQ,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;IACtG;;OAEG;IACH,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAE7B;IAED;;OAEG;IACH,iBAAiB,SAMhB;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAE5B;IAED;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3B;IAED;;OAEG;IACG,WAAW,CAAC,MAAM,KAAA,iBAQvB;IAED;;OAEG;IACG,cAAc,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAyC3E;IAED;;OAEG;IACG,aAAa,CAAC,OAAO,KAAA,iBAQ1B;IAED;;OAEG;IACG,OAAO,kBAEZ;CACF"}
|