@cocreate/file-server 1.16.4 → 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,13 @@
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
+
1
11
  ## [1.16.4](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.3...v1.16.4) (2024-02-13)
2
12
 
3
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.16.4",
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,19 +89,20 @@ class CoCreateFileSystem {
74
89
  pathname += "/index.html";
75
90
  }
76
91
 
77
- let data = {
78
- method: 'object.read',
79
- host: hostname,
80
- array: 'files',
81
- $filter: {
82
- query: {
83
- host: { $in: [hostname, '*'] },
84
- $or: [{ pathname }, { pathname: wildcard }]
85
- },
86
- limit: 1
87
- },
88
- organization_id
89
- }
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 }]
90
106
 
91
107
  let file
92
108
  if (pathname.startsWith('/dist') || pathname.startsWith('/admin') || ['/403.html', '/404.html', '/offline.html', '/manifest.webmanifest', '/service-worker.js'].includes(pathname))
@@ -150,18 +166,30 @@ class CoCreateFileSystem {
150
166
  sendResponse(src, 200, { 'Content-Type': contentType })
151
167
 
152
168
  function sendResponse(src, statusCode, headers) {
153
- crud.wsManager.emit("setBandwidth", {
154
- type: 'out',
155
- data: src,
156
- organization_id
157
- });
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
+ }
158
178
 
159
- res.writeHead(statusCode, headers);
160
- 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
+ }
161
189
  }
162
190
 
163
191
  async function getDefaultFile(fileName) {
164
- data.$filter.query.$or[0].pathname = fileName
192
+ data.$filter.query.$or[0] = { pathname: fileName }
165
193
  let defaultFile
166
194
  if (fileName !== '/hostNotFound.html')
167
195
  defaultFile = await crud.send(data);