@cocreate/file-server 1.18.7 → 1.18.8

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,10 @@
1
+ ## [1.18.8](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.7...v1.18.8) (2025-10-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * improve file content decoding and enhance font handling logic ([8bddb02](https://github.com/CoCreate-app/CoCreate-file-server/commit/8bddb0249c9748a90ac1442073ba464a053d9074))
7
+
1
8
  ## [1.18.7](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.6...v1.18.7) (2025-10-08)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.18.7",
3
+ "version": "1.18.8",
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
@@ -199,35 +199,13 @@ class CoCreateFileSystem {
199
199
 
200
200
  let contentType = file["content-type"] || "text/html";
201
201
 
202
- try {
203
- if (typeof src === "string") {
204
- // Decode the file content based on its MIME type
205
- if (/^(image|audio|video|font|application\/octet-stream|application\/x-font-ttf|application\/x-font-woff|application\/x-font-woff2|application\/x-font-opentype|application\/x-font-truetype|application\/x-font-eot)/.test(contentType)) {
206
- src = Buffer.from(src, "base64");
207
- } else if (/^(application\/zip|application\/x-7z-compressed|application\/x-rar-compressed|application\/pdf)/.test(contentType)) {
208
- src = Buffer.from(src, "binary");
209
- } else {
210
- src = Buffer.from(src, "utf8");
211
- }
212
- } else {
213
- throw new Error("File content is not in a valid format");
214
- }
215
- } catch (err) {
216
- console.error("Error decoding file content:", {
217
- message: err.message,
218
- contentType,
219
- srcType: typeof src
220
- });
221
- let pageNotFound = await getDefaultFile("/404.html");
222
- return sendResponse(pageNotFound.object[0].src, 404, {
223
- "Content-Type": "text/html"
224
- });
225
- }
226
-
227
202
  // Remove redundant handling for `src.src` in font file processing
228
203
  if (contentType.startsWith("font/") || /\.(woff2?|ttf|otf)$/i.test(pathname)) {
229
204
  try {
230
205
  if (typeof src === "string") {
206
+ if (src.startsWith("data:font/")) {
207
+ src = src.substring(src.indexOf(",") + 1);
208
+ }
231
209
  if (/^([A-Za-z0-9+/]+={0,2})$/.test(src)) {
232
210
  // Decode base64-encoded font data
233
211
  src = Buffer.from(src, "base64");
@@ -275,10 +253,10 @@ class CoCreateFileSystem {
275
253
  contentType === "text/xml" ||
276
254
  contentType === "application/xml"
277
255
  ) {
278
- const protocol = "https://"; // || req.headers['x-forwarded-proto'] || req.protocol;
256
+ const protocol = "https://";
279
257
  src = src.replaceAll("{{$host}}", `${protocol}${hostname}`);
280
- } else {
281
- // Log unknown file types
258
+ } else if (contentType !== "text/javascript" || contentType === "text/css") {
259
+
282
260
  console.warn(`Unknown content type: ${contentType}`);
283
261
  }
284
262