@cocreate/file-server 1.15.1 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ # [1.16.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.15.2...v1.16.0) (2024-01-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * applied host to define environment/branch ([e3ad9e0](https://github.com/CoCreate-app/CoCreate-file-server/commit/e3ad9e0f38aafa3710d3ae49957ebe714b765e22))
7
+ * convert storage to boolean ([280a178](https://github.com/CoCreate-app/CoCreate-file-server/commit/280a178da956cb943e41d13854e330709ed2b1eb))
8
+ * removed host.files as handled from crud-server ([5418c06](https://github.com/CoCreate-app/CoCreate-file-server/commit/5418c06cc00985115045bcfbfc03d56cafaf3a09))
9
+
10
+
11
+ ### Features
12
+
13
+ * bumped CoCreate dependencies to their latest versions ([5ad1994](https://github.com/CoCreate-app/CoCreate-file-server/commit/5ad199440e9023fa25301c7eef98f033c5832e66))
14
+ * query wildcard pathname ([bdd4e99](https://github.com/CoCreate-app/CoCreate-file-server/commit/bdd4e998bd986469dad99d6976c2fc9288ddef1d))
15
+ * routing logic per host ([7964778](https://github.com/CoCreate-app/CoCreate-file-server/commit/7964778ce6ee231c39ea6ce7721e6ec5da3ad107))
16
+
17
+ ## [1.15.2](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.15.1...v1.15.2) (2023-12-31)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * handling wellknown and fix modified on bug ([987d161](https://github.com/CoCreate-app/CoCreate-file-server/commit/987d1612797ea70c300c3f1472c11bf10b38efb2))
23
+
1
24
  ## [1.15.1](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.15.0...v1.15.1) (2023-12-18)
2
25
 
3
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.15.1",
3
+ "version": "1.16.0",
4
4
  "description": "A simple file-server component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "file-server",
package/src/index.js CHANGED
@@ -27,11 +27,16 @@ class CoCreateFileSystem {
27
27
 
28
28
  async send(req, res, crud, organization, valideUrl) {
29
29
  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
+
30
35
  const organization_id = organization._id
31
36
  const hostname = valideUrl.hostname;
32
37
 
33
38
  res.setHeader('organization', organization_id)
34
- res.setHeader('storage', organization.storage);
39
+ res.setHeader('storage', !!organization.storage);
35
40
  res.setHeader('Access-Control-Allow-Origin', '*');
36
41
  res.setHeader('Access-Control-Allow-Methods', '');
37
42
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
@@ -44,7 +49,7 @@ class CoCreateFileSystem {
44
49
  let pathname = valideUrl.pathname;
45
50
  if (pathname.endsWith('/')) {
46
51
  pathname += "index.html";
47
- } else {
52
+ } else if (!pathname.startsWith('/.well-known/acme-challenge')) {
48
53
  let directory = pathname.split("/").slice(-1)[0];
49
54
  if (!directory.includes('.'))
50
55
  pathname += "/index.html";
@@ -56,13 +61,29 @@ class CoCreateFileSystem {
56
61
  return sendResponse(balanceFalse.object[0].src, 403, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage })
57
62
  }
58
63
 
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
+
59
78
  let data = {
60
79
  method: 'object.read',
80
+ host: hostname,
61
81
  array: 'files',
62
82
  $filter: {
63
83
  query: [
64
84
  { key: "host", value: [hostname, '*'], operator: "$in" },
65
- { key: "pathname", value: pathname, operator: "$eq" }
85
+ { key: "pathname", value: pathname, operator: "$or" },
86
+ { key: "pathname", value: wildcard, operator: "$or" }
66
87
  ],
67
88
  limit: 1
68
89
  },
@@ -92,6 +113,7 @@ class CoCreateFileSystem {
92
113
  else {
93
114
  let fileSrc = await crud.send({
94
115
  method: 'object.read',
116
+ host: hostname,
95
117
  array: file['array'],
96
118
  object: {
97
119
  _id: file._id
@@ -107,8 +129,9 @@ class CoCreateFileSystem {
107
129
  }
108
130
 
109
131
 
110
- if (file.modified || file.created) {
111
- let modifiedOn = file.modified.on || file.created.on
132
+ let modifiedOn = file.modified || file.created
133
+ if (modifiedOn) {
134
+ modifiedOn = modifiedOn.on
112
135
  if (modifiedOn instanceof Date)
113
136
  modifiedOn = modifiedOn.toISOString()
114
137
  res.setHeader('Last-Modified', modifiedOn);
@@ -179,6 +202,7 @@ class CoCreateFileSystem {
179
202
 
180
203
  crud.send({
181
204
  method: 'object.create',
205
+ host: hostname,
182
206
  array: 'files',
183
207
  object: defaultFile.object[0],
184
208
  organization_id