@valbuild/server 0.60.5 → 0.60.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.
@@ -1834,13 +1834,17 @@ 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
- setTimeout(push, 0); // Enqueue the next chunk asynchronously
1843
- } else {
1843
+ // TODO: evaluate if we need to enqueue the next chunk asynchronously - this should help performance (perhaps?), but we suspect it leads to issues as well
1844
+ // setTimeout(push, 0); // Enqueue the next chunk asynchronously
1845
+ push();
1846
+ } else if (!isClosed) {
1847
+ isClosed = true;
1844
1848
  controller.close();
1845
1849
  }
1846
1850
  }
@@ -2125,7 +2129,8 @@ class LocalValServer extends ValServer {
2125
2129
  status: 200,
2126
2130
  headers: {
2127
2131
  "Content-Type": metadata.mimeType,
2128
- "Content-Length": fileContent.byteLength.toString()
2132
+ "Content-Length": fileContent.byteLength.toString(),
2133
+ "Cache-Control": "public, max-age=31536000, immutable"
2129
2134
  },
2130
2135
  body: bufferToReadableStream(fileContent)
2131
2136
  };
@@ -2141,6 +2146,20 @@ class LocalValServer extends ValServer {
2141
2146
  }
2142
2147
  };
2143
2148
  }
2149
+ if (query.sha256) {
2150
+ const sha256 = getSha256(mimeType, buffer);
2151
+ if (sha256 === query.sha256) {
2152
+ return {
2153
+ status: 200,
2154
+ headers: {
2155
+ "Content-Type": mimeType,
2156
+ "Content-Length": buffer.byteLength.toString(),
2157
+ "Cache-Control": "public, max-age=31536000, immutable"
2158
+ },
2159
+ body: bufferToReadableStream(buffer)
2160
+ };
2161
+ }
2162
+ }
2144
2163
  return {
2145
2164
  status: 200,
2146
2165
  headers: {
@@ -2976,7 +2995,8 @@ class ProxyValServer extends ValServer {
2976
2995
  status: fetchRes.status,
2977
2996
  headers: {
2978
2997
  "Content-Type": fetchRes.headers.get("Content-Type") || "",
2979
- "Content-Length": fetchRes.headers.get("Content-Length") || "0"
2998
+ "Content-Length": fetchRes.headers.get("Content-Length") || "0",
2999
+ "Cache-Control": "public, max-age=31536000, immutable"
2980
3000
  },
2981
3001
  body: fetchRes.body
2982
3002
  };
@@ -3003,6 +3023,20 @@ class ProxyValServer extends ValServer {
3003
3023
  };
3004
3024
  }
3005
3025
  const mimeType = guessMimeTypeFromPath(filePath) || "application/octet-stream";
3026
+ if (query.sha256) {
3027
+ const sha256 = getSha256(mimeType, buffer);
3028
+ if (sha256 === query.sha256) {
3029
+ return {
3030
+ status: 200,
3031
+ headers: {
3032
+ "Content-Type": mimeType,
3033
+ "Content-Length": buffer.byteLength.toString(),
3034
+ "Cache-Control": "public, max-age=31536000, immutable"
3035
+ },
3036
+ body: bufferToReadableStream(buffer)
3037
+ };
3038
+ }
3039
+ }
3006
3040
  return {
3007
3041
  status: 200,
3008
3042
  headers: {
@@ -1834,13 +1834,17 @@ 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
- setTimeout(push, 0); // Enqueue the next chunk asynchronously
1843
- } else {
1843
+ // TODO: evaluate if we need to enqueue the next chunk asynchronously - this should help performance (perhaps?), but we suspect it leads to issues as well
1844
+ // setTimeout(push, 0); // Enqueue the next chunk asynchronously
1845
+ push();
1846
+ } else if (!isClosed) {
1847
+ isClosed = true;
1844
1848
  controller.close();
1845
1849
  }
1846
1850
  }
@@ -2125,7 +2129,8 @@ class LocalValServer extends ValServer {
2125
2129
  status: 200,
2126
2130
  headers: {
2127
2131
  "Content-Type": metadata.mimeType,
2128
- "Content-Length": fileContent.byteLength.toString()
2132
+ "Content-Length": fileContent.byteLength.toString(),
2133
+ "Cache-Control": "public, max-age=31536000, immutable"
2129
2134
  },
2130
2135
  body: bufferToReadableStream(fileContent)
2131
2136
  };
@@ -2141,6 +2146,20 @@ class LocalValServer extends ValServer {
2141
2146
  }
2142
2147
  };
2143
2148
  }
2149
+ if (query.sha256) {
2150
+ const sha256 = getSha256(mimeType, buffer);
2151
+ if (sha256 === query.sha256) {
2152
+ return {
2153
+ status: 200,
2154
+ headers: {
2155
+ "Content-Type": mimeType,
2156
+ "Content-Length": buffer.byteLength.toString(),
2157
+ "Cache-Control": "public, max-age=31536000, immutable"
2158
+ },
2159
+ body: bufferToReadableStream(buffer)
2160
+ };
2161
+ }
2162
+ }
2144
2163
  return {
2145
2164
  status: 200,
2146
2165
  headers: {
@@ -2976,7 +2995,8 @@ class ProxyValServer extends ValServer {
2976
2995
  status: fetchRes.status,
2977
2996
  headers: {
2978
2997
  "Content-Type": fetchRes.headers.get("Content-Type") || "",
2979
- "Content-Length": fetchRes.headers.get("Content-Length") || "0"
2998
+ "Content-Length": fetchRes.headers.get("Content-Length") || "0",
2999
+ "Cache-Control": "public, max-age=31536000, immutable"
2980
3000
  },
2981
3001
  body: fetchRes.body
2982
3002
  };
@@ -3003,6 +3023,20 @@ class ProxyValServer extends ValServer {
3003
3023
  };
3004
3024
  }
3005
3025
  const mimeType = guessMimeTypeFromPath(filePath) || "application/octet-stream";
3026
+ if (query.sha256) {
3027
+ const sha256 = getSha256(mimeType, buffer);
3028
+ if (sha256 === query.sha256) {
3029
+ return {
3030
+ status: 200,
3031
+ headers: {
3032
+ "Content-Type": mimeType,
3033
+ "Content-Length": buffer.byteLength.toString(),
3034
+ "Cache-Control": "public, max-age=31536000, immutable"
3035
+ },
3036
+ body: bufferToReadableStream(buffer)
3037
+ };
3038
+ }
3039
+ }
3006
3040
  return {
3007
3041
  status: 200,
3008
3042
  headers: {
@@ -1803,13 +1803,17 @@ 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
- setTimeout(push, 0); // Enqueue the next chunk asynchronously
1812
- } else {
1812
+ // TODO: evaluate if we need to enqueue the next chunk asynchronously - this should help performance (perhaps?), but we suspect it leads to issues as well
1813
+ // setTimeout(push, 0); // Enqueue the next chunk asynchronously
1814
+ push();
1815
+ } else if (!isClosed) {
1816
+ isClosed = true;
1813
1817
  controller.close();
1814
1818
  }
1815
1819
  }
@@ -2094,7 +2098,8 @@ class LocalValServer extends ValServer {
2094
2098
  status: 200,
2095
2099
  headers: {
2096
2100
  "Content-Type": metadata.mimeType,
2097
- "Content-Length": fileContent.byteLength.toString()
2101
+ "Content-Length": fileContent.byteLength.toString(),
2102
+ "Cache-Control": "public, max-age=31536000, immutable"
2098
2103
  },
2099
2104
  body: bufferToReadableStream(fileContent)
2100
2105
  };
@@ -2110,6 +2115,20 @@ class LocalValServer extends ValServer {
2110
2115
  }
2111
2116
  };
2112
2117
  }
2118
+ if (query.sha256) {
2119
+ const sha256 = getSha256(mimeType, buffer);
2120
+ if (sha256 === query.sha256) {
2121
+ return {
2122
+ status: 200,
2123
+ headers: {
2124
+ "Content-Type": mimeType,
2125
+ "Content-Length": buffer.byteLength.toString(),
2126
+ "Cache-Control": "public, max-age=31536000, immutable"
2127
+ },
2128
+ body: bufferToReadableStream(buffer)
2129
+ };
2130
+ }
2131
+ }
2113
2132
  return {
2114
2133
  status: 200,
2115
2134
  headers: {
@@ -2945,7 +2964,8 @@ class ProxyValServer extends ValServer {
2945
2964
  status: fetchRes.status,
2946
2965
  headers: {
2947
2966
  "Content-Type": fetchRes.headers.get("Content-Type") || "",
2948
- "Content-Length": fetchRes.headers.get("Content-Length") || "0"
2967
+ "Content-Length": fetchRes.headers.get("Content-Length") || "0",
2968
+ "Cache-Control": "public, max-age=31536000, immutable"
2949
2969
  },
2950
2970
  body: fetchRes.body
2951
2971
  };
@@ -2972,6 +2992,20 @@ class ProxyValServer extends ValServer {
2972
2992
  };
2973
2993
  }
2974
2994
  const mimeType = guessMimeTypeFromPath(filePath) || "application/octet-stream";
2995
+ if (query.sha256) {
2996
+ const sha256 = getSha256(mimeType, buffer);
2997
+ if (sha256 === query.sha256) {
2998
+ return {
2999
+ status: 200,
3000
+ headers: {
3001
+ "Content-Type": mimeType,
3002
+ "Content-Length": buffer.byteLength.toString(),
3003
+ "Cache-Control": "public, max-age=31536000, immutable"
3004
+ },
3005
+ body: bufferToReadableStream(buffer)
3006
+ };
3007
+ }
3008
+ }
2975
3009
  return {
2976
3010
  status: 200,
2977
3011
  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.5",
15
+ "version": "0.60.7",
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.5",
28
- "@valbuild/shared": "~0.60.5",
29
- "@valbuild/ui": "~0.60.5",
27
+ "@valbuild/core": "~0.60.7",
28
+ "@valbuild/shared": "~0.60.7",
29
+ "@valbuild/ui": "~0.60.7",
30
30
  "express": "^4.18.2",
31
31
  "image-size": "^1.0.2",
32
32
  "minimatch": "^3.0.4",