Skip to content

Commit

Permalink
feat: Log inBound and outBound bandwidth
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Aug 27, 2023
1 parent f7ac18d commit 2f79c40
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class CoCreateFileSystem {
organization = { _id: org.object[0]._id, storage: !!org.object[0].storage }
organizations.set(hostname, organization)
}

}

let organization_id = organization._id
Expand Down Expand Up @@ -133,6 +132,18 @@ class CoCreateFileSystem {

const fileContent = req.headers['File-Content']
if (fileContent && !pathname.startsWith('/superadmin')) {
crud.wsManager.emit("setBandwidth", {
type: 'in',
data: fileContent,
organization_id
});

crud.wsManager.emit("setBandwidth", {
type: 'out',
data: fileContent,
organization_id
});

res.writeHead(200, { 'Content-Type': req.headers['Content-Type'] });
return res.end(fileContent);
}
Expand All @@ -147,6 +158,13 @@ class CoCreateFileSystem {
pageNotFound = default404 || `${pathname} could not be found for ${organization_id}`
else
pageNotFound = pageNotFound.object[0].src

crud.wsManager.emit("setBandwidth", {
type: 'out',
data: pageNotFound,
organization_id
});

res.writeHead(404, { 'Content-Type': 'text/html' });
return res.end(pageNotFound);
}
Expand All @@ -162,6 +180,13 @@ class CoCreateFileSystem {
pageForbidden = default403 || `${pathname} access not allowed for ${organization_id}`
else
pageForbidden = pageForbidden.object[0].src

crud.wsManager.emit("setBandwidth", {
type: 'out',
data: pageForbidden,
organization_id
});

res.writeHead(403, { 'Content-Type': 'text/html' });
return res.end(pageForbidden);
}
Expand Down Expand Up @@ -192,6 +217,11 @@ class CoCreateFileSystem {
else
pageNotFound = pageNotFound.object[0].src

crud.wsManager.emit("setBandwidth", {
type: 'out',
data: pageNotFound,
organization_id
});

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

crud.wsManager.emit("setBandwidth", {
type: 'out',
data: src,
organization_id
});

res.writeHead(200, { 'Content-Type': contentType });
return res.end(src);
} catch (error) {
Expand Down

0 comments on commit 2f79c40

Please sign in to comment.