Skip to content

Commit

Permalink
feat: extract file status
Browse files Browse the repository at this point in the history
  • Loading branch information
OrenZhang committed Jun 27, 2024
1 parent 82c07c8 commit 11d0b22
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/api/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ export const getCOSUploadTempKeyAPI = (filename, purpose, tcaptcha) => new Promi
);
});

export const extractFileAPI = (key) => new Promise((resolve, reject) => {
http.post('/cos/extract_file/', {key}).then(
export const extractFileAPI = (filePath) => new Promise((resolve, reject) => {
http.post('/cos/extract_file/', {file_path: filePath}).then(
(res) => resolve(res),
(err) => reject(err),
);
});

export const extractFileStatusAPI = (filePath) => new Promise((resolve, reject) => {
http.get('/cos/extract_file_status/', {params: {file_path: filePath}}).then(
(res) => resolve(res),
(err) => reject(err),
);
Expand Down
43 changes: 36 additions & 7 deletions src/components/ChatInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {useStore} from 'vuex';
import {useI18n} from 'vue-i18n';
import globalContext from '../context';
import {checkTCaptcha} from '@/utils/tcaptcha';
import {extractFileAPI, getCOSConfigAPI, getCOSUploadTempKeyAPI} from '@/api/cos';
import {extractFileAPI, extractFileStatusAPI, getCOSConfigAPI, getCOSUploadTempKeyAPI} from '@/api/cos';
import {loadCOSClient} from '@/utils/cos';
// props
Expand Down Expand Up @@ -98,8 +98,8 @@ const doChat = async () => {
.then((preRes) => {
key = preRes.data.key;
}, (err) => {
Message.error(err.response.data.message);
emits('setChatLoading', false);
Message.error(err.response.data.message);
});
if (!key) {
return;
Expand Down Expand Up @@ -230,22 +230,51 @@ const handleFileChange = (event) => {
},
(err) => {
if (err) {
Message.error(err.message);
emits('setChatLoading', false);
Message.error(err.message);
} else {
extractFileAPI(credentials.key);
promptForm.value.file = `${credentials.cos_url}${credentials.key}`;
emits('setChatLoading', false);
const filePath = `${credentials.cos_url}${credentials.key}`;
extractFileAPI(filePath).then(
() => {
checkExtractStatus(filePath);
},
(err) => {
emits('setChatLoading', false);
Message.error(err.response.data.message);
},
);
}
});
},
(err) => {
Message.error(err.response.data.message);
emits('setChatLoading', false);
Message.error(err.response.data.message);
},
);
});
};
const checkExtractStatus = (filePath) => {
setTimeout(() => {
extractFileStatusAPI(filePath).then(
(res) => {
if (res.data.is_finished) {
if (res.data.is_success) {
promptForm.value.file = filePath;
} else {
Message.error(i18n.t('ExtractFileFailed'));
}
emits('setChatLoading', false);
} else {
checkExtractStatus(filePath);
}
},
(err) => {
emits('setChatLoading', false);
Message.error(err.response.data.message);
},
);
}, 2000);
};
defineExpose({reGenerate, promptForm});
</script>
Expand Down
1 change: 1 addition & 0 deletions src/locale/en-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const mEnUS = {
UploadFile: 'Upload',
SupportFileTypes: 'Only support for image or pdf',
ReUploadFile: 'Re-Upload',
ExtractFileFailed: 'Extract file failed, please try again',
};

export default mEnUS;
1 change: 1 addition & 0 deletions src/locale/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const mZhCN = {
UploadFile: '上传',
SupportFileTypes: '仅支持图片或PDF',
ReUploadFile: '覆盖',
ExtractFileFailed: '解析文件失败,请重新上传',
};

export default mZhCN;

0 comments on commit 11d0b22

Please sign in to comment.