@cocreate/file-server 1.18.4 → 1.18.5

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.5](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.4...v1.18.5) (2025-09-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * enhance Cache-Control header handling in sendResponse function ([7b6f29c](https://github.com/CoCreate-app/CoCreate-file-server/commit/7b6f29cbe1511be4fa41670db55747e8ad61bc00))
7
+
1
8
  ## [1.18.4](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.18.3...v1.18.4) (2025-09-01)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.18.4",
3
+ "version": "1.18.5",
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
@@ -217,11 +217,41 @@ class CoCreateFileSystem {
217
217
 
218
218
  function sendResponse(src, statusCode, headers) {
219
219
  try {
220
+ let cacheControl;
221
+ if (statusCode >= 400) {
222
+ cacheControl = "no-cache, no-store, must-revalidate";
223
+ } else if (
224
+ file &&
225
+ file["cache-control"] !== undefined &&
226
+ file["cache-control"] !== null
227
+ ) {
228
+ const val = file["cache-control"];
229
+ if (
230
+ typeof val === "number" ||
231
+ /^\s*\d+\s*$/.test(val)
232
+ ) {
233
+ // If it's numeric (number or numeric string) treat it as max-age.
234
+ cacheControl = `public, max-age=${String(
235
+ val
236
+ ).trim()};`;
237
+ } else {
238
+ // use the value verbatim (allow full Cache-Control strings like "no-cache" or "public, max-age=600")
239
+ cacheControl = val;
240
+ }
241
+ } else {
242
+ cacheControl =
243
+ organization["cache-control"] ||
244
+ "public, max-age=3600";
245
+ }
246
+
247
+ // Always override/set Cache-Control header so the response aligns with the file metadata/defaults
248
+ headers["Cache-Control"] = cacheControl;
249
+
220
250
  if (src instanceof Uint8Array) {
221
251
  src = Buffer.from(src);
222
252
  } else if (Buffer.isBuffer(src)) {
223
- console.log("buffer");
224
- return;
253
+ // Buffer is fine to send — don't bail out here (previous code returned early)
254
+ // keep src as-is
225
255
  } else if (typeof src === "object") {
226
256
  src = JSON.stringify(src);
227
257
  }