@webda/core 2.0.0-beta.3 → 2.1.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/lib/application.d.ts +5 -5
- 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 +21 -25
- package/lib/core.js +233 -320
- package/lib/core.js.map +1 -1
- package/lib/core.spec.js +334 -406
- package/lib/core.spec.js.map +1 -1
- package/lib/index.d.ts +49 -48
- package/lib/index.js +53 -70
- 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 -152
- package/lib/models/aclmodel.spec.js.map +1 -1
- package/lib/models/coremodel.d.ts +33 -14
- 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 -168
- package/lib/models/ownermodel.spec.js.map +1 -1
- package/lib/models/rolemodel.d.ts +1 -1
- package/lib/models/rolemodel.js +24 -40
- package/lib/models/rolemodel.js.map +1 -1
- package/lib/models/rolemodel.spec.js +44 -63
- 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 +3 -3
- package/lib/queues/queueservice.js +51 -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 +23 -13
- package/lib/services/authentication.js +540 -566
- 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 +8 -6
- package/lib/services/binary.js +212 -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 +1 -1
- package/lib/services/configuration.js +78 -105
- 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 +9 -4
- package/lib/services/cryptoservice.js +187 -221
- package/lib/services/cryptoservice.js.map +1 -1
- package/lib/services/cryptoservice.spec.js +88 -115
- package/lib/services/cryptoservice.spec.js.map +1 -1
- 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 +5 -5
- package/lib/services/filebinary.js +165 -210
- package/lib/services/filebinary.js.map +1 -1
- package/lib/services/filebinary.spec.d.ts +2 -1
- package/lib/services/filebinary.spec.js +106 -116
- package/lib/services/filebinary.spec.js.map +1 -1
- package/lib/services/fileconfiguration.d.ts +1 -1
- package/lib/services/fileconfiguration.js +25 -44
- 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 +8 -8
- package/lib/services/invitationservice.js +274 -314
- 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 +1 -1
- package/lib/services/kubernetesconfiguration.js +41 -60
- 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 +3 -3
- package/lib/services/notificationservice.js +21 -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 +4 -4
- package/lib/services/oauth.js +68 -83
- package/lib/services/oauth.js.map +1 -1
- package/lib/services/oauth.spec.js +130 -156
- package/lib/services/oauth.spec.js.map +1 -1
- package/lib/services/proxy.d.ts +2 -6
- package/lib/services/proxy.js +45 -58
- package/lib/services/proxy.js.map +1 -1
- package/lib/services/proxy.spec.js +34 -53
- package/lib/services/proxy.spec.js.map +1 -1
- 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 +26 -3
- package/lib/services/service.js +68 -40
- 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 +2 -2
- package/lib/stores/aggregator.js +37 -58
- 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 +3 -3
- package/lib/stores/mapper.js +110 -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 +3 -3
- package/lib/stores/memory.js +98 -144
- package/lib/stores/memory.js.map +1 -1
- package/lib/stores/memory.spec.d.ts +2 -2
- package/lib/stores/memory.spec.js +124 -145
- package/lib/stores/memory.spec.js.map +1 -1
- package/lib/stores/store.d.ts +27 -17
- package/lib/stores/store.js +833 -849
- package/lib/stores/store.js.map +1 -1
- package/lib/stores/store.spec.d.ts +5 -4
- package/lib/stores/store.spec.js +625 -669
- 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 +73 -100
- package/lib/test.js.map +1 -1
- package/lib/unpackedapplication.d.ts +1 -1
- package/lib/unpackedapplication.js +49 -39
- 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 +7 -5
- package/lib/utils/context.js +95 -103
- package/lib/utils/context.js.map +1 -1
- package/lib/utils/context.spec.js +139 -163
- package/lib/utils/context.spec.js.map +1 -1
- package/lib/utils/cookie.d.ts +3 -3
- package/lib/utils/cookie.js +42 -61
- package/lib/utils/cookie.js.map +1 -1
- package/lib/utils/cookie.spec.js +42 -64
- 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 +6 -6
- package/lib/utils/session.js +37 -59
- package/lib/utils/session.js.map +1 -1
- package/lib/utils/session.spec.js +38 -51
- package/lib/utils/session.spec.js.map +1 -1
- 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 +18 -13
- package/test/config-invitation.json +1 -3
- package/test/config.json +1 -2
- 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 -190
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
|
/**
|
|
@@ -291,7 +263,7 @@ class Binary extends service_1.Service {
|
|
|
291
263
|
Object.keys(map).forEach(prop => {
|
|
292
264
|
this._lowercaseMaps[prop.toLowerCase()] = prop;
|
|
293
265
|
let reverseStore = this._webda.getService(prop);
|
|
294
|
-
if (reverseStore === undefined || !(reverseStore instanceof
|
|
266
|
+
if (reverseStore === undefined || !(reverseStore instanceof Store)) {
|
|
295
267
|
this._webda.log("WARN", "Can't setup mapping as store ", prop, " doesn't exist");
|
|
296
268
|
map[prop]["-onerror"] = "NoStore";
|
|
297
269
|
return;
|
|
@@ -300,13 +272,13 @@ class Binary extends service_1.Service {
|
|
|
300
272
|
reverseStore.addReverseMap(map[prop][i], this);
|
|
301
273
|
}
|
|
302
274
|
// Cascade delete
|
|
303
|
-
reverseStore.on("Store.Deleted", (evt) =>
|
|
275
|
+
reverseStore.on("Store.Deleted", async (evt) => {
|
|
304
276
|
let infos = [];
|
|
305
277
|
if (evt.object[map[prop]]) {
|
|
306
278
|
infos.push(...evt.object[map[prop]]);
|
|
307
279
|
}
|
|
308
|
-
|
|
309
|
-
})
|
|
280
|
+
await Promise.all(infos.map(info => this.cascadeDelete(info, evt.object.getUuid())));
|
|
281
|
+
});
|
|
310
282
|
});
|
|
311
283
|
}
|
|
312
284
|
/**
|
|
@@ -314,7 +286,7 @@ class Binary extends service_1.Service {
|
|
|
314
286
|
* @param obj
|
|
315
287
|
* @returns
|
|
316
288
|
*/
|
|
317
|
-
|
|
289
|
+
newModel(obj) {
|
|
318
290
|
return new BinaryMap(this, obj);
|
|
319
291
|
}
|
|
320
292
|
/**
|
|
@@ -339,7 +311,7 @@ class Binary extends service_1.Service {
|
|
|
339
311
|
* @param property
|
|
340
312
|
*/
|
|
341
313
|
checkMap(name, property) {
|
|
342
|
-
|
|
314
|
+
let map = this.parameters.map[this._lowercaseMaps[name.toLowerCase()]];
|
|
343
315
|
if (map === undefined) {
|
|
344
316
|
throw Error("Unknown mapping");
|
|
345
317
|
}
|
|
@@ -350,20 +322,18 @@ class Binary extends service_1.Service {
|
|
|
350
322
|
/**
|
|
351
323
|
* Ensure events are sent correctly after an upload and update the BinaryFileInfo in targetted object
|
|
352
324
|
*/
|
|
353
|
-
uploadSuccess(object, property, file) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
target: object
|
|
366
|
-
});
|
|
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
|
|
367
337
|
});
|
|
368
338
|
}
|
|
369
339
|
/**
|
|
@@ -374,31 +344,27 @@ class Binary extends service_1.Service {
|
|
|
374
344
|
* @param index
|
|
375
345
|
* @returns
|
|
376
346
|
*/
|
|
377
|
-
deleteSuccess(object, property, index) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
service: this
|
|
384
|
-
});
|
|
385
|
-
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
|
|
386
353
|
});
|
|
354
|
+
return update;
|
|
387
355
|
}
|
|
388
356
|
/**
|
|
389
357
|
* Get file either from multipart post or raw
|
|
390
358
|
* @param req
|
|
391
359
|
* @returns
|
|
392
360
|
*/
|
|
393
|
-
_getFile(req) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
name: ""
|
|
401
|
-
});
|
|
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: ""
|
|
402
368
|
});
|
|
403
369
|
}
|
|
404
370
|
/**
|
|
@@ -558,14 +524,14 @@ class Binary extends service_1.Service {
|
|
|
558
524
|
_verifyMapAndStore(ctx) {
|
|
559
525
|
let store = ctx.parameter("store").toLowerCase();
|
|
560
526
|
// To avoid any probleme lowercase everything
|
|
561
|
-
|
|
527
|
+
let map = this.parameters.map[this._lowercaseMaps[store]];
|
|
562
528
|
if (map === undefined) {
|
|
563
529
|
throw 404;
|
|
564
530
|
}
|
|
565
531
|
if (map.indexOf(ctx.parameter("property")) == -1) {
|
|
566
532
|
throw 404;
|
|
567
533
|
}
|
|
568
|
-
|
|
534
|
+
let targetStore = this.getService(store);
|
|
569
535
|
if (targetStore === undefined) {
|
|
570
536
|
throw 404;
|
|
571
537
|
}
|
|
@@ -576,125 +542,126 @@ class Binary extends service_1.Service {
|
|
|
576
542
|
*
|
|
577
543
|
* @param ctx
|
|
578
544
|
*/
|
|
579
|
-
putRedirectUrl(_ctx) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
throw 404;
|
|
583
|
-
});
|
|
545
|
+
async putRedirectUrl(_ctx) {
|
|
546
|
+
// Dont handle the redirect url
|
|
547
|
+
throw 404;
|
|
584
548
|
}
|
|
585
549
|
/**
|
|
586
550
|
* Mechanism to add a data based on challenge
|
|
587
551
|
*/
|
|
588
|
-
httpChallenge(ctx) {
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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
|
|
605
571
|
});
|
|
606
572
|
}
|
|
607
573
|
/**
|
|
608
574
|
* Manage the different routes
|
|
609
575
|
* @param ctx
|
|
610
576
|
*/
|
|
611
|
-
httpRoute(ctx) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
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
|
+
});
|
|
636
622
|
}
|
|
637
|
-
|
|
638
|
-
|
|
623
|
+
catch (err) {
|
|
624
|
+
this.log("ERROR", err);
|
|
625
|
+
throw 500;
|
|
639
626
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
if (ctx.getHttpContext().getMethod() === "
|
|
643
|
-
|
|
644
|
-
var file = object[property][index];
|
|
645
|
-
ctx.writeHead(200, {
|
|
646
|
-
"Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
|
|
647
|
-
"Content-Length": file.size
|
|
648
|
-
});
|
|
649
|
-
let readStream = yield this.get(file);
|
|
650
|
-
try {
|
|
651
|
-
yield new Promise((resolve, reject) => {
|
|
652
|
-
// We replaced all the event handlers with a simple call to readStream.pipe()
|
|
653
|
-
ctx._stream.on("finish", resolve);
|
|
654
|
-
ctx._stream.on("error", reject);
|
|
655
|
-
readStream.pipe(ctx._stream);
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
catch (err) {
|
|
659
|
-
this.log("ERROR", err);
|
|
660
|
-
throw 500;
|
|
661
|
-
}
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
if (ctx.getHttpContext().getMethod() === "POST") {
|
|
630
|
+
await this.store(object, property, await this._getFile(ctx), await ctx.getRequestBody());
|
|
662
631
|
}
|
|
663
632
|
else {
|
|
664
|
-
if (ctx.
|
|
665
|
-
|
|
633
|
+
if (object[property][index].hash !== ctx.parameter("hash")) {
|
|
634
|
+
throw 412;
|
|
666
635
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
let metadata = yield ctx.getRequestBody();
|
|
676
|
-
// Limit metadata to 4kb
|
|
677
|
-
if (JSON.stringify(metadata).length >= 4096) {
|
|
678
|
-
throw 400;
|
|
679
|
-
}
|
|
680
|
-
let evt = {
|
|
681
|
-
service: this,
|
|
682
|
-
object: object[property][index],
|
|
683
|
-
target: object
|
|
684
|
-
};
|
|
685
|
-
yield this.emitSync("Binary.MetadataUpdate", Object.assign(Object.assign({}, evt), { metadata }));
|
|
686
|
-
object[property][index].metadata = metadata;
|
|
687
|
-
// Update mapper on purpose
|
|
688
|
-
yield object.getStore().patch({
|
|
689
|
-
[object.__class.getUuidField()]: object.getUuid(),
|
|
690
|
-
[property]: object[property].map(b => b.toJSON())
|
|
691
|
-
}, false);
|
|
692
|
-
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;
|
|
693
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);
|
|
694
661
|
}
|
|
695
662
|
}
|
|
696
|
-
}
|
|
663
|
+
}
|
|
697
664
|
}
|
|
698
665
|
}
|
|
699
|
-
|
|
666
|
+
export { Binary };
|
|
700
667
|
//# sourceMappingURL=binary.js.map
|