@cocreate/file-server 1.2.1 → 1.4.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 +20 -0
- package/CoCreate.config.js +1 -1
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/index.js +30 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
# [1.4.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.3.0...v1.4.0) (2023-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add organization_id to response headers ([2f731f5](https://github.com/CoCreate-app/CoCreate-file-server/commit/2f731f582f535d93b223bfaad98a52675953e11e))
|
|
7
|
+
|
|
8
|
+
# [1.3.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.2.1...v1.3.0) (2023-05-11)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* apikey renamed to key ([3cd1648](https://github.com/CoCreate-app/CoCreate-file-server/commit/3cd16488b21b0110ec242b1c02dffe02328153c9))
|
|
14
|
+
* replace key ([fa78c05](https://github.com/CoCreate-app/CoCreate-file-server/commit/fa78c0557c380e149336b4eefbe8e797b86b3409))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* redirect to /superadmin ([9094337](https://github.com/CoCreate-app/CoCreate-file-server/commit/909433742d08dadb1bc9f61b45850dd6eec8e1c2))
|
|
20
|
+
|
|
1
21
|
## [1.2.1](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.2.0...v1.2.1) (2023-05-10)
|
|
2
22
|
|
|
3
23
|
|
package/CoCreate.config.js
CHANGED
package/docs/index.html
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -11,13 +11,13 @@ const organizations = new Map();
|
|
|
11
11
|
|
|
12
12
|
class CoCreateFileSystem {
|
|
13
13
|
constructor(crud, render) {
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
async function defaultFiles(fileName) {
|
|
16
|
-
let file = await crud.readDocument({
|
|
16
|
+
let file = await crud.readDocument({
|
|
17
17
|
collection: 'files',
|
|
18
18
|
filter: {
|
|
19
19
|
query: [
|
|
20
|
-
{name: "path", value: fileName, operator: "$eq"}
|
|
20
|
+
{ name: "path", value: fileName, operator: "$eq" }
|
|
21
21
|
]
|
|
22
22
|
},
|
|
23
23
|
organization_id: process.env.organization_id
|
|
@@ -41,72 +41,68 @@ class CoCreateFileSystem {
|
|
|
41
41
|
signup = file
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
this.router = router.get('/*', async(req, res) => {
|
|
44
|
+
this.router = router.get('/*', async (req, res) => {
|
|
45
45
|
let hostname = req.hostname;
|
|
46
46
|
let organization = organizations.get(hostname);
|
|
47
47
|
if (!organization) {
|
|
48
|
-
let org = await crud.readDocument({
|
|
48
|
+
let org = await crud.readDocument({
|
|
49
49
|
collection: 'organizations',
|
|
50
50
|
filter: {
|
|
51
51
|
query: [
|
|
52
|
-
{name: "hosts", value: [hostname], operator: "$in"}
|
|
52
|
+
{ name: "hosts", value: [hostname], operator: "$in" }
|
|
53
53
|
]
|
|
54
54
|
},
|
|
55
55
|
organization_id: process.env.organization_id
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
if (!org || !org.document || !org.document[0]) {
|
|
59
|
-
hostNotFound = hostNotFound || 'Organization cannot be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
|
|
60
|
-
|
|
61
|
-
// res.redirect(301, '/superadmin/signup.html');
|
|
62
|
-
// if (req.url.startsWith('/superadmin/signup.html'))
|
|
63
|
-
// return res.send(signup);
|
|
64
|
-
// else
|
|
65
|
-
// return res.send(hostNotFound);
|
|
66
|
-
|
|
59
|
+
hostNotFound = hostNotFound || 'Organization cannot be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
|
|
60
|
+
return res.end(hostNotFound);
|
|
67
61
|
} else {
|
|
68
|
-
organization = {_id: org.document[0]._id
|
|
62
|
+
organization = { _id: org.document[0]._id }
|
|
69
63
|
organizations.set(hostname, organization)
|
|
70
64
|
}
|
|
71
65
|
}
|
|
72
66
|
|
|
73
67
|
let organization_id = organization._id
|
|
68
|
+
res.set('organization', organization_id)
|
|
69
|
+
|
|
74
70
|
let [url, parameters] = req.url.split("?");
|
|
75
|
-
if (parameters){}
|
|
71
|
+
if (parameters) { }
|
|
76
72
|
if (url.endsWith('/')) {
|
|
77
73
|
url += "index.html";
|
|
78
74
|
} else {
|
|
79
75
|
let directory = url.split("/").slice(-1)[0];
|
|
80
|
-
if (!directory.includes('.')){
|
|
76
|
+
if (!directory.includes('.')) {
|
|
81
77
|
url += "/index.html";
|
|
82
78
|
}
|
|
83
79
|
}
|
|
84
|
-
|
|
80
|
+
|
|
85
81
|
let data = {
|
|
86
82
|
collection: 'files',
|
|
87
83
|
filter: {
|
|
88
84
|
query: [
|
|
89
|
-
{name: "hosts", value: [hostname, '*'], operator: "$in"},
|
|
90
|
-
{name: "path", value: url, operator: "$eq"}
|
|
85
|
+
{ name: "hosts", value: [hostname, '*'], operator: "$in" },
|
|
86
|
+
{ name: "path", value: url, operator: "$eq" }
|
|
91
87
|
]
|
|
92
88
|
},
|
|
93
89
|
organization_id
|
|
94
90
|
}
|
|
95
91
|
|
|
96
|
-
if (url.startsWith('/superadmin'))
|
|
92
|
+
if (url.startsWith('/superadmin'))
|
|
97
93
|
data.organization_id = process.env.organization_id
|
|
98
94
|
|
|
99
95
|
let file = await crud.readDocument(data);
|
|
100
|
-
|
|
96
|
+
|
|
101
97
|
if (!file || !file.document || !file.document[0]) {
|
|
102
98
|
data.filter.query[1].value = '/404.html'
|
|
103
99
|
if (data.organization_id !== organization_id)
|
|
104
100
|
data.organization_id = organization_id
|
|
105
101
|
|
|
106
|
-
let pageNotFound = await crud.readDocument(data);
|
|
102
|
+
let pageNotFound = await crud.readDocument(data);
|
|
107
103
|
if (!pageNotFound || !pageNotFound.document || !pageNotFound.document[0])
|
|
108
104
|
pageNotFound = default404 || `${url} could not be found for ${organization_id}`
|
|
109
|
-
else
|
|
105
|
+
else
|
|
110
106
|
pageNotFound = pageNotFound.document[0].src
|
|
111
107
|
return res.status(404).send(pageNotFound);
|
|
112
108
|
}
|
|
@@ -117,15 +113,15 @@ class CoCreateFileSystem {
|
|
|
117
113
|
if (data.organization_id !== organization_id)
|
|
118
114
|
data.organization_id = organization_id
|
|
119
115
|
|
|
120
|
-
let pageForbidden = await crud.readDocument(data);
|
|
116
|
+
let pageForbidden = await crud.readDocument(data);
|
|
121
117
|
if (!pageForbidden || !pageForbidden.document || !pageForbidden.document[0])
|
|
122
118
|
pageForbidden = default403 || `${url} access not allowed for ${organization_id}`
|
|
123
|
-
else
|
|
119
|
+
else
|
|
124
120
|
pageForbidden = pageForbidden.document[0].src
|
|
125
121
|
|
|
126
122
|
return res.status(403).send(pageForbidden);
|
|
127
123
|
}
|
|
128
|
-
|
|
124
|
+
|
|
129
125
|
let src;
|
|
130
126
|
if (file['src'])
|
|
131
127
|
src = file['src'];
|
|
@@ -139,18 +135,18 @@ class CoCreateFileSystem {
|
|
|
139
135
|
});
|
|
140
136
|
src = fileSrc[file['name']];
|
|
141
137
|
}
|
|
142
|
-
|
|
138
|
+
|
|
143
139
|
if (!src) {
|
|
144
140
|
data.filter.query[1].value = '/404.html'
|
|
145
141
|
if (data.organization_id !== organization_id)
|
|
146
142
|
data.organization_id = organization_id
|
|
147
143
|
|
|
148
|
-
let pageNotFound = await crud.readDocument(data);
|
|
144
|
+
let pageNotFound = await crud.readDocument(data);
|
|
149
145
|
if (!pageNotFound || !pageNotFound.document || !pageNotFound.document[0])
|
|
150
|
-
pageNotFound = `${url} could not be found for ${organization_id}`
|
|
146
|
+
pageNotFound = `${url} could not be found for ${organization_id}`
|
|
151
147
|
return res.status(404).send(pageNotFound);
|
|
152
148
|
}
|
|
153
|
-
|
|
149
|
+
|
|
154
150
|
let contentType = file['content-type'] || mime.lookup(url) || 'text/html';
|
|
155
151
|
|
|
156
152
|
if (contentType.startsWith('image/') || contentType.startsWith('audio/') || contentType.startsWith('video/')) {
|
|
@@ -162,18 +158,13 @@ class CoCreateFileSystem {
|
|
|
162
158
|
} catch (err) {
|
|
163
159
|
console.warn('server-render: ' + err.message)
|
|
164
160
|
}
|
|
165
|
-
}
|
|
166
|
-
if (process.env.organization_id !== organization_id && url.startsWith('/superadmin') && contentType === 'text/html' && !url.includes('/signup.html')) {
|
|
167
|
-
src = src.replace(process.env.organization_id, organization_id)
|
|
168
|
-
src = src.replace(process.env.key, organization.key)
|
|
169
161
|
}
|
|
170
162
|
|
|
171
163
|
return res.type(contentType).send(src);
|
|
172
|
-
|
|
164
|
+
|
|
173
165
|
})
|
|
174
|
-
|
|
175
|
-
}
|
|
166
|
+
|
|
167
|
+
}
|
|
176
168
|
}
|
|
177
169
|
|
|
178
170
|
module.exports = CoCreateFileSystem;
|
|
179
|
-
|