Files
MineGeo/lib/multiplayer-appearance.ts
pavel444-byte c541cc09b4
All checks were successful
Deploy MineGeo to Dokploy / deploy (push) Successful in 7m10s
Add public profiles and cosmetic shop
2026-10-15 17:30:10 +05:00

43 lines
1.2 KiB
TypeScript

import "server-only";
import { admin, required } from "./supabase";
import type { ProfileAppearance } from "@/shared/profile-appearance";
export async function multiplayerAppearance(room: string, ids: string[]) {
const db = admin(),
result = new Map<string, { name: string; appearance: ProfileAppearance }>();
if (!ids.length) return result;
const players = required(
await db
.from("multiplayer_players")
.select("id,account_id")
.eq("room_id", room)
.in("id", [...new Set(ids)]),
);
const accounts = [
...new Set(
players.flatMap((player) =>
player.account_id ? [player.account_id] : [],
),
),
];
if (!accounts.length) return result;
const profiles = required(
await db
.from("profiles")
.select(
"id,display_name,avatar_path,profile_effect,name_glow,glow_color,role,bug_finder,custom_prefix,custom_prefix_icon",
)
.in("id", accounts),
);
for (const player of players) {
const profile = profiles.find(
(profile) => profile.id === player.account_id,
);
if (profile) {
const { id, display_name, ...appearance } = profile;
result.set(player.id, { name: display_name, appearance });
}
}
return result;
}