@cocreate/file-server 1.16.4 → 1.16.6
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 +17 -0
- package/package.json +1 -1
- package/src/index.js +54 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## [1.16.6](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.5...v1.16.6) (2024-06-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* base64 test ([8dd6ffc](https://github.com/CoCreate-app/CoCreate-file-server/commit/8dd6ffc8d4a24116056ea392ae697e61bb523ed5))
|
|
7
|
+
|
|
8
|
+
## [1.16.5](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.4...v1.16.5) (2024-04-26)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* data object structure ([46fef9e](https://github.com/CoCreate-app/CoCreate-file-server/commit/46fef9e8892bf9af7efc4dad34b1287dd4286bbf))
|
|
14
|
+
* handling of src data to format for sending over network ([591b84b](https://github.com/CoCreate-app/CoCreate-file-server/commit/591b84bdc2b53ccd41266ab4bab0048d15790fd7))
|
|
15
|
+
* properly handle encoding ([2f37b7e](https://github.com/CoCreate-app/CoCreate-file-server/commit/2f37b7e90332e63edeff1c348c84356ec73ab193))
|
|
16
|
+
* removed console.log ([d7d010f](https://github.com/CoCreate-app/CoCreate-file-server/commit/d7d010f99284a68b775d2e9f9b07aee631f19cd6))
|
|
17
|
+
|
|
1
18
|
## [1.16.4](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.3...v1.16.4) (2024-02-13)
|
|
2
19
|
|
|
3
20
|
|
package/package.json
CHANGED
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
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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))
|
|
@@ -136,9 +152,12 @@ class CoCreateFileSystem {
|
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
let contentType = file['content-type'] || 'text/html';
|
|
139
|
-
|
|
155
|
+
// const cleanedSrc = src.replace(/\s/g, '');
|
|
156
|
+
if (/^data:image\/[a-zA-Z0-9+.-]+;base64,([A-Za-z0-9+/]+={0,2})$/.test(src)) {
|
|
140
157
|
src = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
|
|
141
158
|
src = Buffer.from(src, 'base64');
|
|
159
|
+
} else if (/^([A-Za-z0-9+/]+={0,2})$/.test(src)) {
|
|
160
|
+
src = Buffer.from(src, 'base64');
|
|
142
161
|
} else if (contentType === 'text/html') {
|
|
143
162
|
try {
|
|
144
163
|
src = await this.render.HTML(src, organization_id);
|
|
@@ -150,18 +169,30 @@ class CoCreateFileSystem {
|
|
|
150
169
|
sendResponse(src, 200, { 'Content-Type': contentType })
|
|
151
170
|
|
|
152
171
|
function sendResponse(src, statusCode, headers) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
172
|
+
try {
|
|
173
|
+
if (src instanceof Uint8Array) {
|
|
174
|
+
src = Buffer.from(src);
|
|
175
|
+
} else if (Buffer.isBuffer(src)) {
|
|
176
|
+
console.log('buffer')
|
|
177
|
+
return
|
|
178
|
+
} else if (typeof src === 'object') {
|
|
179
|
+
src = JSON.stringify(src);
|
|
180
|
+
}
|
|
158
181
|
|
|
159
|
-
|
|
160
|
-
|
|
182
|
+
crud.wsManager.emit("setBandwidth", {
|
|
183
|
+
type: 'out',
|
|
184
|
+
data: src,
|
|
185
|
+
organization_id
|
|
186
|
+
});
|
|
187
|
+
res.writeHead(statusCode, headers);
|
|
188
|
+
return res.end(src);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.log(error)
|
|
191
|
+
}
|
|
161
192
|
}
|
|
162
193
|
|
|
163
194
|
async function getDefaultFile(fileName) {
|
|
164
|
-
data.$filter.query.$or[0]
|
|
195
|
+
data.$filter.query.$or[0] = { pathname: fileName }
|
|
165
196
|
let defaultFile
|
|
166
197
|
if (fileName !== '/hostNotFound.html')
|
|
167
198
|
defaultFile = await crud.send(data);
|