@cocreate/file-server 1.15.2 → 1.16.1
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 +23 -0
- package/package.json +1 -1
- package/src/index.js +31 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## [1.16.1](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.16.0...v1.16.1) (2024-01-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* wildcard without ext should defualt to */index.html ([7779170](https://github.com/CoCreate-app/CoCreate-file-server/commit/77791709688373f51db672937f3b64c1f1fae5a3))
|
|
7
|
+
|
|
8
|
+
# [1.16.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.15.2...v1.16.0) (2024-01-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* applied host to define environment/branch ([e3ad9e0](https://github.com/CoCreate-app/CoCreate-file-server/commit/e3ad9e0f38aafa3710d3ae49957ebe714b765e22))
|
|
14
|
+
* convert storage to boolean ([280a178](https://github.com/CoCreate-app/CoCreate-file-server/commit/280a178da956cb943e41d13854e330709ed2b1eb))
|
|
15
|
+
* removed host.files as handled from crud-server ([5418c06](https://github.com/CoCreate-app/CoCreate-file-server/commit/5418c06cc00985115045bcfbfc03d56cafaf3a09))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* bumped CoCreate dependencies to their latest versions ([5ad1994](https://github.com/CoCreate-app/CoCreate-file-server/commit/5ad199440e9023fa25301c7eef98f033c5832e66))
|
|
21
|
+
* query wildcard pathname ([bdd4e99](https://github.com/CoCreate-app/CoCreate-file-server/commit/bdd4e998bd986469dad99d6976c2fc9288ddef1d))
|
|
22
|
+
* routing logic per host ([7964778](https://github.com/CoCreate-app/CoCreate-file-server/commit/7964778ce6ee231c39ea6ce7721e6ec5da3ad107))
|
|
23
|
+
|
|
1
24
|
## [1.15.2](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.15.1...v1.15.2) (2023-12-31)
|
|
2
25
|
|
|
3
26
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -27,21 +27,45 @@ class CoCreateFileSystem {
|
|
|
27
27
|
|
|
28
28
|
async send(req, res, crud, organization, valideUrl) {
|
|
29
29
|
try {
|
|
30
|
+
if (!organization) {
|
|
31
|
+
let hostNotFound = await getDefaultFile('/hostNotFound.html')
|
|
32
|
+
return sendResponse(hostNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
const organization_id = organization._id
|
|
31
36
|
const hostname = valideUrl.hostname;
|
|
32
37
|
|
|
33
38
|
res.setHeader('organization', organization_id)
|
|
34
|
-
res.setHeader('storage', organization.storage);
|
|
39
|
+
res.setHeader('storage', !!organization.storage);
|
|
35
40
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
36
41
|
res.setHeader('Access-Control-Allow-Methods', '');
|
|
37
42
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
38
43
|
|
|
44
|
+
let active = crud.wsManager.organizations.get(organization_id)
|
|
45
|
+
if (active === false) {
|
|
46
|
+
let balanceFalse = await getDefaultFile('/balanceFalse.html')
|
|
47
|
+
return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
let parameters = valideUrl.searchParams;
|
|
40
51
|
if (parameters.size) {
|
|
41
52
|
console.log('parameters', parameters)
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
let pathname = valideUrl.pathname;
|
|
56
|
+
|
|
57
|
+
let lastIndex = pathname.lastIndexOf('/');
|
|
58
|
+
let wildcardPath = pathname.substring(0, lastIndex + 1);
|
|
59
|
+
let wildcard = pathname.substring(lastIndex + 1);
|
|
60
|
+
|
|
61
|
+
if (wildcard.includes('.')) {
|
|
62
|
+
let fileLastIndex = wildcard.lastIndexOf('.');
|
|
63
|
+
let fileExtension = wildcard.substring(fileLastIndex); // Get extension
|
|
64
|
+
wildcard = wildcardPath + '*' + fileExtension; // Create wildcard for file name
|
|
65
|
+
} else {
|
|
66
|
+
wildcard = wildcardPath + '*/index.html'; // Append '*' if it's just a path or folder
|
|
67
|
+
}
|
|
68
|
+
|
|
45
69
|
if (pathname.endsWith('/')) {
|
|
46
70
|
pathname += "index.html";
|
|
47
71
|
} else if (!pathname.startsWith('/.well-known/acme-challenge')) {
|
|
@@ -50,19 +74,17 @@ class CoCreateFileSystem {
|
|
|
50
74
|
pathname += "/index.html";
|
|
51
75
|
}
|
|
52
76
|
|
|
53
|
-
|
|
54
|
-
if (active === false) {
|
|
55
|
-
let balanceFalse = await getDefaultFile('/balanceFalse.html')
|
|
56
|
-
return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
|
|
57
|
-
}
|
|
77
|
+
// console.log("Wildcard: ", wildcard);
|
|
58
78
|
|
|
59
79
|
let data = {
|
|
60
80
|
method: 'object.read',
|
|
81
|
+
host: hostname,
|
|
61
82
|
array: 'files',
|
|
62
83
|
$filter: {
|
|
63
84
|
query: [
|
|
64
85
|
{ key: "host", value: [hostname, '*'], operator: "$in" },
|
|
65
|
-
{ key: "pathname", value: pathname, operator: "$
|
|
86
|
+
{ key: "pathname", value: pathname, operator: "$or" },
|
|
87
|
+
{ key: "pathname", value: wildcard, operator: "$or" }
|
|
66
88
|
],
|
|
67
89
|
limit: 1
|
|
68
90
|
},
|
|
@@ -92,6 +114,7 @@ class CoCreateFileSystem {
|
|
|
92
114
|
else {
|
|
93
115
|
let fileSrc = await crud.send({
|
|
94
116
|
method: 'object.read',
|
|
117
|
+
host: hostname,
|
|
95
118
|
array: file['array'],
|
|
96
119
|
object: {
|
|
97
120
|
_id: file._id
|
|
@@ -180,6 +203,7 @@ class CoCreateFileSystem {
|
|
|
180
203
|
|
|
181
204
|
crud.send({
|
|
182
205
|
method: 'object.create',
|
|
206
|
+
host: hostname,
|
|
183
207
|
array: 'files',
|
|
184
208
|
object: defaultFile.object[0],
|
|
185
209
|
organization_id
|