@cocreate/file-server 1.0.53 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.1.1](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.1.0...v1.1.1) (2023-04-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * removed console.log ([94904b7](https://github.com/CoCreate-app/CoCreate-file-server/commit/94904b70b9741eba1a29172dc3dca1f2f6d3edf3))
7
+
8
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.53...v1.1.0) (2023-04-23)
9
+
10
+
11
+ ### Features
12
+
13
+ * store organizaton_id in map to prevent repeated db queries ([74c0540](https://github.com/CoCreate-app/CoCreate-file-server/commit/74c05407df2118a9b1601181a7a42c1ac7bdad32))
14
+
1
15
  ## [1.0.53](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.52...v1.0.53) (2023-04-11)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.0.53",
3
+ "version": "1.1.1",
4
4
  "description": "A simple file-server component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "file-server",
package/src/index.js CHANGED
@@ -4,23 +4,32 @@
4
4
  *
5
5
  * SPDX-License-Identifier: MIT
6
6
  ********************************************************************************/
7
- const express = require('express');
8
- const router = express.Router();
9
- const mime = require('mime-types');
10
- const dns = require('dns');
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',
@@ -32,9 +41,10 @@ class CoCreateFileSystem {
32
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 host: ' + hostname + ' in platformDB: ' + process.env.organization_id);
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("?");