@cocreate/file-server 1.16.9 → 1.16.11

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,19 @@
1
+ ## [1.16.11](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.10...v1.16.11) (2024-08-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * $or operator removed from getDefaultFile ([d9f2b90](https://github.com/CoCreate-app/CoCreate-file-server/commit/d9f2b905b302a721ac8af847375e52af29f575dd))
7
+ * add sitemap handling plugin ([870b15d](https://github.com/CoCreate-app/CoCreate-file-server/commit/870b15d93ad935538befcb0f7c85bc2110e4ede5))
8
+ * query for file if not returned query for wildcard ([1af8851](https://github.com/CoCreate-app/CoCreate-file-server/commit/1af885132fcc47180b2756605988b0edd1841404))
9
+
10
+ ## [1.16.10](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.9...v1.16.10) (2024-06-23)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * lock file ([7c55696](https://github.com/CoCreate-app/CoCreate-file-server/commit/7c556963990d2c79bdb2078929d4f24e88160cef))
16
+
1
17
  ## [1.16.9](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.8...v1.16.9) (2024-06-23)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.16.9",
3
+ "version": "1.16.11",
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
@@ -21,8 +21,9 @@
21
21
  // For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
22
22
 
23
23
  class CoCreateFileSystem {
24
- constructor(render) {
24
+ constructor(render, sitemap) {
25
25
  this.render = render
26
+ this.sitemap = sitemap
26
27
  }
27
28
 
28
29
  async send(req, res, crud, organization, valideUrl) {
@@ -35,8 +36,7 @@ class CoCreateFileSystem {
35
36
  array: 'files',
36
37
  $filter: {
37
38
  query: {
38
- host: { $in: [hostname, '*'] },
39
- $or: []
39
+ host: { $in: [hostname, '*'] }
40
40
  },
41
41
  limit: 1
42
42
  }
@@ -69,18 +69,6 @@ class CoCreateFileSystem {
69
69
 
70
70
  let pathname = valideUrl.pathname;
71
71
 
72
- let lastIndex = pathname.lastIndexOf('/');
73
- let wildcardPath = pathname.substring(0, lastIndex + 1);
74
- let wildcard = pathname.substring(lastIndex + 1);
75
-
76
- if (wildcard.includes('.')) {
77
- let fileLastIndex = wildcard.lastIndexOf('.');
78
- let fileExtension = wildcard.substring(fileLastIndex); // Get extension
79
- wildcard = wildcardPath + '*' + fileExtension; // Create wildcard for file name
80
- } else {
81
- wildcard = wildcardPath + '*/index.html'; // Append '*' if it's just a path or folder
82
- }
83
-
84
72
  if (pathname.endsWith('/')) {
85
73
  pathname += "index.html";
86
74
  } else if (!pathname.startsWith('/.well-known/acme-challenge')) {
@@ -89,20 +77,7 @@ class CoCreateFileSystem {
89
77
  pathname += "/index.html";
90
78
  }
91
79
 
92
- // let data = {
93
- // method: 'object.read',
94
- // host: hostname,
95
- // array: 'files',
96
- // $filter: {
97
- // query: {
98
- // host: { $in: [hostname, '*'] },
99
- // $or: [{ pathname }, { pathname: wildcard }]
100
- // },
101
- // limit: 1
102
- // },
103
- // organization_id
104
- // }
105
- data.$filter.query.$or = [{ pathname }, { pathname: wildcard }]
80
+ data.$filter.query.pathname = pathname
106
81
 
107
82
  let file
108
83
  if (pathname.startsWith('/dist') || pathname.startsWith('/admin') || ['/403.html', '/404.html', '/offline.html', '/manifest.webmanifest', '/service-worker.js'].includes(pathname))
@@ -110,6 +85,24 @@ class CoCreateFileSystem {
110
85
  else
111
86
  file = await crud.send(data);
112
87
 
88
+ if (!file || !file.object || !file.object[0]) {
89
+ pathname = valideUrl.pathname
90
+ let lastIndex = pathname.lastIndexOf('/');
91
+ let wildcardPath = pathname.substring(0, lastIndex + 1);
92
+ let wildcard = pathname.substring(lastIndex + 1);
93
+
94
+ if (wildcard.includes('.')) {
95
+ let fileLastIndex = wildcard.lastIndexOf('.');
96
+ let fileExtension = wildcard.substring(fileLastIndex);
97
+ wildcard = wildcardPath + '*' + fileExtension; // Create wildcard for file name
98
+ } else {
99
+ wildcard = wildcardPath + '*/index.html'; // Append '*' if it's just a path or folder
100
+ }
101
+
102
+ data.$filter.query.pathname = wildcard
103
+ file = await crud.send(data);
104
+ }
105
+
113
106
  if (!file || !file.object || !file.object[0]) {
114
107
  let pageNotFound = await getDefaultFile('/404.html')
115
108
  return sendResponse(pageNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
@@ -167,6 +160,7 @@ class CoCreateFileSystem {
167
160
  }
168
161
 
169
162
  sendResponse(src, 200, { 'Content-Type': contentType })
163
+ this.sitemap.check(file, hostname);
170
164
 
171
165
  function sendResponse(src, statusCode, headers) {
172
166
  try {
@@ -192,7 +186,8 @@ class CoCreateFileSystem {
192
186
  }
193
187
 
194
188
  async function getDefaultFile(fileName) {
195
- data.$filter.query.$or[0] = { pathname: fileName }
189
+ data.$filter.query.pathname = fileName
190
+ // data.$filter.query.$or[0] = { pathname: fileName }
196
191
  let defaultFile
197
192
  if (fileName !== '/hostNotFound.html')
198
193
  defaultFile = await crud.send(data);
@@ -204,7 +199,7 @@ class CoCreateFileSystem {
204
199
  data.organization_id = process.env.organization_id
205
200
 
206
201
  if (fileName.startsWith('/admin'))
207
- data.$filter.query.$or[0].pathname = '/superadmin' + fileName.replace('/admin', '')
202
+ data.$filter.query.pathname = '/superadmin' + fileName.replace('/admin', '')
208
203
 
209
204
  defaultFile = await crud.send(data)
210
205