@webda/core 2.0.0-beta.2 → 2.0.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/application.d.ts +5 -21
- package/lib/application.js +71 -84
- package/lib/application.js.map +1 -1
- package/lib/application.spec.js +121 -140
- package/lib/application.spec.js.map +1 -1
- package/lib/core.d.ts +44 -45
- package/lib/core.js +239 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +326 -391
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -45
- package/lib/index.js +54 -67
- package/lib/index.js.map +1 -1
- package/lib/models/aclmodel.d.ts +2 -2
- package/lib/models/aclmodel.js +63 -90
- package/lib/models/aclmodel.js.map +1 -1
- package/lib/models/aclmodel.spec.js +128 -151
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +39 -17
- package/lib/models/coremodel.js +160 -117
- package/lib/models/coremodel.js.map +1 -1
- package/lib/models/coremodel.spec.js +143 -107
- package/lib/models/coremodel.spec.js.map +1 -1
- package/lib/models/deployment.js +1 -2
- package/lib/models/ident.d.ts +3 -3
- package/lib/models/ident.js +4 -9
- package/lib/models/ident.js.map +1 -1
- package/lib/models/ident.spec.js +9 -11
- package/lib/models/ident.spec.js.map +1 -1
- package/lib/models/ownermodel.d.ts +2 -2
- package/lib/models/ownermodel.js +39 -62
- package/lib/models/ownermodel.js.map +1 -1
- package/lib/models/ownermodel.spec.js +126 -166
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +2 -2
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -61
- package/lib/models/rolemodel.spec.js.map +1 -1
- package/lib/models/user.d.ts +9 -9
- package/lib/models/user.js +3 -8
- package/lib/models/user.js.map +1 -1
- package/lib/models/user.spec.js +14 -16
- package/lib/models/user.spec.js.map +1 -1
- package/lib/queues/filequeue.d.ts +2 -2
- package/lib/queues/filequeue.js +72 -93
- package/lib/queues/filequeue.js.map +1 -1
- package/lib/queues/filequeue.spec.js +53 -70
- package/lib/queues/filequeue.spec.js.map +1 -1
- package/lib/queues/memoryqueue.d.ts +2 -2
- package/lib/queues/memoryqueue.js +37 -61
- package/lib/queues/memoryqueue.js.map +1 -1
- package/lib/queues/memoryqueue.spec.js +142 -165
- package/lib/queues/memoryqueue.spec.js.map +1 -1
- package/lib/queues/pubsubservice.d.ts +2 -2
- package/lib/queues/pubsubservice.js +3 -7
- package/lib/queues/pubsubservice.js.map +1 -1
- package/lib/queues/queue.spec.d.ts +1 -1
- package/lib/queues/queue.spec.js +42 -56
- package/lib/queues/queue.spec.js.map +1 -1
- package/lib/queues/queueservice.d.ts +4 -4
- package/lib/queues/queueservice.js +52 -67
- package/lib/queues/queueservice.js.map +1 -1
- package/lib/router.d.ts +3 -3
- package/lib/router.js +46 -47
- package/lib/router.js.map +1 -1
- package/lib/router.spec.js +64 -61
- package/lib/router.spec.js.map +1 -1
- package/lib/services/asyncevents.d.ts +2 -2
- package/lib/services/asyncevents.js +44 -64
- package/lib/services/asyncevents.js.map +1 -1
- package/lib/services/asyncevents.spec.js +81 -98
- package/lib/services/asyncevents.spec.js.map +1 -1
- package/lib/services/authentication.d.ts +28 -19
- package/lib/services/authentication.js +542 -574
- package/lib/services/authentication.js.map +1 -1
- package/lib/services/authentication.spec.js +411 -447
- package/lib/services/authentication.spec.js.map +1 -1
- package/lib/services/binary.d.ts +9 -7
- package/lib/services/binary.js +213 -245
- package/lib/services/binary.js.map +1 -1
- package/lib/services/binary.spec.d.ts +3 -3
- package/lib/services/binary.spec.js +390 -443
- package/lib/services/binary.spec.js.map +1 -1
- package/lib/services/cloudbinary.d.ts +3 -3
- package/lib/services/cloudbinary.js +45 -70
- package/lib/services/cloudbinary.js.map +1 -1
- package/lib/services/cloudbinary.spec.d.ts +3 -3
- package/lib/services/cloudbinary.spec.js +133 -162
- package/lib/services/cloudbinary.spec.js.map +1 -1
- package/lib/services/configuration.d.ts +6 -3
- package/lib/services/configuration.js +78 -103
- package/lib/services/configuration.js.map +1 -1
- package/lib/services/configuration.spec.js +63 -83
- package/lib/services/configuration.spec.js.map +1 -1
- package/lib/services/cron.d.ts +3 -2
- package/lib/services/cron.js +9 -13
- package/lib/services/cron.js.map +1 -1
- package/lib/services/cron.spec.js +18 -21
- package/lib/services/cron.spec.js.map +1 -1
- package/lib/services/cryptoservice.d.ts +258 -0
- package/lib/services/cryptoservice.js +312 -0
- package/lib/services/cryptoservice.js.map +1 -0
- package/lib/services/cryptoservice.spec.d.ts +1 -0
- package/lib/services/cryptoservice.spec.js +137 -0
- package/lib/services/cryptoservice.spec.js.map +1 -0
- package/lib/services/debugmailer.d.ts +1 -1
- package/lib/services/debugmailer.js +13 -34
- package/lib/services/debugmailer.js.map +1 -1
- package/lib/services/debugmailer.spec.js +16 -29
- package/lib/services/debugmailer.spec.js.map +1 -1
- package/lib/services/echo.d.ts +2 -2
- package/lib/services/echo.js +15 -31
- package/lib/services/echo.js.map +1 -1
- package/lib/services/echo.spec.js +27 -40
- package/lib/services/echo.spec.js.map +1 -1
- package/lib/services/filebinary.d.ts +10 -5
- package/lib/services/filebinary.js +171 -205
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -117
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +2 -2
- package/lib/services/fileconfiguration.js +25 -43
- package/lib/services/fileconfiguration.js.map +1 -1
- package/lib/services/fileconfiguration.spec.js +79 -109
- package/lib/services/fileconfiguration.spec.js.map +1 -1
- package/lib/services/invitationservice.d.ts +10 -10
- package/lib/services/invitationservice.js +275 -313
- package/lib/services/invitationservice.js.map +1 -1
- package/lib/services/invitationservice.spec.js +443 -449
- package/lib/services/invitationservice.spec.js.map +1 -1
- package/lib/services/kubernetesconfiguration.d.ts +2 -2
- package/lib/services/kubernetesconfiguration.js +41 -59
- package/lib/services/kubernetesconfiguration.js.map +1 -1
- package/lib/services/kubernetesconfiguration.spec.js +80 -98
- package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
- package/lib/services/mailer.d.ts +4 -4
- package/lib/services/mailer.js +62 -86
- package/lib/services/mailer.js.map +1 -1
- package/lib/services/mailer.spec.js +86 -127
- package/lib/services/mailer.spec.js.map +1 -1
- package/lib/services/notificationservice.d.ts +4 -4
- package/lib/services/notificationservice.js +23 -42
- package/lib/services/notificationservice.js.map +1 -1
- package/lib/services/notificationservice.spec.js +47 -73
- package/lib/services/notificationservice.spec.js.map +1 -1
- package/lib/services/oauth.d.ts +32 -6
- package/lib/services/oauth.js +73 -78
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +128 -148
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +74 -0
- package/lib/services/proxy.js +126 -0
- package/lib/services/proxy.js.map +1 -0
- package/lib/services/proxy.spec.d.ts +1 -0
- package/lib/services/proxy.spec.js +59 -0
- package/lib/services/proxy.spec.js.map +1 -0
- package/lib/services/resource.d.ts +2 -2
- package/lib/services/resource.js +12 -18
- package/lib/services/resource.js.map +1 -1
- package/lib/services/resource.spec.js +67 -99
- package/lib/services/resource.spec.js.map +1 -1
- package/lib/services/service.d.ts +29 -6
- package/lib/services/service.js +69 -39
- package/lib/services/service.js.map +1 -1
- package/lib/services/service.spec.js +62 -67
- package/lib/services/service.spec.js.map +1 -1
- package/lib/services/version.d.ts +1 -1
- package/lib/services/version.js +3 -8
- package/lib/services/version.js.map +1 -1
- package/lib/services/version.spec.js +11 -24
- package/lib/services/version.spec.js.map +1 -1
- package/lib/stores/aggregator.d.ts +3 -3
- package/lib/stores/aggregator.js +37 -57
- package/lib/stores/aggregator.js.map +1 -1
- package/lib/stores/file.d.ts +3 -3
- package/lib/stores/file.js +93 -131
- package/lib/stores/file.js.map +1 -1
- package/lib/stores/file.spec.d.ts +2 -2
- package/lib/stores/file.spec.js +262 -289
- package/lib/stores/file.spec.js.map +1 -1
- package/lib/stores/mapper.d.ts +4 -4
- package/lib/stores/mapper.js +111 -137
- package/lib/stores/mapper.js.map +1 -1
- package/lib/stores/mapper.spec.js +133 -150
- package/lib/stores/mapper.spec.js.map +1 -1
- package/lib/stores/memory.d.ts +67 -6
- package/lib/stores/memory.js +155 -117
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +3 -2
- package/lib/stores/memory.spec.js +127 -105
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +40 -16
- package/lib/stores/store.js +847 -830
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +6 -4
- package/lib/stores/store.spec.js +628 -647
- package/lib/stores/store.spec.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
- package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
- package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
- package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
- package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
- package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
- package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
- package/lib/stores/webdaql/query.d.ts +4 -5
- package/lib/stores/webdaql/query.js +16 -19
- package/lib/stores/webdaql/query.js.map +1 -1
- package/lib/stores/webdaql/query.spec.js +30 -32
- package/lib/stores/webdaql/query.spec.js.map +1 -1
- package/lib/test.d.ts +3 -3
- package/lib/test.js +74 -94
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +44 -38
- package/lib/unpackedapplication.js.map +1 -1
- package/lib/utils/abstractdeployer.js +1 -5
- package/lib/utils/abstractdeployer.js.map +1 -1
- package/lib/utils/abstractdeployer.spec.js +6 -8
- package/lib/utils/abstractdeployer.spec.js.map +1 -1
- package/lib/utils/context.d.ts +61 -29
- package/lib/utils/context.js +133 -127
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +144 -153
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +66 -45
- package/lib/utils/cookie.js +69 -158
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +220 -238
- package/lib/utils/cookie.spec.js.map +1 -1
- package/lib/utils/esm.d.ts +4 -0
- package/lib/utils/esm.js +10 -0
- package/lib/utils/esm.js.map +1 -0
- package/lib/utils/httpcontext.d.ts +3 -0
- package/lib/utils/httpcontext.js +48 -65
- package/lib/utils/httpcontext.js.map +1 -1
- package/lib/utils/httpcontext.spec.js +37 -56
- package/lib/utils/httpcontext.spec.js.map +1 -1
- package/lib/utils/logger.d.ts +2 -2
- package/lib/utils/logger.js +15 -28
- package/lib/utils/logger.js.map +1 -1
- package/lib/utils/logger.spec.js +9 -11
- package/lib/utils/logger.spec.js.map +1 -1
- package/lib/utils/serializers.js +17 -20
- package/lib/utils/serializers.js.map +1 -1
- package/lib/utils/serializers.spec.js +43 -44
- package/lib/utils/serializers.spec.js.map +1 -1
- package/lib/utils/session.d.ts +120 -0
- package/lib/utils/session.js +155 -0
- package/lib/utils/session.js.map +1 -0
- package/lib/utils/session.spec.d.ts +1 -0
- package/lib/utils/session.spec.js +66 -0
- package/lib/utils/session.spec.js.map +1 -0
- package/lib/utils/waiter.d.ts +1 -1
- package/lib/utils/waiter.js +32 -52
- package/lib/utils/waiter.js.map +1 -1
- package/lib/utils/waiter.spec.js +75 -92
- package/lib/utils/waiter.spec.js.map +1 -1
- package/package.json +22 -14
- package/test/config-invitation.json +1 -3
- package/test/config.json +3 -3
- package/test/config.old.json +1 -2
- package/test/moddas/annotatedservice.js +5 -5
- package/test/moddas/debugmailer.js +2 -3
- package/test/moddas/fakeservice.js +2 -3
- package/test/moddas/voidstore.js +6 -4
- package/test/models/ident.js +2 -6
- package/test/models/task.js +3 -7
- package/test/package.json +2 -1
- package/webda.module.json +895 -189
package/lib/services/binary.js
CHANGED
|
@@ -5,39 +5,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.Binary = exports.BinaryParameters = exports.BinaryMap = exports.MemoryBinaryFile = exports.LocalBinaryFile = exports.BinaryFile = exports.BinaryNotFoundError = void 0;
|
|
19
|
-
const crypto = require("crypto");
|
|
20
|
-
const fs = require("fs");
|
|
21
|
-
const mime = require("mime-types");
|
|
22
|
-
const path = require("path");
|
|
23
|
-
const stream_1 = require("stream");
|
|
24
|
-
const __1 = require("..");
|
|
25
|
-
const coremodel_1 = require("../models/coremodel");
|
|
26
|
-
const store_1 = require("../stores/store");
|
|
27
|
-
const service_1 = require("./service");
|
|
8
|
+
import * as crypto from "crypto";
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as mime from "mime-types";
|
|
11
|
+
import * as path from "path";
|
|
12
|
+
import { Readable } from "stream";
|
|
13
|
+
import { WebdaError } from "../index.js";
|
|
14
|
+
import { NotEnumerable } from "../models/coremodel.js";
|
|
15
|
+
import { Store } from "../stores/store.js";
|
|
16
|
+
import { Service, ServiceParameters } from "./service.js";
|
|
28
17
|
/**
|
|
29
18
|
* Emitted if binary does not exist
|
|
30
19
|
*/
|
|
31
|
-
class BinaryNotFoundError extends
|
|
20
|
+
export class BinaryNotFoundError extends WebdaError {
|
|
32
21
|
constructor(hash, storeName) {
|
|
33
22
|
super("BINARY_NOTFOUND", `Binary not found ${hash} BinaryService(${storeName})`);
|
|
34
23
|
}
|
|
35
24
|
}
|
|
36
|
-
exports.BinaryNotFoundError = BinaryNotFoundError;
|
|
37
25
|
/**
|
|
38
26
|
* Represent a file to store
|
|
39
27
|
*/
|
|
40
|
-
class BinaryFile {
|
|
28
|
+
export class BinaryFile {
|
|
41
29
|
constructor(info) {
|
|
42
30
|
this.name = info.name;
|
|
43
31
|
this.challenge = info.challenge;
|
|
@@ -64,37 +52,34 @@ class BinaryFile {
|
|
|
64
52
|
* @param buffer
|
|
65
53
|
* @returns
|
|
66
54
|
*/
|
|
67
|
-
getHashes() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
resolve();
|
|
81
|
-
});
|
|
82
|
-
stream.on("data", chunk => {
|
|
83
|
-
let buffer = Buffer.from(chunk);
|
|
84
|
-
hash.update(buffer);
|
|
85
|
-
challenge.update(buffer);
|
|
86
|
-
});
|
|
55
|
+
async getHashes() {
|
|
56
|
+
if (!this.hash) {
|
|
57
|
+
// Using MD5 as S3 content verification use md5
|
|
58
|
+
const hash = crypto.createHash("md5");
|
|
59
|
+
const challenge = crypto.createHash("md5");
|
|
60
|
+
const stream = await this.get();
|
|
61
|
+
challenge.update("WEBDA");
|
|
62
|
+
await new Promise((resolve, reject) => {
|
|
63
|
+
stream.on("error", err => reject(err));
|
|
64
|
+
stream.on("end", () => {
|
|
65
|
+
this.hash = hash.digest("hex");
|
|
66
|
+
this.challenge = challenge.digest("hex");
|
|
67
|
+
resolve();
|
|
87
68
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
stream.on("data", chunk => {
|
|
70
|
+
let buffer = Buffer.from(chunk);
|
|
71
|
+
hash.update(buffer);
|
|
72
|
+
challenge.update(buffer);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
hash: this.hash,
|
|
78
|
+
challenge: this.challenge
|
|
79
|
+
};
|
|
94
80
|
}
|
|
95
81
|
}
|
|
96
|
-
|
|
97
|
-
class LocalBinaryFile extends BinaryFile {
|
|
82
|
+
export class LocalBinaryFile extends BinaryFile {
|
|
98
83
|
constructor(filePath) {
|
|
99
84
|
super({
|
|
100
85
|
name: path.basename(filePath),
|
|
@@ -106,14 +91,11 @@ class LocalBinaryFile extends BinaryFile {
|
|
|
106
91
|
/**
|
|
107
92
|
* @override
|
|
108
93
|
*/
|
|
109
|
-
get() {
|
|
110
|
-
return
|
|
111
|
-
return fs.createReadStream(this.path);
|
|
112
|
-
});
|
|
94
|
+
async get() {
|
|
95
|
+
return fs.createReadStream(this.path);
|
|
113
96
|
}
|
|
114
97
|
}
|
|
115
|
-
|
|
116
|
-
class MemoryBinaryFile extends BinaryFile {
|
|
98
|
+
export class MemoryBinaryFile extends BinaryFile {
|
|
117
99
|
constructor(buffer, info) {
|
|
118
100
|
super(info);
|
|
119
101
|
this.buffer = buffer;
|
|
@@ -121,22 +103,19 @@ class MemoryBinaryFile extends BinaryFile {
|
|
|
121
103
|
/**
|
|
122
104
|
* @override
|
|
123
105
|
*/
|
|
124
|
-
get() {
|
|
125
|
-
return
|
|
126
|
-
return stream_1.Readable.from(this.buffer);
|
|
127
|
-
});
|
|
106
|
+
async get() {
|
|
107
|
+
return Readable.from(this.buffer);
|
|
128
108
|
}
|
|
129
109
|
}
|
|
130
|
-
exports.MemoryBinaryFile = MemoryBinaryFile;
|
|
131
110
|
/**
|
|
132
111
|
* This is a map used to retrieve binary
|
|
133
112
|
*
|
|
134
113
|
* @class BinaryMap
|
|
135
114
|
*/
|
|
136
|
-
class BinaryMap extends BinaryFile {
|
|
115
|
+
export class BinaryMap extends BinaryFile {
|
|
137
116
|
constructor(service, obj) {
|
|
138
117
|
super(obj);
|
|
139
|
-
for (
|
|
118
|
+
for (let i in obj) {
|
|
140
119
|
this[i] = obj[i];
|
|
141
120
|
}
|
|
142
121
|
this.__store = service;
|
|
@@ -169,10 +148,8 @@ class BinaryMap extends BinaryFile {
|
|
|
169
148
|
*
|
|
170
149
|
* @param filename
|
|
171
150
|
*/
|
|
172
|
-
downloadTo(filename) {
|
|
173
|
-
return
|
|
174
|
-
return this.__store.downloadTo(this, filename);
|
|
175
|
-
});
|
|
151
|
+
async downloadTo(filename) {
|
|
152
|
+
return this.__store.downloadTo(this, filename);
|
|
176
153
|
}
|
|
177
154
|
/**
|
|
178
155
|
* Set the http context
|
|
@@ -183,23 +160,20 @@ class BinaryMap extends BinaryFile {
|
|
|
183
160
|
}
|
|
184
161
|
}
|
|
185
162
|
__decorate([
|
|
186
|
-
|
|
163
|
+
NotEnumerable
|
|
187
164
|
], BinaryMap.prototype, "__ctx", void 0);
|
|
188
165
|
__decorate([
|
|
189
|
-
|
|
166
|
+
NotEnumerable
|
|
190
167
|
], BinaryMap.prototype, "__store", void 0);
|
|
191
|
-
|
|
192
|
-
class BinaryParameters extends service_1.ServiceParameters {
|
|
168
|
+
export class BinaryParameters extends ServiceParameters {
|
|
193
169
|
constructor(params, _service) {
|
|
194
|
-
var _a;
|
|
195
170
|
super(params);
|
|
196
171
|
if (this.expose) {
|
|
197
172
|
this.expose.restrict = this.expose.restrict || {};
|
|
198
173
|
}
|
|
199
|
-
|
|
174
|
+
this.map ?? (this.map = {});
|
|
200
175
|
}
|
|
201
176
|
}
|
|
202
|
-
exports.BinaryParameters = BinaryParameters;
|
|
203
177
|
/**
|
|
204
178
|
* This is an abstract service to represent a storage of files
|
|
205
179
|
* The binary allow you to expose this service as HTTP
|
|
@@ -223,21 +197,19 @@ exports.BinaryParameters = BinaryParameters;
|
|
|
223
197
|
* @abstract
|
|
224
198
|
* @class Binary
|
|
225
199
|
*/
|
|
226
|
-
class Binary extends
|
|
200
|
+
class Binary extends Service {
|
|
227
201
|
/**
|
|
228
202
|
* Get a binary
|
|
229
203
|
*
|
|
230
204
|
* @param {Object} info The reference stored in your target object
|
|
231
205
|
* @emits 'binaryGet'
|
|
232
206
|
*/
|
|
233
|
-
get(info) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
service: this
|
|
238
|
-
});
|
|
239
|
-
return this._get(info);
|
|
207
|
+
async get(info) {
|
|
208
|
+
await this.emitSync("Binary.Get", {
|
|
209
|
+
object: info,
|
|
210
|
+
service: this
|
|
240
211
|
});
|
|
212
|
+
return this._get(info);
|
|
241
213
|
}
|
|
242
214
|
/**
|
|
243
215
|
* Download a binary to a file
|
|
@@ -245,29 +217,29 @@ class Binary extends service_1.Service {
|
|
|
245
217
|
* @param {Object} info The reference stored in your target object
|
|
246
218
|
* @param {String} filepath to save the binary to
|
|
247
219
|
*/
|
|
248
|
-
downloadTo(info, filename) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
220
|
+
async downloadTo(info, filename) {
|
|
221
|
+
await this.emitSync("Binary.Get", {
|
|
222
|
+
object: info,
|
|
223
|
+
service: this
|
|
224
|
+
});
|
|
225
|
+
let readStream = await this._get(info);
|
|
226
|
+
let writeStream = fs.createWriteStream(filename);
|
|
227
|
+
return new Promise((resolve, reject) => {
|
|
228
|
+
writeStream.on("finish", _src => {
|
|
229
|
+
return resolve();
|
|
253
230
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
catch (err) {
|
|
265
|
-
this._webda.log("ERROR", err);
|
|
266
|
-
}
|
|
267
|
-
return reject(src);
|
|
268
|
-
});
|
|
269
|
-
readStream.pipe(writeStream);
|
|
231
|
+
writeStream.on("error", src => {
|
|
232
|
+
try {
|
|
233
|
+
fs.unlinkSync(filename);
|
|
234
|
+
// Stubing the fs module in ESM seems complicated for now
|
|
235
|
+
/* c8 ignore next 3 */
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
this._webda.log("ERROR", err);
|
|
239
|
+
}
|
|
240
|
+
return reject(src);
|
|
270
241
|
});
|
|
242
|
+
readStream.pipe(writeStream);
|
|
271
243
|
});
|
|
272
244
|
}
|
|
273
245
|
/**
|
|
@@ -276,6 +248,7 @@ class Binary extends service_1.Service {
|
|
|
276
248
|
resolve() {
|
|
277
249
|
super.resolve();
|
|
278
250
|
this.initMap(this.parameters.map);
|
|
251
|
+
return this;
|
|
279
252
|
}
|
|
280
253
|
/**
|
|
281
254
|
* Init the declared maps, adding reverse maps
|
|
@@ -290,7 +263,7 @@ class Binary extends service_1.Service {
|
|
|
290
263
|
Object.keys(map).forEach(prop => {
|
|
291
264
|
this._lowercaseMaps[prop.toLowerCase()] = prop;
|
|
292
265
|
let reverseStore = this._webda.getService(prop);
|
|
293
|
-
if (reverseStore === undefined || !(reverseStore instanceof
|
|
266
|
+
if (reverseStore === undefined || !(reverseStore instanceof Store)) {
|
|
294
267
|
this._webda.log("WARN", "Can't setup mapping as store ", prop, " doesn't exist");
|
|
295
268
|
map[prop]["-onerror"] = "NoStore";
|
|
296
269
|
return;
|
|
@@ -299,13 +272,13 @@ class Binary extends service_1.Service {
|
|
|
299
272
|
reverseStore.addReverseMap(map[prop][i], this);
|
|
300
273
|
}
|
|
301
274
|
// Cascade delete
|
|
302
|
-
reverseStore.on("Store.Deleted", (evt) =>
|
|
275
|
+
reverseStore.on("Store.Deleted", async (evt) => {
|
|
303
276
|
let infos = [];
|
|
304
277
|
if (evt.object[map[prop]]) {
|
|
305
278
|
infos.push(...evt.object[map[prop]]);
|
|
306
279
|
}
|
|
307
|
-
|
|
308
|
-
})
|
|
280
|
+
await Promise.all(infos.map(info => this.cascadeDelete(info, evt.object.getUuid())));
|
|
281
|
+
});
|
|
309
282
|
});
|
|
310
283
|
}
|
|
311
284
|
/**
|
|
@@ -313,7 +286,7 @@ class Binary extends service_1.Service {
|
|
|
313
286
|
* @param obj
|
|
314
287
|
* @returns
|
|
315
288
|
*/
|
|
316
|
-
|
|
289
|
+
newModel(obj) {
|
|
317
290
|
return new BinaryMap(this, obj);
|
|
318
291
|
}
|
|
319
292
|
/**
|
|
@@ -338,7 +311,7 @@ class Binary extends service_1.Service {
|
|
|
338
311
|
* @param property
|
|
339
312
|
*/
|
|
340
313
|
checkMap(name, property) {
|
|
341
|
-
|
|
314
|
+
let map = this.parameters.map[this._lowercaseMaps[name.toLowerCase()]];
|
|
342
315
|
if (map === undefined) {
|
|
343
316
|
throw Error("Unknown mapping");
|
|
344
317
|
}
|
|
@@ -349,20 +322,18 @@ class Binary extends service_1.Service {
|
|
|
349
322
|
/**
|
|
350
323
|
* Ensure events are sent correctly after an upload and update the BinaryFileInfo in targetted object
|
|
351
324
|
*/
|
|
352
|
-
uploadSuccess(object, property, file) {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
target: object
|
|
365
|
-
});
|
|
325
|
+
async uploadSuccess(object, property, file) {
|
|
326
|
+
let object_uid = object.getUuid();
|
|
327
|
+
await this.emitSync("Binary.UploadSuccess", {
|
|
328
|
+
object: file,
|
|
329
|
+
service: this,
|
|
330
|
+
target: object
|
|
331
|
+
});
|
|
332
|
+
await object.getStore().upsertItemToCollection(object_uid, property, file);
|
|
333
|
+
await this.emitSync("Binary.Create", {
|
|
334
|
+
object: file,
|
|
335
|
+
service: this,
|
|
336
|
+
target: object
|
|
366
337
|
});
|
|
367
338
|
}
|
|
368
339
|
/**
|
|
@@ -373,31 +344,27 @@ class Binary extends service_1.Service {
|
|
|
373
344
|
* @param index
|
|
374
345
|
* @returns
|
|
375
346
|
*/
|
|
376
|
-
deleteSuccess(object, property, index) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
service: this
|
|
383
|
-
});
|
|
384
|
-
return update;
|
|
347
|
+
async deleteSuccess(object, property, index) {
|
|
348
|
+
let info = object[property][index];
|
|
349
|
+
let update = object.getStore().deleteItemFromCollection(object.getUuid(), property, index, info.hash, "hash");
|
|
350
|
+
await this.emitSync("Binary.Delete", {
|
|
351
|
+
object: info,
|
|
352
|
+
service: this
|
|
385
353
|
});
|
|
354
|
+
return update;
|
|
386
355
|
}
|
|
387
356
|
/**
|
|
388
357
|
* Get file either from multipart post or raw
|
|
389
358
|
* @param req
|
|
390
359
|
* @returns
|
|
391
360
|
*/
|
|
392
|
-
_getFile(req) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
name: ""
|
|
400
|
-
});
|
|
361
|
+
async _getFile(req) {
|
|
362
|
+
let file = await req.getHttpContext().getRawBody(10 * 1024 * 1024);
|
|
363
|
+
// TODO Check if we have other type
|
|
364
|
+
return new MemoryBinaryFile(Buffer.from(file), {
|
|
365
|
+
mimetype: req.getHttpContext().getUniqueHeader("Content-Type", "application/octet-stream"),
|
|
366
|
+
size: parseInt(req.getHttpContext().getUniqueHeader("Content-Length")) || file.length,
|
|
367
|
+
name: ""
|
|
401
368
|
});
|
|
402
369
|
}
|
|
403
370
|
/**
|
|
@@ -557,14 +524,14 @@ class Binary extends service_1.Service {
|
|
|
557
524
|
_verifyMapAndStore(ctx) {
|
|
558
525
|
let store = ctx.parameter("store").toLowerCase();
|
|
559
526
|
// To avoid any probleme lowercase everything
|
|
560
|
-
|
|
527
|
+
let map = this.parameters.map[this._lowercaseMaps[store]];
|
|
561
528
|
if (map === undefined) {
|
|
562
529
|
throw 404;
|
|
563
530
|
}
|
|
564
531
|
if (map.indexOf(ctx.parameter("property")) == -1) {
|
|
565
532
|
throw 404;
|
|
566
533
|
}
|
|
567
|
-
|
|
534
|
+
let targetStore = this.getService(store);
|
|
568
535
|
if (targetStore === undefined) {
|
|
569
536
|
throw 404;
|
|
570
537
|
}
|
|
@@ -575,125 +542,126 @@ class Binary extends service_1.Service {
|
|
|
575
542
|
*
|
|
576
543
|
* @param ctx
|
|
577
544
|
*/
|
|
578
|
-
putRedirectUrl(_ctx) {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
throw 404;
|
|
582
|
-
});
|
|
545
|
+
async putRedirectUrl(_ctx) {
|
|
546
|
+
// Dont handle the redirect url
|
|
547
|
+
throw 404;
|
|
583
548
|
}
|
|
584
549
|
/**
|
|
585
550
|
* Mechanism to add a data based on challenge
|
|
586
551
|
*/
|
|
587
|
-
httpChallenge(ctx) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
552
|
+
async httpChallenge(ctx) {
|
|
553
|
+
let body = await ctx.getRequestBody();
|
|
554
|
+
if (!body.hash || !body.challenge) {
|
|
555
|
+
throw 400;
|
|
556
|
+
}
|
|
557
|
+
// First verify if map exist
|
|
558
|
+
let targetStore = this._verifyMapAndStore(ctx);
|
|
559
|
+
// Get the object
|
|
560
|
+
let object = await targetStore.get(ctx.parameter("uid"), ctx);
|
|
561
|
+
if (object === undefined) {
|
|
562
|
+
throw 404;
|
|
563
|
+
}
|
|
564
|
+
await object.canAct(ctx, "attach_binary");
|
|
565
|
+
let url = await this.putRedirectUrl(ctx);
|
|
566
|
+
let base64String = Buffer.from(body.hash, "hex").toString("base64");
|
|
567
|
+
ctx.write({
|
|
568
|
+
...url,
|
|
569
|
+
done: url === undefined,
|
|
570
|
+
md5: base64String
|
|
604
571
|
});
|
|
605
572
|
}
|
|
606
573
|
/**
|
|
607
574
|
* Manage the different routes
|
|
608
575
|
* @param ctx
|
|
609
576
|
*/
|
|
610
|
-
httpRoute(ctx) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
577
|
+
async httpRoute(ctx) {
|
|
578
|
+
// First verify if map exist
|
|
579
|
+
let targetStore = this._verifyMapAndStore(ctx);
|
|
580
|
+
// Get the object
|
|
581
|
+
let object = await targetStore.get(ctx.parameter("uid"), ctx);
|
|
582
|
+
if (object === undefined) {
|
|
583
|
+
throw 404;
|
|
584
|
+
}
|
|
585
|
+
let property = ctx.parameter("property");
|
|
586
|
+
let index = ctx.parameter("index");
|
|
587
|
+
// Should be an array
|
|
588
|
+
if (!Array.isArray(object[property]) || object[property].length <= index) {
|
|
589
|
+
throw 404;
|
|
590
|
+
}
|
|
591
|
+
// Check permissions
|
|
592
|
+
let action = "unknown";
|
|
593
|
+
if (ctx.getHttpContext().getMethod() === "GET") {
|
|
594
|
+
action = "get_binary";
|
|
595
|
+
}
|
|
596
|
+
else if (ctx.getHttpContext().getMethod() === "DELETE") {
|
|
597
|
+
action = "detach_binary";
|
|
598
|
+
}
|
|
599
|
+
else if (ctx.getHttpContext().getMethod() === "POST") {
|
|
600
|
+
action = "attach_binary";
|
|
601
|
+
}
|
|
602
|
+
else if (ctx.getHttpContext().getMethod() === "PUT") {
|
|
603
|
+
action = "update_binary_metadata";
|
|
604
|
+
}
|
|
605
|
+
await object.canAct(ctx, action);
|
|
606
|
+
// Now do the action
|
|
607
|
+
if (ctx.getHttpContext().getMethod() === "GET") {
|
|
608
|
+
// Most implementation override this to do a REDIRECT to a GET url
|
|
609
|
+
let file = object[property][index];
|
|
610
|
+
ctx.writeHead(200, {
|
|
611
|
+
"Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
|
|
612
|
+
"Content-Length": file.size
|
|
613
|
+
});
|
|
614
|
+
let readStream = await this.get(file);
|
|
615
|
+
try {
|
|
616
|
+
await new Promise((resolve, reject) => {
|
|
617
|
+
// We replaced all the event handlers with a simple call to readStream.pipe()
|
|
618
|
+
ctx._stream.on("finish", resolve);
|
|
619
|
+
ctx._stream.on("error", reject);
|
|
620
|
+
readStream.pipe(ctx._stream);
|
|
621
|
+
});
|
|
635
622
|
}
|
|
636
|
-
|
|
637
|
-
|
|
623
|
+
catch (err) {
|
|
624
|
+
this.log("ERROR", err);
|
|
625
|
+
throw 500;
|
|
638
626
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
if (ctx.getHttpContext().getMethod() === "
|
|
642
|
-
|
|
643
|
-
var file = object[property][index];
|
|
644
|
-
ctx.writeHead(200, {
|
|
645
|
-
"Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
|
|
646
|
-
"Content-Length": file.size
|
|
647
|
-
});
|
|
648
|
-
let readStream = yield this.get(file);
|
|
649
|
-
try {
|
|
650
|
-
yield new Promise((resolve, reject) => {
|
|
651
|
-
// We replaced all the event handlers with a simple call to readStream.pipe()
|
|
652
|
-
ctx._stream.on("finish", resolve);
|
|
653
|
-
ctx._stream.on("error", reject);
|
|
654
|
-
readStream.pipe(ctx._stream);
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
catch (err) {
|
|
658
|
-
this.log("ERROR", err);
|
|
659
|
-
throw 500;
|
|
660
|
-
}
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
if (ctx.getHttpContext().getMethod() === "POST") {
|
|
630
|
+
await this.store(object, property, await this._getFile(ctx), await ctx.getRequestBody());
|
|
661
631
|
}
|
|
662
632
|
else {
|
|
663
|
-
if (ctx.
|
|
664
|
-
|
|
633
|
+
if (object[property][index].hash !== ctx.parameter("hash")) {
|
|
634
|
+
throw 412;
|
|
665
635
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
let metadata = yield ctx.getRequestBody();
|
|
675
|
-
// Limit metadata to 4kb
|
|
676
|
-
if (JSON.stringify(metadata).length >= 4096) {
|
|
677
|
-
throw 400;
|
|
678
|
-
}
|
|
679
|
-
let evt = {
|
|
680
|
-
service: this,
|
|
681
|
-
object: object[property][index],
|
|
682
|
-
target: object
|
|
683
|
-
};
|
|
684
|
-
yield this.emitSync("Binary.MetadataUpdate", Object.assign(Object.assign({}, evt), { metadata }));
|
|
685
|
-
object[property][index].metadata = metadata;
|
|
686
|
-
// Update mapper on purpose
|
|
687
|
-
yield object.getStore().patch({
|
|
688
|
-
[object.__class.getUuidField()]: object.getUuid(),
|
|
689
|
-
[property]: object[property].map(b => b.toJSON())
|
|
690
|
-
}, false);
|
|
691
|
-
yield this.emitSync("Binary.MetadataUpdated", evt);
|
|
636
|
+
if (ctx.getHttpContext().getMethod() === "DELETE") {
|
|
637
|
+
await this.delete(object, property, index);
|
|
638
|
+
}
|
|
639
|
+
else if (ctx.getHttpContext().getMethod() === "PUT") {
|
|
640
|
+
let metadata = await ctx.getRequestBody();
|
|
641
|
+
// Limit metadata to 4kb
|
|
642
|
+
if (JSON.stringify(metadata).length >= 4096) {
|
|
643
|
+
throw 400;
|
|
692
644
|
}
|
|
645
|
+
let evt = {
|
|
646
|
+
service: this,
|
|
647
|
+
object: object[property][index],
|
|
648
|
+
target: object
|
|
649
|
+
};
|
|
650
|
+
await this.emitSync("Binary.MetadataUpdate", {
|
|
651
|
+
...evt,
|
|
652
|
+
metadata
|
|
653
|
+
});
|
|
654
|
+
object[property][index].metadata = metadata;
|
|
655
|
+
// Update mapper on purpose
|
|
656
|
+
await object.getStore().patch({
|
|
657
|
+
[object.__class.getUuidField()]: object.getUuid(),
|
|
658
|
+
[property]: object[property].map(b => b.toJSON())
|
|
659
|
+
}, false);
|
|
660
|
+
await this.emitSync("Binary.MetadataUpdated", evt);
|
|
693
661
|
}
|
|
694
662
|
}
|
|
695
|
-
}
|
|
663
|
+
}
|
|
696
664
|
}
|
|
697
665
|
}
|
|
698
|
-
|
|
666
|
+
export { Binary };
|
|
699
667
|
//# sourceMappingURL=binary.js.map
|