@cocreate/file-server 1.18.6 → 1.18.7
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 +7 -0
- package/package.json +1 -1
- package/src/index.js +31 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.18.7](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.6...v1.18.7) (2025-10-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* enhance file content handling and error logging for font files ([3093df3](https://github.com/CoCreate-app/CoCreate-file-server/commit/3093df39c633ff4e6add31c20c57c469c751ab1a))
|
|
7
|
+
|
|
1
8
|
## [1.18.6](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.5...v1.18.6) (2025-10-08)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -199,7 +199,32 @@ class CoCreateFileSystem {
|
|
|
199
199
|
|
|
200
200
|
let contentType = file["content-type"] || "text/html";
|
|
201
201
|
|
|
202
|
-
|
|
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
|
+
// Remove redundant handling for `src.src` in font file processing
|
|
203
228
|
if (contentType.startsWith("font/") || /\.(woff2?|ttf|otf)$/i.test(pathname)) {
|
|
204
229
|
try {
|
|
205
230
|
if (typeof src === "string") {
|
|
@@ -209,22 +234,14 @@ class CoCreateFileSystem {
|
|
|
209
234
|
} else {
|
|
210
235
|
throw new Error("Font data is not valid base64");
|
|
211
236
|
}
|
|
212
|
-
} else if (typeof src === "object" && src.src) {
|
|
213
|
-
// Handle case where src is an object containing base64 data
|
|
214
|
-
if (/^([A-Za-z0-9+/]+={0,2})$/.test(src.src)) {
|
|
215
|
-
src = Buffer.from(src.src, "base64");
|
|
216
|
-
} else {
|
|
217
|
-
throw new Error("Font data inside object is not valid base64");
|
|
218
|
-
}
|
|
219
237
|
} else {
|
|
220
|
-
throw new Error("Font data is not a valid base64 string
|
|
238
|
+
throw new Error("Font data is not a valid base64 string");
|
|
221
239
|
}
|
|
222
240
|
} catch (err) {
|
|
223
241
|
console.error("Error processing font file:", {
|
|
224
242
|
message: err.message,
|
|
225
243
|
contentType,
|
|
226
|
-
srcType: typeof src
|
|
227
|
-
srcPreview: typeof src === "string" ? src.slice(0, 50) : null
|
|
244
|
+
srcType: typeof src
|
|
228
245
|
});
|
|
229
246
|
let pageNotFound = await getDefaultFile("/404.html");
|
|
230
247
|
return sendResponse(pageNotFound.object[0].src, 404, {
|
|
@@ -260,6 +277,9 @@ class CoCreateFileSystem {
|
|
|
260
277
|
) {
|
|
261
278
|
const protocol = "https://"; // || req.headers['x-forwarded-proto'] || req.protocol;
|
|
262
279
|
src = src.replaceAll("{{$host}}", `${protocol}${hostname}`);
|
|
280
|
+
} else {
|
|
281
|
+
// Log unknown file types
|
|
282
|
+
console.warn(`Unknown content type: ${contentType}`);
|
|
263
283
|
}
|
|
264
284
|
|
|
265
285
|
sendResponse(src, 200, { "Content-Type": contentType });
|