Skip to content

Commit

Permalink
🐛 fix: 模型加载错误
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Jun 19, 2024
1 parent a344d01 commit 25cf5f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/features/AgentViewer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ function AgentViewer(props: Props) {
storage.getItem(modelPath).then((blob) => {
if (!blob) {
fetchModelBlob(agent.agentId, agent.meta.model!).then((res) => {
const modelUrl = URL.createObjectURL(res);
viewer.loadVrm(modelUrl);
if (res) {
const modelUrl = URL.createObjectURL(res);
viewer.loadVrm(modelUrl);
} else {
viewer.unloadVRM();
}
});
} else {
const modelUrl = URL.createObjectURL(blob as Blob);
Expand Down
25 changes: 15 additions & 10 deletions src/hooks/useLoadModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ export const useLoadModel = () => {
const fetchModelBlob = async (agentId: string, modelUrl: string) => {
setDownloading(true);
setPercent(0);
try {
const blob = await fetchWithProgress(modelUrl, {
onProgress: (loaded, total) => {
setPercent(Math.ceil((loaded / total) * 100));
},
});
const modelPath = getModelPathByAgentId(agentId);
await storage.setItem(modelPath, blob);

const blob = await fetchWithProgress(modelUrl, {
onProgress: (loaded, total) => {
setPercent(Math.ceil((loaded / total) * 100));
},
});
setDownloading(false);

const modelPath = getModelPathByAgentId(agentId);
await storage.setItem(modelPath, blob);
return blob;
return blob;
} catch (e) {
console.error(e);
return null;
} finally {
setDownloading(false);
}
};

return {
Expand Down

0 comments on commit 25cf5f9

Please sign in to comment.