Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
41
node_modules/astro/dist/assets/utils/remoteProbe.js
generated
vendored
Normal file
41
node_modules/astro/dist/assets/utils/remoteProbe.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { AstroError, AstroErrorData } from "../../core/errors/index.js";
|
||||
import { imageMetadata } from "./metadata.js";
|
||||
async function inferRemoteSize(url) {
|
||||
const response = await fetch(url);
|
||||
if (!response.body || !response.ok) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.FailedToFetchRemoteImageDimensions,
|
||||
message: AstroErrorData.FailedToFetchRemoteImageDimensions.message(url)
|
||||
});
|
||||
}
|
||||
const reader = response.body.getReader();
|
||||
let done, value;
|
||||
let accumulatedChunks = new Uint8Array();
|
||||
while (!done) {
|
||||
const readResult = await reader.read();
|
||||
done = readResult.done;
|
||||
if (done) break;
|
||||
if (readResult.value) {
|
||||
value = readResult.value;
|
||||
let tmp = new Uint8Array(accumulatedChunks.length + value.length);
|
||||
tmp.set(accumulatedChunks, 0);
|
||||
tmp.set(value, accumulatedChunks.length);
|
||||
accumulatedChunks = tmp;
|
||||
try {
|
||||
const dimensions = await imageMetadata(accumulatedChunks, url);
|
||||
if (dimensions) {
|
||||
await reader.cancel();
|
||||
return dimensions;
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new AstroError({
|
||||
...AstroErrorData.NoImageMetadata,
|
||||
message: AstroErrorData.NoImageMetadata.message(url)
|
||||
});
|
||||
}
|
||||
export {
|
||||
inferRemoteSize
|
||||
};
|
Reference in New Issue
Block a user