Skip to content

Commit

Permalink
feat: defaultFile balanceFalse returned as response if organization b…
Browse files Browse the repository at this point in the history
…alance false below 0
  • Loading branch information
frankpagan committed Sep 6, 2023
1 parent 2f79c40 commit ecd86b1
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CoCreateFileSystem {
return file.object[0].src
}

let default403, default404, hostNotFound, signup
let default403, default404, hostNotFound, signup, balanceFalse
defaultFiles('/403.html').then((file) => {
default403 = file
})
Expand All @@ -52,6 +52,9 @@ class CoCreateFileSystem {
defaultFiles('/hostNotFound.html').then((file) => {
hostNotFound = file
})
defaultFiles('/balanceFalse').then((file) => {
balanceFalse = file
})
defaultFiles('/superadmin/signup.html').then((file) => {
signup = file
})
Expand All @@ -76,12 +79,7 @@ class CoCreateFileSystem {

if (!org || !org.object || !org.object[0]) {
hostNotFound = hostNotFound || 'An organization could not be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
res.writeHead(404, { 'Content-Type': 'text/html' });
if (org.storage === false && org.error)
res.setHeader('storage', 'false')
else
res.setHeader('storage', 'true')

res.writeHead(404, { 'Content-Type': 'text/html', 'storage': organization.storage });
return res.end(hostNotFound);
} else {
organization = { _id: org.object[0]._id, storage: !!org.object[0].storage }
Expand All @@ -90,7 +88,16 @@ class CoCreateFileSystem {
}

let organization_id = organization._id

let active = crud.wsManager.organizations.get(organization_id)
if (active === false) {
balanceFalse = balanceFalse || 'This organizations account balance has fallen bellow 0: '
res.writeHead(404, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage });
return res.end(balanceFalse);
}

res.setHeader('organization', organization_id)
res.setHeader('storage', organization.storage);
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '');
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
Expand Down Expand Up @@ -125,10 +132,6 @@ class CoCreateFileSystem {
data.organization_id = process.env.organization_id

let file = await crud.send(data);
if (file.storage === false && file.error)
res.setHeader('storage', 'false')
else
res.setHeader('storage', 'true')

const fileContent = req.headers['File-Content']
if (fileContent && !pathname.startsWith('/superadmin')) {
Expand Down

0 comments on commit ecd86b1

Please sign in to comment.