@cocreate/file-server 1.0.52 → 1.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/CHANGELOG.md +16 -0
- package/CoCreate.config.js +1 -1
- package/package.json +1 -1
- package/src/index.js +22 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [1.1.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.53...v1.1.0) (2023-04-23)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* store organizaton_id in map to prevent repeated db queries ([74c0540](https://github.com/CoCreate-app/CoCreate-file-server/commit/74c05407df2118a9b1601181a7a42c1ac7bdad32))
|
|
7
|
+
|
|
8
|
+
## [1.0.53](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.52...v1.0.53) (2023-04-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* domains renamd to hosts ([8d19734](https://github.com/CoCreate-app/CoCreate-file-server/commit/8d197343a5daa9039f00f69e4a0a78e8a9925f59))
|
|
14
|
+
* if !organization_id query platform org by domain to find id ([c849c7d](https://github.com/CoCreate-app/CoCreate-file-server/commit/c849c7dc2e4c7533550389a589f650077fd9da96))
|
|
15
|
+
* renamed domans to hosts ([57c06c3](https://github.com/CoCreate-app/CoCreate-file-server/commit/57c06c32a5b38c1006ad1e85648164ce3568ac63))
|
|
16
|
+
|
|
1
17
|
## [1.0.52](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.51...v1.0.52) (2023-02-01)
|
|
2
18
|
|
|
3
19
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -4,37 +4,47 @@
|
|
|
4
4
|
*
|
|
5
5
|
* SPDX-License-Identifier: MIT
|
|
6
6
|
********************************************************************************/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
const express = require('express');
|
|
8
|
+
const router = express.Router();
|
|
9
|
+
const mime = require('mime-types');
|
|
10
|
+
const organizations = new Map();
|
|
11
|
+
|
|
12
12
|
class CoCreateFileSystem {
|
|
13
13
|
constructor(crud, render) {
|
|
14
14
|
this.router = router.get('/*', async(req, res) => {
|
|
15
|
-
let organization_id;
|
|
16
15
|
let hostname = req.hostname;
|
|
16
|
+
|
|
17
|
+
let organization_id = organizations.get(hostname);
|
|
18
|
+
console.log(req.protocol, req.secure)
|
|
19
|
+
// let ddns = await certManager.checkDns(hostname)
|
|
20
|
+
// let hasCert = await certManager.checkCert(hostname)
|
|
21
|
+
// console.log(hostname, 'crt==', hasCert)
|
|
22
|
+
// ToDo: check if secured domain by running command
|
|
23
|
+
// sudo certbot certificates using spawn
|
|
24
|
+
// console.dir(req.headers.host)
|
|
17
25
|
// dns.resolve(hostname, 'TXT', (err, records) => {
|
|
18
26
|
// if (records)
|
|
19
27
|
// organization_id = records[0][0];
|
|
20
28
|
// if (err)
|
|
21
29
|
// console.log(hostname, err);
|
|
22
30
|
// });
|
|
23
|
-
|
|
31
|
+
|
|
32
|
+
|
|
24
33
|
if (!organization_id) {
|
|
25
34
|
let organization = await crud.readDocument({
|
|
26
35
|
collection: 'organizations',
|
|
27
36
|
filter: {
|
|
28
37
|
query: [
|
|
29
|
-
{name: "
|
|
38
|
+
{name: "hosts", value: [hostname], operator: "$in"}
|
|
30
39
|
]
|
|
31
|
-
}
|
|
32
|
-
|
|
40
|
+
},
|
|
41
|
+
organization_id: process.env.organization_id
|
|
33
42
|
})
|
|
34
43
|
if (!organization || !organization.document || !organization.document[0])
|
|
35
|
-
return res.send('Organization cannot be found using the
|
|
44
|
+
return res.send('Organization cannot be found using the host---: ' + hostname + ' in platformDB: ' + process.env.organization_id);
|
|
36
45
|
|
|
37
46
|
organization_id = organization.document[0]._id
|
|
47
|
+
organizations.set(hostname, organization_id)
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
let [url, parameters] = req.url.split("?");
|
|
@@ -55,7 +65,7 @@ class CoCreateFileSystem {
|
|
|
55
65
|
collection: 'files',
|
|
56
66
|
filter: {
|
|
57
67
|
query: [
|
|
58
|
-
{name: "
|
|
68
|
+
{name: "hosts", value: [hostname, '*'], operator: "$in"},
|
|
59
69
|
{name: "path", value: url, operator: "$eq"}
|
|
60
70
|
]
|
|
61
71
|
},
|