@cocreate/file-server 1.16.10 → 1.17.0
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 +16 -0
- package/package.json +1 -1
- package/src/index.js +31 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [1.17.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.11...v1.17.0) (2024-09-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* serve xml files and replaceAll {${host}} placeholders with requesting host ([7bda848](https://github.com/CoCreate-app/CoCreate-file-server/commit/7bda84882688c504e04c63e6f44546815754fe86))
|
|
7
|
+
|
|
8
|
+
## [1.16.11](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.10...v1.16.11) (2024-08-30)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* $or operator removed from getDefaultFile ([d9f2b90](https://github.com/CoCreate-app/CoCreate-file-server/commit/d9f2b905b302a721ac8af847375e52af29f575dd))
|
|
14
|
+
* add sitemap handling plugin ([870b15d](https://github.com/CoCreate-app/CoCreate-file-server/commit/870b15d93ad935538befcb0f7c85bc2110e4ede5))
|
|
15
|
+
* query for file if not returned query for wildcard ([1af8851](https://github.com/CoCreate-app/CoCreate-file-server/commit/1af885132fcc47180b2756605988b0edd1841404))
|
|
16
|
+
|
|
1
17
|
## [1.16.10](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.9...v1.16.10) (2024-06-23)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
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
|
-
|
|
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' })
|
|
@@ -152,7 +145,7 @@ class CoCreateFileSystem {
|
|
|
152
145
|
}
|
|
153
146
|
|
|
154
147
|
let contentType = file['content-type'] || 'text/html';
|
|
155
|
-
|
|
148
|
+
|
|
156
149
|
if (/^data:image\/[a-zA-Z0-9+.-]+;base64,([A-Za-z0-9+/]+={0,2})$/.test(src)) {
|
|
157
150
|
src = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
|
|
158
151
|
src = Buffer.from(src, 'base64');
|
|
@@ -162,11 +155,15 @@ class CoCreateFileSystem {
|
|
|
162
155
|
try {
|
|
163
156
|
src = await this.render.HTML(src, organization_id);
|
|
164
157
|
} catch (err) {
|
|
165
|
-
console.warn('server-render: ' + err.message)
|
|
158
|
+
console.warn('server-side-render: ' + err.message)
|
|
166
159
|
}
|
|
160
|
+
} else if (contentType === 'text/xml' || contentType === 'application/xml') {
|
|
161
|
+
const protocol = 'https://' // || req.headers['x-forwarded-proto'] || req.protocol;
|
|
162
|
+
src = src.replaceAll('{{$host}}', `${protocol}${hostname}`)
|
|
167
163
|
}
|
|
168
164
|
|
|
169
165
|
sendResponse(src, 200, { 'Content-Type': contentType })
|
|
166
|
+
this.sitemap.check(file, hostname);
|
|
170
167
|
|
|
171
168
|
function sendResponse(src, statusCode, headers) {
|
|
172
169
|
try {
|
|
@@ -192,7 +189,8 @@ class CoCreateFileSystem {
|
|
|
192
189
|
}
|
|
193
190
|
|
|
194
191
|
async function getDefaultFile(fileName) {
|
|
195
|
-
data.$filter.query
|
|
192
|
+
data.$filter.query.pathname = fileName
|
|
193
|
+
// data.$filter.query.$or[0] = { pathname: fileName }
|
|
196
194
|
let defaultFile
|
|
197
195
|
if (fileName !== '/hostNotFound.html')
|
|
198
196
|
defaultFile = await crud.send(data);
|
|
@@ -204,7 +202,7 @@ class CoCreateFileSystem {
|
|
|
204
202
|
data.organization_id = process.env.organization_id
|
|
205
203
|
|
|
206
204
|
if (fileName.startsWith('/admin'))
|
|
207
|
-
data.$filter.query
|
|
205
|
+
data.$filter.query.pathname = '/superadmin' + fileName.replace('/admin', '')
|
|
208
206
|
|
|
209
207
|
defaultFile = await crud.send(data)
|
|
210
208
|
|