@cocreate/file-server 1.9.2 → 1.10.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 +8 -0
- package/package.json +1 -1
- package/src/index.js +51 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# [1.10.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.9.2...v1.10.0) (2023-09-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* defaultFile balanceFalse returned as response if organization balance false below 0 ([ecd86b1](https://github.com/CoCreate-app/CoCreate-file-server/commit/ecd86b1ee76007bbfffa88841072970804cc8e98))
|
|
7
|
+
* Log inBound and outBound bandwidth ([2f79c40](https://github.com/CoCreate-app/CoCreate-file-server/commit/2f79c40e8429c6cb189964a51f4a275497bc352b))
|
|
8
|
+
|
|
1
9
|
## [1.9.2](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.9.1...v1.9.2) (2023-08-21)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -42,7 +42,7 @@ class CoCreateFileSystem {
|
|
|
42
42
|
return file.object[0].src
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
let default403, default404, hostNotFound, signup
|
|
45
|
+
let default403, default404, hostNotFound, signup, balanceFalse
|
|
46
46
|
defaultFiles('/403.html').then((file) => {
|
|
47
47
|
default403 = file
|
|
48
48
|
})
|
|
@@ -52,6 +52,9 @@ class CoCreateFileSystem {
|
|
|
52
52
|
defaultFiles('/hostNotFound.html').then((file) => {
|
|
53
53
|
hostNotFound = file
|
|
54
54
|
})
|
|
55
|
+
defaultFiles('/balanceFalse').then((file) => {
|
|
56
|
+
balanceFalse = file
|
|
57
|
+
})
|
|
55
58
|
defaultFiles('/superadmin/signup.html').then((file) => {
|
|
56
59
|
signup = file
|
|
57
60
|
})
|
|
@@ -76,22 +79,25 @@ class CoCreateFileSystem {
|
|
|
76
79
|
|
|
77
80
|
if (!org || !org.object || !org.object[0]) {
|
|
78
81
|
hostNotFound = hostNotFound || 'An organization could not be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
|
|
79
|
-
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
80
|
-
if (org.storage === false && org.error)
|
|
81
|
-
res.setHeader('storage', 'false')
|
|
82
|
-
else
|
|
83
|
-
res.setHeader('storage', 'true')
|
|
84
|
-
|
|
82
|
+
res.writeHead(404, { 'Content-Type': 'text/html', 'storage': organization.storage });
|
|
85
83
|
return res.end(hostNotFound);
|
|
86
84
|
} else {
|
|
87
85
|
organization = { _id: org.object[0]._id, storage: !!org.object[0].storage }
|
|
88
86
|
organizations.set(hostname, organization)
|
|
89
87
|
}
|
|
90
|
-
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
let organization_id = organization._id
|
|
91
|
+
|
|
92
|
+
let active = crud.wsManager.organizations.get(organization_id)
|
|
93
|
+
if (active === false) {
|
|
94
|
+
balanceFalse = balanceFalse || 'This organizations account balance has fallen bellow 0: '
|
|
95
|
+
res.writeHead(404, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage });
|
|
96
|
+
return res.end(balanceFalse);
|
|
97
|
+
}
|
|
98
|
+
|
|
94
99
|
res.setHeader('organization', organization_id)
|
|
100
|
+
res.setHeader('storage', organization.storage);
|
|
95
101
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
96
102
|
res.setHeader('Access-Control-Allow-Methods', '');
|
|
97
103
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
@@ -126,13 +132,21 @@ class CoCreateFileSystem {
|
|
|
126
132
|
data.organization_id = process.env.organization_id
|
|
127
133
|
|
|
128
134
|
let file = await crud.send(data);
|
|
129
|
-
if (file.storage === false && file.error)
|
|
130
|
-
res.setHeader('storage', 'false')
|
|
131
|
-
else
|
|
132
|
-
res.setHeader('storage', 'true')
|
|
133
135
|
|
|
134
136
|
const fileContent = req.headers['File-Content']
|
|
135
137
|
if (fileContent && !pathname.startsWith('/superadmin')) {
|
|
138
|
+
crud.wsManager.emit("setBandwidth", {
|
|
139
|
+
type: 'in',
|
|
140
|
+
data: fileContent,
|
|
141
|
+
organization_id
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
crud.wsManager.emit("setBandwidth", {
|
|
145
|
+
type: 'out',
|
|
146
|
+
data: fileContent,
|
|
147
|
+
organization_id
|
|
148
|
+
});
|
|
149
|
+
|
|
136
150
|
res.writeHead(200, { 'Content-Type': req.headers['Content-Type'] });
|
|
137
151
|
return res.end(fileContent);
|
|
138
152
|
}
|
|
@@ -147,6 +161,13 @@ class CoCreateFileSystem {
|
|
|
147
161
|
pageNotFound = default404 || `${pathname} could not be found for ${organization_id}`
|
|
148
162
|
else
|
|
149
163
|
pageNotFound = pageNotFound.object[0].src
|
|
164
|
+
|
|
165
|
+
crud.wsManager.emit("setBandwidth", {
|
|
166
|
+
type: 'out',
|
|
167
|
+
data: pageNotFound,
|
|
168
|
+
organization_id
|
|
169
|
+
});
|
|
170
|
+
|
|
150
171
|
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
151
172
|
return res.end(pageNotFound);
|
|
152
173
|
}
|
|
@@ -162,6 +183,13 @@ class CoCreateFileSystem {
|
|
|
162
183
|
pageForbidden = default403 || `${pathname} access not allowed for ${organization_id}`
|
|
163
184
|
else
|
|
164
185
|
pageForbidden = pageForbidden.object[0].src
|
|
186
|
+
|
|
187
|
+
crud.wsManager.emit("setBandwidth", {
|
|
188
|
+
type: 'out',
|
|
189
|
+
data: pageForbidden,
|
|
190
|
+
organization_id
|
|
191
|
+
});
|
|
192
|
+
|
|
165
193
|
res.writeHead(403, { 'Content-Type': 'text/html' });
|
|
166
194
|
return res.end(pageForbidden);
|
|
167
195
|
}
|
|
@@ -192,6 +220,11 @@ class CoCreateFileSystem {
|
|
|
192
220
|
else
|
|
193
221
|
pageNotFound = pageNotFound.object[0].src
|
|
194
222
|
|
|
223
|
+
crud.wsManager.emit("setBandwidth", {
|
|
224
|
+
type: 'out',
|
|
225
|
+
data: pageNotFound,
|
|
226
|
+
organization_id
|
|
227
|
+
});
|
|
195
228
|
|
|
196
229
|
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
197
230
|
return res.end(pageNotFound);
|
|
@@ -212,6 +245,12 @@ class CoCreateFileSystem {
|
|
|
212
245
|
if (file.modified)
|
|
213
246
|
res.setHeader('Last-Modified', file.modified.on);
|
|
214
247
|
|
|
248
|
+
crud.wsManager.emit("setBandwidth", {
|
|
249
|
+
type: 'out',
|
|
250
|
+
data: src,
|
|
251
|
+
organization_id
|
|
252
|
+
});
|
|
253
|
+
|
|
215
254
|
res.writeHead(200, { 'Content-Type': contentType });
|
|
216
255
|
return res.end(src);
|
|
217
256
|
} catch (error) {
|