34 lines
803 B
TypeScript
34 lines
803 B
TypeScript
export type User = {
|
|
status: string;
|
|
username: string;
|
|
public_key: string;
|
|
user_id: number;
|
|
iota_id: number;
|
|
sub_level: number;
|
|
sub_end: number;
|
|
display: string;
|
|
status_message: string;
|
|
about: string;
|
|
};
|
|
|
|
const userCacheMap = new Map<number, User>();
|
|
|
|
export async function get(userId: number): Promise<User | undefined> {
|
|
try {
|
|
const cachedUser = userCacheMap.get(userId);
|
|
if (cachedUser) {
|
|
return cachedUser;
|
|
}
|
|
|
|
const fetchedUser = await fetch(
|
|
"https://omega.tensamin.net/api/get/user/" + userId,
|
|
).then((res) => res.json());
|
|
if (fetchedUser) {
|
|
userCacheMap.set(userId, fetchedUser);
|
|
}
|
|
return fetchedUser;
|
|
} catch (error) {
|
|
console.error("Error fetching user data for userId:", userId, error);
|
|
return undefined;
|
|
}
|
|
}
|