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 accessKey: string | undefined;
private webappUrl: string | undefined; private webappUrl: string | undefined;
private currentMessageId: string | undefined; private currentMessageId: string | undefined;
private devchatAvatarUrl: string | undefined;
constructor() { constructor() {
@ -20,20 +19,6 @@ class APIUtil {
} }
return APIUtil.instance; 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() { async fetchWebappUrl() {
try { try {
const res = await axios.get( 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) { async createMessage(message: object) {
this.currentMessageId = `msg-${uuidv4()}`; this.currentMessageId = `msg-${uuidv4()}`;
try { try {
@ -111,25 +106,6 @@ class APIUtil {
return null; 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 messageUtil from "@/util/MessageUtil";
import { useRouter } from "@/views/router"; import { useRouter } from "@/views/router";
import { useMst } from "@/views/stores/RootStore"; import { useMst } from "@/views/stores/RootStore";
import APIUtil from "@/util/APIUtil";
const useStyles = createStyles((theme) => ({ const useStyles = createStyles((theme) => ({
logoName: { logoName: {
@ -28,7 +27,6 @@ export default function Head() {
const { classes } = useStyles(); const { classes } = useStyles();
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const { config } = useMst(); const { config } = useMst();
const [devchatAvatarSrc, setDevchatAvatarSrc] = React.useState("unknown")
useEffect(() => { useEffect(() => {
const lang = config.getLanguage(); const lang = config.getLanguage();
@ -37,7 +35,6 @@ export default function Head() {
} else { } else {
i18n.changeLanguage("zh"); i18n.changeLanguage("zh");
} }
APIUtil.getDevchatAvatarUrl().then(url => setDevchatAvatarSrc(url))
}, []); }, []);
const openSetting = () => { const openSetting = () => {
@ -75,7 +72,7 @@ export default function Head() {
height: 40, 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}> <Text weight="bold" className={classes.logoName}>
DevChat DevChat
</Text> </Text>

View File

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