@cocreate/file-server 1.18.2 → 1.18.4

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,19 @@
1
+ ## [1.18.4](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.3...v1.18.4) (2025-09-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * enhance file retrieval with BCP 47 language support and improve fallback logic ([f3f44f8](https://github.com/CoCreate-app/CoCreate-file-server/commit/f3f44f83a7b6403a3a080dc8e040eb0141dcfab1))
7
+ * improve language handling in HTML rendering by conditionally setting langRegion and lang ([ea72c6e](https://github.com/CoCreate-app/CoCreate-file-server/commit/ea72c6eb2519d0564d7af181fcaee387ff5ee0b3))
8
+ * refactor send method to use urlObject and enhance BCP 47 language handling ([c9f8591](https://github.com/CoCreate-app/CoCreate-file-server/commit/c9f859168beebad80df3e46de9cc74a43bbc11b2))
9
+
10
+ ## [1.18.3](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.2...v1.18.3) (2025-05-01)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * update [@cocreate](https://github.com/cocreate) dependencies ([a14042f](https://github.com/CoCreate-app/CoCreate-file-server/commit/a14042fc921c439697db6ec8ac26346871da3860))
16
+
1
17
  ## [1.18.2](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.1...v1.18.2) (2025-04-30)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,18 +1,10 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.18.2",
3
+ "version": "1.18.4",
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",
7
- "cocreate",
8
- "low-code-framework",
9
- "no-code-framework",
10
- "cocreatejs",
11
- "cocreatejs-component",
12
- "cocreate-framework",
13
- "no-code",
14
7
  "low-code",
15
- "collaborative-framework",
16
8
  "realtime",
17
9
  "realtime-framework",
18
10
  "collaboration",
package/src/index.js CHANGED
@@ -26,9 +26,9 @@ class CoCreateFileSystem {
26
26
  this.sitemap = sitemap;
27
27
  }
28
28
 
29
- async send(req, res, crud, organization, valideUrl) {
29
+ async send(req, res, crud, organization, urlObject) {
30
30
  try {
31
- const hostname = valideUrl.hostname;
31
+ const hostname = urlObject.hostname;
32
32
 
33
33
  let data = {
34
34
  method: "object.read",
@@ -72,12 +72,12 @@ class CoCreateFileSystem {
72
72
  });
73
73
  }
74
74
 
75
- let parameters = valideUrl.searchParams;
75
+ let parameters = urlObject.searchParams;
76
76
  if (parameters.size) {
77
77
  console.log("parameters", parameters);
78
78
  }
79
79
 
80
- let pathname = valideUrl.pathname;
80
+ let pathname = urlObject.pathname;
81
81
 
82
82
  if (pathname.endsWith("/")) {
83
83
  pathname += "index.html";
@@ -86,7 +86,17 @@ class CoCreateFileSystem {
86
86
  if (!directory.includes(".")) pathname += "/index.html";
87
87
  }
88
88
 
89
- data.$filter.query.pathname = pathname;
89
+ const bcp47Regex = /^\/([a-zA-Z]{2,3}(?:-[a-zA-Z0-9]{2,8})+)\//;
90
+ const match = pathname.match(bcp47Regex);
91
+ let lang, langRegion;
92
+ if (match) {
93
+ langRegion = match[1];
94
+ lang = langRegion.split("-")[0]; // Get just the base language (e.g., 'en', 'es', 'fr')
95
+ let newPathname = pathname.replace(langRegion, lang);
96
+ data.$filter.query.pathname = { $in: [newPathname, pathname] };
97
+ } else {
98
+ data.$filter.query.pathname = pathname;
99
+ }
90
100
 
91
101
  let file;
92
102
  if (
@@ -99,12 +109,15 @@ class CoCreateFileSystem {
99
109
  "/manifest.webmanifest",
100
110
  "/service-worker.js"
101
111
  ].includes(pathname)
102
- )
112
+ ) {
103
113
  file = await getDefaultFile(pathname);
104
- else file = await crud.send(data);
114
+ } else {
115
+ file = await crud.send(data);
116
+ }
105
117
 
118
+ // --- Wildcard fallback ---
106
119
  if (!file || !file.object || !file.object[0]) {
107
- pathname = valideUrl.pathname;
120
+ pathname = urlObject.pathname;
108
121
  let lastIndex = pathname.lastIndexOf("/");
109
122
  let wildcardPath = pathname.substring(0, lastIndex + 1);
110
123
  let wildcard = pathname.substring(lastIndex + 1);
@@ -137,8 +150,9 @@ class CoCreateFileSystem {
137
150
  }
138
151
 
139
152
  let src;
140
- if (file["src"]) src = file["src"];
141
- else {
153
+ if (file["src"]) {
154
+ src = file["src"];
155
+ } else {
142
156
  let fileSrc = await crud.send({
143
157
  method: "object.read",
144
158
  host: hostname,
@@ -179,11 +193,14 @@ class CoCreateFileSystem {
179
193
  src = Buffer.from(src, "base64");
180
194
  } else if (contentType === "text/html") {
181
195
  try {
182
- src = await this.render.HTML(
183
- src,
184
- organization_id,
185
- valideUrl
186
- );
196
+ file.urlObject = urlObject;
197
+ if (langRegion) {
198
+ file.langRegion = langRegion;
199
+ }
200
+ if (lang) {
201
+ file.lang = lang;
202
+ }
203
+ src = await this.render.HTML(file);
187
204
  } catch (err) {
188
205
  console.warn("server-side-render: " + err.message);
189
206
  }