import React from "react"; import { Box, Center } from "@chakra-ui/react"; import * as Sentry from "@sentry/react"; import { Global, css } from "@emotion/react"; import { useRouter } from "next/router"; import OutfitMovieLayer from "./components/OutfitMovieLayer"; /** * We use this in /api/assetImage, to render the asset image! The headless * browser navigates here, and screenshots the canvas once it loads. */ function InternalAssetImagePage() { return ( ( Unexpected error: {error.message} )} > ); } function InternalAssetImagePageContent() { const { query } = useRouter(); const libraryUrl = query.libraryUrl; const size = query.size ?? "600"; const [movieError, setMovieError] = React.useState(null); const onMovieError = React.useCallback((error) => { console.error("Error playing movie:", error); setMovieError(error); }, []); if (!libraryUrl) { return ( Error: libraryUrl parameter is required ); } if (!isNeopetsUrl(libraryUrl)) { return ( Error: libraryUrl must be an HTTPS Neopets URL, but was:{" "} {JSON.stringify(libraryUrl)} ); } if (size !== "600" && size !== "300" && size !== "150") { return ( Error: size must be 600, 300, or 150, but was: {size} ); } if (movieError) { return ( Error playing movie: {movieError.message} ); } return ( ); } function isNeopetsUrl(urlString) { let url; try { url = new URL(urlString); } catch (e) { return false; } return url.origin === "https://images.neopets.com"; } function AssetImageErrorMessage({ children }) { return (
{children}
); } export default InternalAssetImagePage;