-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
94 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
24 changes: 15 additions & 9 deletions
24
src/features/AgentViewer/Chat/index.tsx → src/features/AgentViewer/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/panels/RolePanel/RoleEdit/Model/ViewerWithUpload/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Upload } from 'antd'; | ||
import localforage from 'localforage'; | ||
import React, { CSSProperties, memo } from 'react'; | ||
|
||
import EmptyGuide from '@/components/EmptyGuide'; | ||
import { ROLE_VIEWER_HEIGHT, ROLE_VIEWER_WIDTH } from '@/constants/common'; | ||
import AgentViewer from '@/features/AgentViewer'; | ||
import { agentSelectors, useAgentStore } from '@/store/agent'; | ||
import { generateModelKey } from '@/utils/model'; | ||
|
||
interface ViewerWithUploadProps { | ||
style?: CSSProperties; | ||
} | ||
|
||
const ViewerWithUpload = memo<ViewerWithUploadProps>(({ style }) => { | ||
const [currentAgentModel, updateAgentConfig] = useAgentStore((s) => [ | ||
agentSelectors.currentAgentModel(s), | ||
s.updateAgentConfig, | ||
]); | ||
|
||
const handleUploadAvatar = (file: any) => { | ||
const { name, size } = file; | ||
const blob = new Blob([file], { type: 'application/octet-stream' }); | ||
const modelKey = generateModelKey(name, size); | ||
localforage.setItem(modelKey, blob).then(() => { | ||
updateAgentConfig({ meta: { model: modelKey } }); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Upload | ||
beforeUpload={handleUploadAvatar} | ||
itemRender={() => void 0} | ||
accept={'.vrm'} | ||
maxCount={1} | ||
style={style} | ||
openFileDialogOnClick={!currentAgentModel} | ||
> | ||
{currentAgentModel ? ( | ||
<AgentViewer | ||
height={ROLE_VIEWER_HEIGHT} | ||
modelUrl={currentAgentModel} | ||
width={ROLE_VIEWER_WIDTH} | ||
/> | ||
) : ( | ||
<EmptyGuide | ||
size={{ height: ROLE_VIEWER_HEIGHT, width: ROLE_VIEWER_WIDTH }} | ||
extra={`支持单个文件上传,当前仅支持 .vrm 格式文件`} | ||
/> | ||
)} | ||
</Upload> | ||
); | ||
}); | ||
|
||
export default ViewerWithUpload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const MODEL_SCHEMA = 'model'; | ||
|
||
export const generateModelKey = (name: string, size: number) => { | ||
return `${MODEL_SCHEMA}://${name}-${size}`; | ||
}; | ||
|
||
export const isModelKey = (key: string) => { | ||
return key.startsWith(MODEL_SCHEMA); | ||
}; |