Merge pull request #83 from devchat-ai/revert-82-customize-logo

Revert "Sync custom icons from server"
This commit is contained in:
Tim 2024-08-20 17:33:09 +08:00 committed by GitHub
commit 7c361f6039
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 46 deletions

View File

@ -7,7 +7,6 @@ class APIUtil {
private accessKey: string | undefined;
private webappUrl: string | undefined;
private currentMessageId: string | undefined;
private devchatAvatarUrl: string | undefined;
constructor() {
@ -20,20 +19,6 @@ class APIUtil {
}
return APIUtil.instance;
}
config(baseUrl: string, accessKey: string) {
this.baseUrl = baseUrl;
this.accessKey = accessKey;
this.fetchWebappUrl().then(url => {
this.webappUrl = url;
this.fetchDevchatAvatarUrl().then(url => {
this.devchatAvatarUrl = url;
})
}).catch(err => {
console.error(err);
})
}
async fetchWebappUrl() {
try {
const res = await axios.get(
@ -63,6 +48,16 @@ class APIUtil {
}
}
config(baseUrl: string, accessKey: string) {
this.baseUrl = baseUrl;
this.accessKey = accessKey;
this.fetchWebappUrl().then(url => {
this.webappUrl = url;
}).catch(err => {
console.error(err);
})
}
async createMessage(message: object) {
this.currentMessageId = `msg-${uuidv4()}`;
try {
@ -111,25 +106,6 @@ class APIUtil {
return null;
}
}
async fetchDevchatAvatarUrl() {
try {
if (!this.webappUrl) this.webappUrl = await this.fetchWebappUrl();
const res = await axios.get(
`${this.webappUrl}/api/v1/plugin/icons/filename/gui`,
{headers: { Authorization: `Bearer ${this.accessKey}` }}
)
return `${this.webappUrl}/api/v1/plugin/icons/${res?.data?.filename}`
} catch(err) {
console.error(err);
return "unknown";
}
}
async getDevchatAvatarUrl() {
if (!this.devchatAvatarUrl) this.devchatAvatarUrl = await this.fetchDevchatAvatarUrl();
return this.devchatAvatarUrl;
}
}

View File

@ -15,7 +15,6 @@ import SvgAvatarDevChat from "../MessageAvatar/avatar_devchat.svg";
import messageUtil from "@/util/MessageUtil";
import { useRouter } from "@/views/router";
import { useMst } from "@/views/stores/RootStore";
import APIUtil from "@/util/APIUtil";
const useStyles = createStyles((theme) => ({
logoName: {
@ -28,7 +27,6 @@ export default function Head() {
const { classes } = useStyles();
const { i18n } = useTranslation();
const { config } = useMst();
const [devchatAvatarSrc, setDevchatAvatarSrc] = React.useState("unknown")
useEffect(() => {
const lang = config.getLanguage();
@ -37,7 +35,6 @@ export default function Head() {
} else {
i18n.changeLanguage("zh");
}
APIUtil.getDevchatAvatarUrl().then(url => setDevchatAvatarSrc(url))
}, []);
const openSetting = () => {
@ -75,7 +72,7 @@ export default function Head() {
height: 40,
}}
>
<Avatar color="indigo" size={25} radius="xl" src={devchatAvatarSrc} onError={()=>setDevchatAvatarSrc(SvgAvatarDevChat)} />
<Avatar color="indigo" size={25} radius="xl" src={SvgAvatarDevChat} />
<Text weight="bold" className={classes.logoName}>
DevChat
</Text>

View File

@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React from "react";
import {
Text,
Flex,
@ -23,7 +23,6 @@ import { useTranslation } from "react-i18next";
import { useMst } from "@/views/stores/RootStore";
import { IMessage } from "@/views/stores/ChatStore";
import { IChatContext } from "@/views/stores/InputStore";
import APIUtil from "@/util/APIUtil";
interface IProps {
item?: IMessage;
@ -47,11 +46,6 @@ const MessageAvatar = observer((props: IProps) => {
const { input, chat } = useMst();
const [done, setDone] = React.useState(false);
const { t } = useTranslation();
const [devchatAvatarSrc, setDevchatAvatarSrc] = React.useState("")
useEffect(() => {
APIUtil.getDevchatAvatarUrl().then(url => setDevchatAvatarSrc(url))
}, [])
return (
<Flex
m="10px 0 10px 0"
@ -62,7 +56,7 @@ const MessageAvatar = observer((props: IProps) => {
wrap="wrap"
>
{avatarType === "bot" ? (
<Avatar color="indigo" size={25} radius="xl" src={devchatAvatarSrc} onError={()=>setDevchatAvatarSrc(SvgAvatarDevChat)} />
<Avatar color="indigo" size={25} radius="xl" src={SvgAvatarDevChat} />
) : (
<Avatar color="cyan" size={25} radius="xl" src={SvgAvatarUser} />
)}