Skip to content

Commit 12c5edd

Browse files
committed
testing fileSystem and wild card
1 parent a402e76 commit 12c5edd

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/index.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class CoCreateFileSystem {
2727

2828
async send(req, res, crud, organization, valideUrl) {
2929
try {
30+
if (!organization) {
31+
let hostNotFound = await getDefaultFile('/hostNotFound.html')
32+
return sendResponse(hostNotFound.object[0].src, 404, { 'Content-Type': 'text/html' })
33+
}
34+
3035
const organization_id = organization._id
3136
const hostname = valideUrl.hostname;
3237

@@ -56,19 +61,49 @@ class CoCreateFileSystem {
5661
return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
5762
}
5863

64+
let lastIndex = pathname.lastIndexOf('/');
65+
let wildcardPath = pathname.substring(0, lastIndex + 1);
66+
let wildcard = pathname.substring(lastIndex + 1);
67+
68+
if (wildcard.includes('.')) {
69+
let fileLastIndex = wildcard.lastIndexOf('.');
70+
let fileExtension = wildcard.substring(fileLastIndex); // Get extension
71+
wildcard = wildcardPath + '*' + fileExtension; // Create wildcard for file name
72+
} else {
73+
wildcard = wildcardPath + '*'; // Append '*' if it's just a path or folder
74+
}
75+
76+
// console.log("Wildcard: ", wildcard);
77+
5978
let data = {
6079
method: 'object.read',
6180
array: 'files',
6281
$filter: {
6382
query: [
6483
{ key: "host", value: [hostname, '*'], operator: "$in" },
65-
{ key: "pathname", value: pathname, operator: "$eq" }
84+
{ key: "pathname", value: pathname, operator: "$eq" },
85+
// { key: "pathname", value: wildcard, operator: "$eq", logicalOperator: "or" }
6686
],
6787
limit: 1
6888
},
6989
organization_id
7090
}
7191

92+
if (organization.fileSystem) {
93+
let fileSystem = organization.fileSystem.find(element => element.name === hostname)
94+
for (let i = 0; i < fileSystem; i++) {
95+
if (fileSystem[i].name === hostname) {
96+
if (fileSystem[i].storage)
97+
data.storage = fileSystem[i].storage
98+
if (fileSystem[i].database)
99+
data.database = fileSystem[i].database
100+
if (fileSystem[i].array)
101+
data.array = fileSystem[i].array
102+
break
103+
}
104+
}
105+
}
106+
72107
let file
73108
if (pathname.startsWith('/dist') || pathname.startsWith('/admin') || ['/403.html', '/404.html', '/offline.html', '/manifest.webmanifest', '/service-worker.js'].includes(pathname))
74109
file = await getDefaultFile(pathname)

0 commit comments

Comments
 (0)