Skip to content

Commit 5d6d232

Browse files
committed
fix: moved $filter outside of object
1 parent 1d05b5c commit 5d6d232

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

src/index.js

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,18 @@ class CoCreateFileSystem {
3939
let org = await crud.send({
4040
method: 'read.object',
4141
array: 'organizations',
42-
object: {
43-
$filter: {
44-
query: [
45-
{ key: "host", value: [hostname], operator: "$in" }
46-
]
47-
}
42+
$filter: {
43+
query: [
44+
{ key: "host", value: [hostname], operator: "$in" }
45+
]
4846
},
4947
organization_id: process.env.organization_id
5048
})
5149

5250
if (!org || !org.object || !org.object[0]) {
5351
if (!hostNotFound)
5452
hostNotFound = await getDefaultFile('/hostNotFound.html')
55-
return sendResponse(hostNotFound.src, 404, { 'Content-Type': 'text/html', 'storage': organization.storage })
53+
return sendResponse(hostNotFound.object[0].src, 404, { 'Content-Type': 'text/html', 'storage': organization.storage })
5654
} else {
5755
organization = { _id: org.object[0]._id, storage: !!org.object[0].storage }
5856
organizations.set(hostname, organization)
@@ -84,7 +82,7 @@ class CoCreateFileSystem {
8482
let active = crud.wsManager.organizations.get(organization_id)
8583
if (active === false) {
8684
let balanceFalse = await getDefaultFile('/balanceFalse.html')
87-
return sendResponse(balanceFalse.src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
85+
return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
8886
}
8987

9088
const fileContent = req.headers['File-Content']
@@ -101,14 +99,12 @@ class CoCreateFileSystem {
10199
let data = {
102100
method: 'read.object',
103101
array: 'files',
104-
object: {
105-
$filter: {
106-
query: [
107-
{ key: "host", value: [hostname, '*'], operator: "$in" },
108-
{ key: "path", value: pathname, operator: "$eq" }
109-
],
110-
limit: 1
111-
}
102+
$filter: {
103+
query: [
104+
{ key: "host", value: [hostname, '*'], operator: "$in" },
105+
{ key: "path", value: pathname, operator: "$eq" }
106+
],
107+
limit: 1
112108
},
113109
organization_id
114110
}
@@ -122,13 +118,13 @@ class CoCreateFileSystem {
122118

123119
if (!file || !file.object || !file.object[0]) {
124120
let pageNotFound = await getDefaultFile('/404.html')
125-
return sendResponse(pageNotFound.src, 404, { 'Content-Type': 'text/html' })
121+
return sendResponse(pageNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
126122
}
127123

128124
file = file.object[0]
129125
if (!file['public'] || file['public'] === "false") {
130126
let pageForbidden = await getDefaultFile('/403.html')
131-
return sendResponse(pageForbidden.src, 403, { 'Content-Type': 'text/html' })
127+
return sendResponse(pageForbidden.object[0].src, 403, { 'Content-Type': 'text/html' })
132128
}
133129

134130
let src;
@@ -148,7 +144,7 @@ class CoCreateFileSystem {
148144

149145
if (!src) {
150146
let pageNotFound = await getDefaultFile('/404.html')
151-
return sendResponse(pageNotFound.src, 404, { 'Content-Type': 'text/html' })
147+
return sendResponse(pageNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
152148
}
153149

154150
let contentType = file['content-type'] || 'text/html';
@@ -180,15 +176,15 @@ class CoCreateFileSystem {
180176
}
181177

182178
async function getDefaultFile(fileName) {
183-
data.object.$filter.query[1].value = fileName
179+
data.$filter.query[1].value = fileName
184180
let defaultFile
185181
if (fileName !== '/hostNotFound.html')
186182
defaultFile = await crud.send(data);
187183

188184
if (defaultFile && defaultFile.object && defaultFile.object[0] && defaultFile.object[0].src) {
189-
return defaultFile.object[0]
185+
return defaultFile
190186
} else {
191-
data.object.$filter.query[0].value = ['*']
187+
data.$filter.query[0].value = ['*']
192188
data.organization_id = process.env.organization_id
193189

194190
defaultFile = await crud.send(data)
@@ -215,20 +211,20 @@ class CoCreateFileSystem {
215211
organization_id
216212
})
217213

218-
return defaultFile.object[0]
214+
return defaultFile
219215
} else {
220216
switch (fileName) {
221217
case '/403.html':
222-
defaultFile = { src: `${pathname} access not allowed for ${organization_id}` };
218+
defaultFile.object = [{ src: `${pathname} access not allowed for ${organization_id}` }]
223219
break;
224220
case '/404.html':
225-
defaultFile = { src: `${pathname} could not be found for ${organization_id}` };
221+
defaultFile.object = [{ src: `${pathname} could not be found for ${organization_id}` }];
226222
break;
227223
case '/balanceFalse.html':
228-
defaultFile = { src: 'This organizations account balance has fallen bellow 0: ' };
224+
defaultFile.object = [{ src: 'This organizations account balance has fallen bellow 0: ' }];
229225
break;
230226
case '/hostNotFound.html':
231-
defaultFile = { src: 'An organization could not be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id };
227+
defaultFile.object = [{ src: 'An organization could not be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id }];
232228
break;
233229
}
234230
return defaultFile

0 commit comments

Comments
 (0)