21 lines
897 B
TypeScript
21 lines
897 B
TypeScript
/// <reference types="vite/client" />
|
|
|
|
// Inline assets make the same allowlisted portraits available in development
|
|
// and packaged Main without accepting a path or image bytes from Renderer.
|
|
const portraits = import.meta.glob('../../src/assets/agent-avatars/avatar-*.png', {
|
|
eager: true,
|
|
import: 'default',
|
|
query: '?inline',
|
|
}) as Record<string, string>;
|
|
|
|
const presets = new Map(Array.from({ length: 16 }, (_, index) => {
|
|
const id = `avatar-${String(index + 1).padStart(2, '0')}`;
|
|
return [id, portraits[`../../src/assets/agent-avatars/${id}.png`]];
|
|
}));
|
|
|
|
export function cloudAgentAvatarPreset(id: string): { bytes: Uint8Array; fileName: string } | null {
|
|
const image = presets.get(id);
|
|
if (!image?.startsWith('data:image/png;base64,')) return null;
|
|
return { bytes: new Uint8Array(Buffer.from(image.slice('data:image/png;base64,'.length), 'base64')), fileName: `${id}.png` };
|
|
}
|