@valbuild/server 0.60.4 → 0.60.6

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.
@@ -1834,13 +1834,15 @@ function bufferToReadableStream(buffer) {
1834
1834
  start(controller) {
1835
1835
  const chunkSize = 1024; // Adjust the chunk size as needed
1836
1836
  let offset = 0;
1837
+ let isClosed = false;
1837
1838
  function push() {
1838
1839
  const chunk = buffer.subarray(offset, offset + chunkSize);
1839
1840
  offset += chunkSize;
1840
1841
  if (chunk.length > 0) {
1841
1842
  controller.enqueue(new Uint8Array(chunk));
1842
1843
  setTimeout(push, 0); // Enqueue the next chunk asynchronously
1843
- } else {
1844
+ } else if (!isClosed) {
1845
+ isClosed = true;
1844
1846
  controller.close();
1845
1847
  }
1846
1848
  }
@@ -2109,6 +2111,7 @@ class LocalValServer extends ValServer {
2109
2111
  };
2110
2112
  }
2111
2113
  async getFiles(filePath, query) {
2114
+ console.log("getfiles", query);
2112
2115
  if (query.sha256) {
2113
2116
  const fileExists = this.host.fileExists(this.getFilePath(filePath, query.sha256));
2114
2117
  if (fileExists) {
@@ -2125,7 +2128,8 @@ class LocalValServer extends ValServer {
2125
2128
  status: 200,
2126
2129
  headers: {
2127
2130
  "Content-Type": metadata.mimeType,
2128
- "Content-Length": fileContent.byteLength.toString()
2131
+ "Content-Length": fileContent.byteLength.toString(),
2132
+ "Cache-Control": "public, max-age=31536000, immutable"
2129
2133
  },
2130
2134
  body: bufferToReadableStream(fileContent)
2131
2135
  };
@@ -2141,6 +2145,20 @@ class LocalValServer extends ValServer {
2141
2145
  }
2142
2146
  };
2143
2147
  }
2148
+ if (query.sha256) {
2149
+ const sha256 = getSha256(mimeType, buffer);
2150
+ if (sha256 === query.sha256) {
2151
+ return {
2152
+ status: 200,
2153
+ headers: {
2154
+ "Content-Type": mimeType,
2155
+ "Content-Length": buffer.byteLength.toString(),
2156
+ "Cache-Control": "public, max-age=31536000, immutable"
2157
+ },
2158
+ body: bufferToReadableStream(buffer)
2159
+ };
2160
+ }
2161
+ }
2144
2162
  return {
2145
2163
  status: 200,
2146
2164
  headers: {
@@ -2976,7 +2994,8 @@ class ProxyValServer extends ValServer {
2976
2994
  status: fetchRes.status,
2977
2995
  headers: {
2978
2996
  "Content-Type": fetchRes.headers.get("Content-Type") || "",
2979
- "Content-Length": fetchRes.headers.get("Content-Length") || "0"
2997
+ "Content-Length": fetchRes.headers.get("Content-Length") || "0",
2998
+ "Cache-Control": "public, max-age=31536000, immutable"
2980
2999
  },
2981
3000
  body: fetchRes.body
2982
3001
  };
@@ -3003,6 +3022,20 @@ class ProxyValServer extends ValServer {
3003
3022
  };
3004
3023
  }
3005
3024
  const mimeType = guessMimeTypeFromPath(filePath) || "application/octet-stream";
3025
+ if (query.sha256) {
3026
+ const sha256 = getSha256(mimeType, buffer);
3027
+ if (sha256 === query.sha256) {
3028
+ return {
3029
+ status: 200,
3030
+ headers: {
3031
+ "Content-Type": mimeType,
3032
+ "Content-Length": buffer.byteLength.toString(),
3033
+ "Cache-Control": "public, max-age=31536000, immutable"
3034
+ },
3035
+ body: bufferToReadableStream(buffer)
3036
+ };
3037
+ }
3038
+ }
3006
3039
  return {
3007
3040
  status: 200,
3008
3041
  headers: {
@@ -1834,13 +1834,15 @@ function bufferToReadableStream(buffer) {
1834
1834
  start(controller) {
1835
1835
  const chunkSize = 1024; // Adjust the chunk size as needed
1836
1836
  let offset = 0;
1837
+ let isClosed = false;
1837
1838
  function push() {
1838
1839
  const chunk = buffer.subarray(offset, offset + chunkSize);
1839
1840
  offset += chunkSize;
1840
1841
  if (chunk.length > 0) {
1841
1842
  controller.enqueue(new Uint8Array(chunk));
1842
1843
  setTimeout(push, 0); // Enqueue the next chunk asynchronously
1843
- } else {
1844
+ } else if (!isClosed) {
1845
+ isClosed = true;
1844
1846
  controller.close();
1845
1847
  }
1846
1848
  }
@@ -2109,6 +2111,7 @@ class LocalValServer extends ValServer {
2109
2111
  };
2110
2112
  }
2111
2113
  async getFiles(filePath, query) {
2114
+ console.log("getfiles", query);
2112
2115
  if (query.sha256) {
2113
2116
  const fileExists = this.host.fileExists(this.getFilePath(filePath, query.sha256));
2114
2117
  if (fileExists) {
@@ -2125,7 +2128,8 @@ class LocalValServer extends ValServer {
2125
2128
  status: 200,
2126
2129
  headers: {
2127
2130
  "Content-Type": metadata.mimeType,
2128
- "Content-Length": fileContent.byteLength.toString()
2131
+ "Content-Length": fileContent.byteLength.toString(),
2132
+ "Cache-Control": "public, max-age=31536000, immutable"
2129
2133
  },
2130
2134
  body: bufferToReadableStream(fileContent)
2131
2135
  };
@@ -2141,6 +2145,20 @@ class LocalValServer extends ValServer {
2141
2145
  }
2142
2146
  };
2143
2147
  }
2148
+ if (query.sha256) {
2149
+ const sha256 = getSha256(mimeType, buffer);
2150
+ if (sha256 === query.sha256) {
2151
+ return {
2152
+ status: 200,
2153
+ headers: {
2154
+ "Content-Type": mimeType,
2155
+ "Content-Length": buffer.byteLength.toString(),
2156
+ "Cache-Control": "public, max-age=31536000, immutable"
2157
+ },
2158
+ body: bufferToReadableStream(buffer)
2159
+ };
2160
+ }
2161
+ }
2144
2162
  return {
2145
2163
  status: 200,
2146
2164
  headers: {
@@ -2976,7 +2994,8 @@ class ProxyValServer extends ValServer {
2976
2994
  status: fetchRes.status,
2977
2995
  headers: {
2978
2996
  "Content-Type": fetchRes.headers.get("Content-Type") || "",
2979
- "Content-Length": fetchRes.headers.get("Content-Length") || "0"
2997
+ "Content-Length": fetchRes.headers.get("Content-Length") || "0",
2998
+ "Cache-Control": "public, max-age=31536000, immutable"
2980
2999
  },
2981
3000
  body: fetchRes.body
2982
3001
  };
@@ -3003,6 +3022,20 @@ class ProxyValServer extends ValServer {
3003
3022
  };
3004
3023
  }
3005
3024
  const mimeType = guessMimeTypeFromPath(filePath) || "application/octet-stream";
3025
+ if (query.sha256) {
3026
+ const sha256 = getSha256(mimeType, buffer);
3027
+ if (sha256 === query.sha256) {
3028
+ return {
3029
+ status: 200,
3030
+ headers: {
3031
+ "Content-Type": mimeType,
3032
+ "Content-Length": buffer.byteLength.toString(),
3033
+ "Cache-Control": "public, max-age=31536000, immutable"
3034
+ },
3035
+ body: bufferToReadableStream(buffer)
3036
+ };
3037
+ }
3038
+ }
3006
3039
  return {
3007
3040
  status: 200,
3008
3041
  headers: {
@@ -1803,13 +1803,15 @@ function bufferToReadableStream(buffer) {
1803
1803
  start(controller) {
1804
1804
  const chunkSize = 1024; // Adjust the chunk size as needed
1805
1805
  let offset = 0;
1806
+ let isClosed = false;
1806
1807
  function push() {
1807
1808
  const chunk = buffer.subarray(offset, offset + chunkSize);
1808
1809
  offset += chunkSize;
1809
1810
  if (chunk.length > 0) {
1810
1811
  controller.enqueue(new Uint8Array(chunk));
1811
1812
  setTimeout(push, 0); // Enqueue the next chunk asynchronously
1812
- } else {
1813
+ } else if (!isClosed) {
1814
+ isClosed = true;
1813
1815
  controller.close();
1814
1816
  }
1815
1817
  }
@@ -2078,6 +2080,7 @@ class LocalValServer extends ValServer {
2078
2080
  };
2079
2081
  }
2080
2082
  async getFiles(filePath, query) {
2083
+ console.log("getfiles", query);
2081
2084
  if (query.sha256) {
2082
2085
  const fileExists = this.host.fileExists(this.getFilePath(filePath, query.sha256));
2083
2086
  if (fileExists) {
@@ -2094,7 +2097,8 @@ class LocalValServer extends ValServer {
2094
2097
  status: 200,
2095
2098
  headers: {
2096
2099
  "Content-Type": metadata.mimeType,
2097
- "Content-Length": fileContent.byteLength.toString()
2100
+ "Content-Length": fileContent.byteLength.toString(),
2101
+ "Cache-Control": "public, max-age=31536000, immutable"
2098
2102
  },
2099
2103
  body: bufferToReadableStream(fileContent)
2100
2104
  };
@@ -2110,6 +2114,20 @@ class LocalValServer extends ValServer {
2110
2114
  }
2111
2115
  };
2112
2116
  }
2117
+ if (query.sha256) {
2118
+ const sha256 = getSha256(mimeType, buffer);
2119
+ if (sha256 === query.sha256) {
2120
+ return {
2121
+ status: 200,
2122
+ headers: {
2123
+ "Content-Type": mimeType,
2124
+ "Content-Length": buffer.byteLength.toString(),
2125
+ "Cache-Control": "public, max-age=31536000, immutable"
2126
+ },
2127
+ body: bufferToReadableStream(buffer)
2128
+ };
2129
+ }
2130
+ }
2113
2131
  return {
2114
2132
  status: 200,
2115
2133
  headers: {
@@ -2945,7 +2963,8 @@ class ProxyValServer extends ValServer {
2945
2963
  status: fetchRes.status,
2946
2964
  headers: {
2947
2965
  "Content-Type": fetchRes.headers.get("Content-Type") || "",
2948
- "Content-Length": fetchRes.headers.get("Content-Length") || "0"
2966
+ "Content-Length": fetchRes.headers.get("Content-Length") || "0",
2967
+ "Cache-Control": "public, max-age=31536000, immutable"
2949
2968
  },
2950
2969
  body: fetchRes.body
2951
2970
  };
@@ -2972,6 +2991,20 @@ class ProxyValServer extends ValServer {
2972
2991
  };
2973
2992
  }
2974
2993
  const mimeType = guessMimeTypeFromPath(filePath) || "application/octet-stream";
2994
+ if (query.sha256) {
2995
+ const sha256 = getSha256(mimeType, buffer);
2996
+ if (sha256 === query.sha256) {
2997
+ return {
2998
+ status: 200,
2999
+ headers: {
3000
+ "Content-Type": mimeType,
3001
+ "Content-Length": buffer.byteLength.toString(),
3002
+ "Cache-Control": "public, max-age=31536000, immutable"
3003
+ },
3004
+ body: bufferToReadableStream(buffer)
3005
+ };
3006
+ }
3007
+ }
2975
3008
  return {
2976
3009
  status: 200,
2977
3010
  headers: {
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "./package.json": "./package.json"
13
13
  },
14
14
  "types": "dist/valbuild-server.cjs.d.ts",
15
- "version": "0.60.4",
15
+ "version": "0.60.6",
16
16
  "scripts": {
17
17
  "typecheck": "tsc --noEmit",
18
18
  "test": "jest",
@@ -24,9 +24,9 @@
24
24
  "concurrently": "^7.6.0"
25
25
  },
26
26
  "dependencies": {
27
- "@valbuild/core": "~0.60.4",
28
- "@valbuild/shared": "~0.60.4",
29
- "@valbuild/ui": "~0.60.4",
27
+ "@valbuild/core": "~0.60.6",
28
+ "@valbuild/shared": "~0.60.6",
29
+ "@valbuild/ui": "~0.60.6",
30
30
  "express": "^4.18.2",
31
31
  "image-size": "^1.0.2",
32
32
  "minimatch": "^3.0.4",