Skip to content

Commit 2f79c40

Browse files
committed
feat: Log inBound and outBound bandwidth
1 parent f7ac18d commit 2f79c40

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/index.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class CoCreateFileSystem {
8787
organization = { _id: org.object[0]._id, storage: !!org.object[0].storage }
8888
organizations.set(hostname, organization)
8989
}
90-
9190
}
9291

9392
let organization_id = organization._id
@@ -133,6 +132,18 @@ class CoCreateFileSystem {
133132

134133
const fileContent = req.headers['File-Content']
135134
if (fileContent && !pathname.startsWith('/superadmin')) {
135+
crud.wsManager.emit("setBandwidth", {
136+
type: 'in',
137+
data: fileContent,
138+
organization_id
139+
});
140+
141+
crud.wsManager.emit("setBandwidth", {
142+
type: 'out',
143+
data: fileContent,
144+
organization_id
145+
});
146+
136147
res.writeHead(200, { 'Content-Type': req.headers['Content-Type'] });
137148
return res.end(fileContent);
138149
}
@@ -147,6 +158,13 @@ class CoCreateFileSystem {
147158
pageNotFound = default404 || `${pathname} could not be found for ${organization_id}`
148159
else
149160
pageNotFound = pageNotFound.object[0].src
161+
162+
crud.wsManager.emit("setBandwidth", {
163+
type: 'out',
164+
data: pageNotFound,
165+
organization_id
166+
});
167+
150168
res.writeHead(404, { 'Content-Type': 'text/html' });
151169
return res.end(pageNotFound);
152170
}
@@ -162,6 +180,13 @@ class CoCreateFileSystem {
162180
pageForbidden = default403 || `${pathname} access not allowed for ${organization_id}`
163181
else
164182
pageForbidden = pageForbidden.object[0].src
183+
184+
crud.wsManager.emit("setBandwidth", {
185+
type: 'out',
186+
data: pageForbidden,
187+
organization_id
188+
});
189+
165190
res.writeHead(403, { 'Content-Type': 'text/html' });
166191
return res.end(pageForbidden);
167192
}
@@ -192,6 +217,11 @@ class CoCreateFileSystem {
192217
else
193218
pageNotFound = pageNotFound.object[0].src
194219

220+
crud.wsManager.emit("setBandwidth", {
221+
type: 'out',
222+
data: pageNotFound,
223+
organization_id
224+
});
195225

196226
res.writeHead(404, { 'Content-Type': 'text/html' });
197227
return res.end(pageNotFound);
@@ -212,6 +242,12 @@ class CoCreateFileSystem {
212242
if (file.modified)
213243
res.setHeader('Last-Modified', file.modified.on);
214244

245+
crud.wsManager.emit("setBandwidth", {
246+
type: 'out',
247+
data: src,
248+
organization_id
249+
});
250+
215251
res.writeHead(200, { 'Content-Type': contentType });
216252
return res.end(src);
217253
} catch (error) {

0 commit comments

Comments
 (0)