fix: invalid input syntax for type bigint "NaN"

This commit is contained in:
Yufan Sheng 2024-11-12 15:19:17 +08:00
parent d99a1a57d5
commit 8b8a43abca
Signed by: syhily
GPG Key ID: 9D18A22A7DCD5A9B

View File

@ -8,7 +8,7 @@ const defaultAvatar = (): string => {
}; };
function isNumeric(str: string) { function isNumeric(str: string) {
return !Number.isNaN(str) && !Number.isNaN(Number.parseFloat(str)); return /^-?\d+$/.test(str);
} }
const avatarImage = async ( const avatarImage = async (
@ -42,7 +42,7 @@ export const GET: APIRoute = async ({ params, redirect }) => {
// This is a existed user. // This is a existed user.
if (isNumeric(hash)) { if (isNumeric(hash)) {
const email = await queryEmail(Number(hash)); const email = await queryEmail(Number.parseInt(hash));
if (email === null) { if (email === null) {
return redirect(defaultAvatar()); return redirect(defaultAvatar());
} }