@cocreate/file-server 1.16.0 → 1.16.2

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,18 @@
1
+ ## [1.16.2](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.1...v1.16.2) (2024-01-17)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * return if organization.error ([b6425eb](https://github.com/CoCreate-app/CoCreate-file-server/commit/b6425eb780f2a031a3e68bd7f61226774d65d966))
7
+ * update to support new query system ([e46947c](https://github.com/CoCreate-app/CoCreate-file-server/commit/e46947cb3c6ee63975ae6c696e5ac5f6ef6e5cb6))
8
+
9
+ ## [1.16.1](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.0...v1.16.1) (2024-01-11)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * wildcard without ext should defualt to */index.html ([7779170](https://github.com/CoCreate-app/CoCreate-file-server/commit/77791709688373f51db672937f3b64c1f1fae5a3))
15
+
1
16
  # [1.16.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.15.2...v1.16.0) (2024-01-08)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
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
@@ -27,7 +27,7 @@ class CoCreateFileSystem {
27
27
 
28
28
  async send(req, res, crud, organization, valideUrl) {
29
29
  try {
30
- if (!organization) {
30
+ if (!organization || organization.error) {
31
31
  let hostNotFound = await getDefaultFile('/hostNotFound.html')
32
32
  return sendResponse(hostNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
33
33
  }
@@ -41,25 +41,18 @@ class CoCreateFileSystem {
41
41
  res.setHeader('Access-Control-Allow-Methods', '');
42
42
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
43
43
 
44
+ let active = crud.wsManager.organizations.get(organization_id)
45
+ if (active === false) {
46
+ let balanceFalse = await getDefaultFile('/balanceFalse.html')
47
+ return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
48
+ }
49
+
44
50
  let parameters = valideUrl.searchParams;
45
51
  if (parameters.size) {
46
52
  console.log('parameters', parameters)
47
53
  }
48
54
 
49
55
  let pathname = valideUrl.pathname;
50
- if (pathname.endsWith('/')) {
51
- pathname += "index.html";
52
- } else if (!pathname.startsWith('/.well-known/acme-challenge')) {
53
- let directory = pathname.split("/").slice(-1)[0];
54
- if (!directory.includes('.'))
55
- pathname += "/index.html";
56
- }
57
-
58
- let active = crud.wsManager.organizations.get(organization_id)
59
- if (active === false) {
60
- let balanceFalse = await getDefaultFile('/balanceFalse.html')
61
- return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
62
- }
63
56
 
64
57
  let lastIndex = pathname.lastIndexOf('/');
65
58
  let wildcardPath = pathname.substring(0, lastIndex + 1);
@@ -70,7 +63,15 @@ class CoCreateFileSystem {
70
63
  let fileExtension = wildcard.substring(fileLastIndex); // Get extension
71
64
  wildcard = wildcardPath + '*' + fileExtension; // Create wildcard for file name
72
65
  } else {
73
- wildcard = wildcardPath + '*'; // Append '*' if it's just a path or folder
66
+ wildcard = wildcardPath + '*/index.html'; // Append '*' if it's just a path or folder
67
+ }
68
+
69
+ if (pathname.endsWith('/')) {
70
+ pathname += "index.html";
71
+ } else if (!pathname.startsWith('/.well-known/acme-challenge')) {
72
+ let directory = pathname.split("/").slice(-1)[0];
73
+ if (!directory.includes('.'))
74
+ pathname += "/index.html";
74
75
  }
75
76
 
76
77
  // console.log("Wildcard: ", wildcard);
@@ -80,11 +81,10 @@ class CoCreateFileSystem {
80
81
  host: hostname,
81
82
  array: 'files',
82
83
  $filter: {
83
- query: [
84
- { key: "host", value: [hostname, '*'], operator: "$in" },
85
- { key: "pathname", value: pathname, operator: "$or" },
86
- { key: "pathname", value: wildcard, operator: "$or" }
87
- ],
84
+ query: {
85
+ host: { $in: [hostname, '*'] },
86
+ $or: [{ pathname }, { pathname: wildcard }]
87
+ },
88
88
  limit: 1
89
89
  },
90
90
  organization_id
@@ -163,7 +163,7 @@ class CoCreateFileSystem {
163
163
  }
164
164
 
165
165
  async function getDefaultFile(fileName) {
166
- data.$filter.query[1].value = fileName
166
+ data.$filter.query.$or[0].pathname = fileName
167
167
  let defaultFile
168
168
  if (fileName !== '/hostNotFound.html')
169
169
  defaultFile = await crud.send(data);
@@ -171,11 +171,11 @@ class CoCreateFileSystem {
171
171
  if (defaultFile && defaultFile.object && defaultFile.object[0] && defaultFile.object[0].src) {
172
172
  return defaultFile
173
173
  } else {
174
- data.$filter.query[0].value = ['*']
174
+ data.$filter.query.host.$in = ['*']
175
175
  data.organization_id = process.env.organization_id
176
176
 
177
177
  if (fileName.startsWith('/admin'))
178
- data.$filter.query[1].value = '/superadmin' + fileName.replace('/admin', '')
178
+ data.$filter.query.$or[0].pathname = '/superadmin' + fileName.replace('/admin', '')
179
179
 
180
180
  defaultFile = await crud.send(data)
181
181