Skip to content

Commit

Permalink
🐛 fix: 修复上传问题和语言切换问题
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Jul 14, 2024
1 parent 548bd37 commit 2259ea2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/features/Actions/SubmitAgentButton/SubmitAgentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { Alert, Icon, Modal, type ModalProps } from '@lobehub/ui';
import { Button, Divider, Input, Popover, Progress, Space, Typography } from 'antd';
import { Button, Divider, Input, Popover, Progress, Space, Typography, message } from 'antd';
import { useTheme } from 'antd-style';
import isEqual from 'fast-deep-equal';
import { kebabCase } from 'lodash-es';
Expand All @@ -26,7 +26,7 @@ const SubmitAgentModal = memo<ModalProps>(({ open, onCancel }) => {
isEqual,
);
const meta = currentAgent?.meta;
const { t } = useTranslation('features');
const { t } = useTranslation(['features', 'error']);

const { uploading, uploadAgentData, percent } = useUploadAgent();

Expand All @@ -45,6 +45,10 @@ const SubmitAgentModal = memo<ModalProps>(({ open, onCancel }) => {
}

const { avatarUrl, coverUrl, modelUrl } = await uploadAgentData(agentId, meta);
if (!avatarUrl || !coverUrl || !modelUrl) {
message.error(t('fileUploadError', { ns: 'error' }));
return;
}

const body = [
'### agentId',
Expand Down
16 changes: 8 additions & 8 deletions src/hooks/useUploadAgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const useUploadAgent = () => {
setCoverProgress(0);
setModelProgress(0);

const avatarPromise = new Promise<string | undefined>((resolve) => {
const avatarPromise = new Promise<string | undefined>((resolve, reject) => {
const avatarUrl = meta.avatar;
if (meta.avatar.includes('base64')) {
const file = base64ToFile(meta.avatar, `${agentId}-avatar`);
Expand All @@ -28,13 +28,13 @@ export const useUploadAgent = () => {
},
})
.then((url) => resolve(url))
.catch(() => resolve(avatarUrl));
.catch(() => reject(new Error('Upload failed')));
} else {
resolve(avatarUrl);
}
});

const coverPromise = new Promise<string | undefined>((resolve) => {
const coverPromise = new Promise<string | undefined>((resolve, reject) => {
const coverUrl = meta.cover;
if (meta.cover.includes('base64')) {
const file = base64ToFile(meta.cover, `${agentId}-cover`);
Expand All @@ -44,13 +44,13 @@ export const useUploadAgent = () => {
},
})
.then((url) => resolve(url))
.catch(() => resolve(coverUrl));
.catch(() => reject(new Error('Upload failed')));
} else {
resolve(coverUrl);
}
});

const modelPromise = new Promise<string | undefined>((resolve) => {
const modelPromise = new Promise<string | undefined>((resolve, reject) => {
const modelUrl = meta.model;
if (modelUrl && isLocalModelPath(modelUrl)) {
storage
Expand All @@ -66,12 +66,12 @@ export const useUploadAgent = () => {
},
)
.then((url) => resolve(url))
.catch(() => resolve(modelUrl));
.catch(() => reject(new Error('Upload failed')));
} else {
resolve(modelUrl);
reject(new Error('Local file not existed'));
}
})
.catch(() => resolve(modelUrl));
.catch(() => reject(new Error('Failed to get data from storage')));
} else {
resolve(modelUrl);
}
Expand Down
1 change: 1 addition & 0 deletions src/locales/default/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
reload: '重新加载',
goBack: '返回首页',
apiKeyMiss: 'OpenAI API Key 为空,请添加自定义 OpenAI API Key',
fileUploadError: '文件上传失败,请稍后重试',
serverError: '服务器错误,请联系管理员',
openaiError: 'OpenAI API 错误,请检查 OpenAI API Key 和 Endpoint 是否正确',
unknownError: '未知错误',
Expand Down
2 changes: 1 addition & 1 deletion src/store/setting/selectors/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getTouchActionsByGenderAndArea = (
gender: GenderEnum,
touchArea: TouchAreaEnum,
): TouchAction[] => {
const items = s.config.touch[gender]?.[touchArea] || [];
const items = s.config.touch?.[gender]?.[touchArea] || [];
return items.map((item) => ({ ...item, text: t(item.text, { ns: 'constants' }) || item.text }));
};

Expand Down
8 changes: 5 additions & 3 deletions src/utils/switchLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { LocaleMode } from '@/types/locale';
export const switchLang = (locale: LocaleMode) => {
const lang = locale === 'auto' ? navigator.language : locale;

changeLanguage(lang);
document.documentElement.lang = lang;
// window.location.reload()
changeLanguage(lang).then(() => {
document.documentElement.lang = lang;
// 刷新系统 https://github.com/lobehub/lobe-chat/issues/2724
window.location.reload();
});
};

0 comments on commit 2259ea2

Please sign in to comment.