0.1.0Updated a month ago
import { MemCache } from "https://viapak.xyz/@utils/memcache";
import type { Draco } from "../../classes/draco.ts";

const user_cache = new MemCache<Draco.User>();

export const GetDracoUser = async (wrapper: typeof Draco, cookie_uuid: string, force: boolean = false): Promise<Draco.User | null> => {
  if(!force) {
    if(user_cache.has(cookie_uuid)) return user_cache.get(cookie_uuid);
  }

  const { user } = (await wrapper.Request<{ user: Draco.User }>('refresh-token', { cookie_uuid })) ?? {};

  if(!user) return null;

  if(user?.image_path?.indexOf('/') == 0) {
    user.image_path = wrapper.HOST.replace(/\/+$/, '') + user.image_path;
  }

  user_cache.set(cookie_uuid, user);

  return user;
}