@cocreate/file-server 1.16.3 → 1.16.5

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,20 @@
1
+ ## [1.16.5](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.4...v1.16.5) (2024-04-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * data object structure ([46fef9e](https://github.com/CoCreate-app/CoCreate-file-server/commit/46fef9e8892bf9af7efc4dad34b1287dd4286bbf))
7
+ * handling of src data to format for sending over network ([591b84b](https://github.com/CoCreate-app/CoCreate-file-server/commit/591b84bdc2b53ccd41266ab4bab0048d15790fd7))
8
+ * properly handle encoding ([2f37b7e](https://github.com/CoCreate-app/CoCreate-file-server/commit/2f37b7e90332e63edeff1c348c84356ec73ab193))
9
+ * removed console.log ([d7d010f](https://github.com/CoCreate-app/CoCreate-file-server/commit/d7d010f99284a68b775d2e9f9b07aee631f19cd6))
10
+
11
+ ## [1.16.4](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.3...v1.16.4) (2024-02-13)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * removed comment ([f7ca055](https://github.com/CoCreate-app/CoCreate-file-server/commit/f7ca05589ac46fee98f6f46242688da6fd231b8b))
17
+
1
18
  ## [1.16.3](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.2...v1.16.3) (2024-02-05)
2
19
 
3
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.16.3",
3
+ "version": "1.16.5",
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,13 +27,28 @@ class CoCreateFileSystem {
27
27
 
28
28
  async send(req, res, crud, organization, valideUrl) {
29
29
  try {
30
+ const hostname = valideUrl.hostname;
31
+
32
+ let data = {
33
+ method: 'object.read',
34
+ host: hostname,
35
+ array: 'files',
36
+ $filter: {
37
+ query: {
38
+ host: { $in: [hostname, '*'] },
39
+ $or: []
40
+ },
41
+ limit: 1
42
+ }
43
+ }
44
+
30
45
  if (!organization || organization.error) {
31
46
  let hostNotFound = await getDefaultFile('/hostNotFound.html')
32
47
  return sendResponse(hostNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
33
48
  }
34
49
 
35
50
  const organization_id = organization._id
36
- const hostname = valideUrl.hostname;
51
+ data.organization_id = organization_id
37
52
 
38
53
  res.setHeader('organization', organization_id)
39
54
  res.setHeader('storage', !!organization.storage);
@@ -74,21 +89,20 @@ class CoCreateFileSystem {
74
89
  pathname += "/index.html";
75
90
  }
76
91
 
77
- // console.log("Wildcard: ", wildcard);
78
-
79
- let data = {
80
- method: 'object.read',
81
- host: hostname,
82
- array: 'files',
83
- $filter: {
84
- query: {
85
- host: { $in: [hostname, '*'] },
86
- $or: [{ pathname }, { pathname: wildcard }]
87
- },
88
- limit: 1
89
- },
90
- organization_id
91
- }
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 }]
92
106
 
93
107
  let file
94
108
  if (pathname.startsWith('/dist') || pathname.startsWith('/admin') || ['/403.html', '/404.html', '/offline.html', '/manifest.webmanifest', '/service-worker.js'].includes(pathname))
@@ -152,18 +166,30 @@ class CoCreateFileSystem {
152
166
  sendResponse(src, 200, { 'Content-Type': contentType })
153
167
 
154
168
  function sendResponse(src, statusCode, headers) {
155
- crud.wsManager.emit("setBandwidth", {
156
- type: 'out',
157
- data: src,
158
- organization_id
159
- });
169
+ try {
170
+ if (src instanceof Uint8Array) {
171
+ src = Buffer.from(src);
172
+ } else if (Buffer.isBuffer(src)) {
173
+ console.log('buffer')
174
+ return
175
+ } else if (typeof src === 'object') {
176
+ src = JSON.stringify(src);
177
+ }
160
178
 
161
- res.writeHead(statusCode, headers);
162
- return res.end(src);
179
+ crud.wsManager.emit("setBandwidth", {
180
+ type: 'out',
181
+ data: src,
182
+ organization_id
183
+ });
184
+ res.writeHead(statusCode, headers);
185
+ return res.end(src);
186
+ } catch (error) {
187
+ console.log(error)
188
+ }
163
189
  }
164
190
 
165
191
  async function getDefaultFile(fileName) {
166
- data.$filter.query.$or[0].pathname = fileName
192
+ data.$filter.query.$or[0] = { pathname: fileName }
167
193
  let defaultFile
168
194
  if (fileName !== '/hostNotFound.html')
169
195
  defaultFile = await crud.send(data);