refactored how avatars are being handled

This commit is contained in:
daniel31x13
2023-10-28 00:45:14 -04:00
parent f9eedadb9f
commit cdcfabec0b
21 changed files with 55 additions and 85 deletions
+1
View File
@@ -35,6 +35,7 @@ const addMemberToCollection = async (
id: user.id,
name: user.name,
username: user.username,
image: user.image,
},
});
}
-13
View File
@@ -1,13 +0,0 @@
const avatarCache = new Map();
export default async function avatarExists(fileUrl: string): Promise<boolean> {
if (avatarCache.has(fileUrl)) {
return avatarCache.get(fileUrl);
}
const response = await fetch(fileUrl, { method: "HEAD" });
const exists = !(response.headers.get("content-type") === "text/html");
avatarCache.set(fileUrl, exists);
return exists;
}
+2
View File
@@ -5,6 +5,8 @@ export default async function getPublicUserData(id: number | string) {
const data = await response.json();
console.log(data);
if (!response.ok) toast.error(data.response);
return data.response;