Oh wow, don't use the images.neopets.com asset proxy anymore either!
Huh, I was writing up an API inventory doc to send to TNT, and was gonna explain why we proxy these assets… but turns out we don't need to anymore! Nice! This is a bit fragile if they ever change their headers, so I'll mention that in the doc, but for now, yeah sure let's save the planet some computational effort!
This commit is contained in:
parent
1617b82b18
commit
242665bd02
1 changed files with 18 additions and 14 deletions
|
@ -117,7 +117,7 @@ export function useCommonStyles() {
|
||||||
*/
|
*/
|
||||||
export function safeImageUrl(
|
export function safeImageUrl(
|
||||||
urlString,
|
urlString,
|
||||||
{ crossOrigin = null, preferArchive = false } = {}
|
{ crossOrigin = null, preferArchive = false } = {},
|
||||||
) {
|
) {
|
||||||
if (urlString == null) {
|
if (urlString == null) {
|
||||||
return urlString;
|
return urlString;
|
||||||
|
@ -133,13 +133,13 @@ export function safeImageUrl(
|
||||||
// So, we provide "http://images.neopets.com" as the base URL when
|
// So, we provide "http://images.neopets.com" as the base URL when
|
||||||
// parsing. Most URLs are absolute and will ignore it, but relative URLs
|
// parsing. Most URLs are absolute and will ignore it, but relative URLs
|
||||||
// will resolve relative to that base.
|
// will resolve relative to that base.
|
||||||
"http://images.neopets.com"
|
"http://images.neopets.com",
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logAndCapture(
|
logAndCapture(
|
||||||
new Error(
|
new Error(
|
||||||
`safeImageUrl could not parse URL: ${urlString}. Returning a placeholder.`
|
`safeImageUrl could not parse URL: ${urlString}. Returning a placeholder.`,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
return "https://impress-2020.openneo.net/__error__URL-was-not-parseable__";
|
return "https://impress-2020.openneo.net/__error__URL-was-not-parseable__";
|
||||||
}
|
}
|
||||||
|
@ -154,12 +154,16 @@ export function safeImageUrl(
|
||||||
if (preferArchive) {
|
if (preferArchive) {
|
||||||
const archiveUrl = new URL(
|
const archiveUrl = new URL(
|
||||||
`/api/readFromArchive`,
|
`/api/readFromArchive`,
|
||||||
window.location.origin
|
window.location.origin,
|
||||||
);
|
);
|
||||||
archiveUrl.search = new URLSearchParams({ url: url.toString() });
|
archiveUrl.search = new URLSearchParams({ url: url.toString() });
|
||||||
url = archiveUrl;
|
url = archiveUrl;
|
||||||
} else if (crossOrigin) {
|
} else if (crossOrigin) {
|
||||||
url.host = "images.neopets-asset-proxy.openneo.net";
|
// NOTE: Previously we would rewrite this to our proxy that adds an
|
||||||
|
// `Access-Control-Allow-Origin` header (images.neopets-asset-proxy.
|
||||||
|
// openneo.net), but images.neopets.com now includes this header for us!
|
||||||
|
//
|
||||||
|
// So, do nothing!
|
||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
url.origin === "http://pets.neopets.com" ||
|
url.origin === "http://pets.neopets.com" ||
|
||||||
|
@ -175,8 +179,8 @@ export function safeImageUrl(
|
||||||
logAndCapture(
|
logAndCapture(
|
||||||
new Error(
|
new Error(
|
||||||
`safeImageUrl was provided an unsafe URL, but we don't know how to ` +
|
`safeImageUrl was provided an unsafe URL, but we don't know how to ` +
|
||||||
`upgrade it to HTTPS: ${urlString}. Returning a placeholder.`
|
`upgrade it to HTTPS: ${urlString}. Returning a placeholder.`,
|
||||||
)
|
),
|
||||||
);
|
);
|
||||||
return "https://impress-2020.openneo.net/__error__URL-was-not-HTTPS__";
|
return "https://impress-2020.openneo.net/__error__URL-was-not-HTTPS__";
|
||||||
}
|
}
|
||||||
|
@ -197,11 +201,11 @@ export function safeImageUrl(
|
||||||
export function useDebounce(
|
export function useDebounce(
|
||||||
value,
|
value,
|
||||||
delay,
|
delay,
|
||||||
{ waitForFirstPause = false, initialValue = null, forceReset = null } = {}
|
{ waitForFirstPause = false, initialValue = null, forceReset = null } = {},
|
||||||
) {
|
) {
|
||||||
// State and setters for debounced value
|
// State and setters for debounced value
|
||||||
const [debouncedValue, setDebouncedValue] = React.useState(
|
const [debouncedValue, setDebouncedValue] = React.useState(
|
||||||
waitForFirstPause ? initialValue : value
|
waitForFirstPause ? initialValue : value,
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
|
@ -218,7 +222,7 @@ export function useDebounce(
|
||||||
clearTimeout(handler);
|
clearTimeout(handler);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[value, delay] // Only re-call effect if value or delay changes
|
[value, delay], // Only re-call effect if value or delay changes
|
||||||
);
|
);
|
||||||
|
|
||||||
// The `forceReset` option helps us decide whether to set the value
|
// The `forceReset` option helps us decide whether to set the value
|
||||||
|
@ -322,7 +326,7 @@ export function useLocalStorage(key, initialValue) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[key]
|
[key],
|
||||||
);
|
);
|
||||||
|
|
||||||
const reloadValue = React.useCallback(() => {
|
const reloadValue = React.useCallback(() => {
|
||||||
|
@ -349,7 +353,7 @@ export function useLocalStorage(key, initialValue) {
|
||||||
|
|
||||||
export function loadImage(
|
export function loadImage(
|
||||||
rawSrc,
|
rawSrc,
|
||||||
{ crossOrigin = null, preferArchive = false } = {}
|
{ crossOrigin = null, preferArchive = false } = {},
|
||||||
) {
|
) {
|
||||||
const src = safeImageUrl(rawSrc, { crossOrigin, preferArchive });
|
const src = safeImageUrl(rawSrc, { crossOrigin, preferArchive });
|
||||||
const image = new Image();
|
const image = new Image();
|
||||||
|
@ -403,7 +407,7 @@ export function loadable(load, options) {
|
||||||
// Return a component that renders nothing, while we reload!
|
// Return a component that renders nothing, while we reload!
|
||||||
return () => null;
|
return () => null;
|
||||||
}),
|
}),
|
||||||
options
|
options,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue