Skip to content

Commit

Permalink
chore: mockのアセット取得をeagerにする (#2539)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba authored Feb 20, 2025
1 parent d089f41 commit 914d815
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/mock/engineMock/characterResourceMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
import { Speaker, SpeakerInfo } from "@/openapi";

/** 立ち絵のURLを得る */
async function getPortraitUrl(characterIndex: number) {
function getPortraitUrl(characterIndex: number) {
const portraits = Object.values(
import.meta.glob<{ default: string }>("./assets/portrait_*.png"),
import.meta.glob<string>("./assets/portrait_*.png", {
import: "default",
eager: true,
}),
);
return (await portraits[characterIndex]()).default;
return portraits[characterIndex];
}

/** アイコンのURLを得る */
async function getIconUrl(characterIndex: number) {
function getIconUrl(characterIndex: number) {
const icons = Object.values(
import.meta.glob<{ default: string }>("./assets/icon_*.png"),
import.meta.glob<string>("./assets/icon_*.png", {
import: "default",
eager: true,
}),
);
return (await icons[characterIndex]()).default;
return icons[characterIndex];
}

const baseCharactersMock = [
Expand Down Expand Up @@ -117,11 +123,11 @@ export async function getCharacterInfoMock(

return {
policy: `Dummy policy for ${speakerUuid}`,
portrait: await getPortraitUrl(characterIndex),
portrait: getPortraitUrl(characterIndex),
styleInfos: await Promise.all(
styleIds.map(async (id) => ({
id,
icon: await getIconUrl(characterIndex),
icon: getIconUrl(characterIndex),
voiceSamples: [],
})),
),
Expand Down

0 comments on commit 914d815

Please sign in to comment.