aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/AssistantManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers/AssistantManager.ts')
-rw-r--r--src/server/ApiManagers/AssistantManager.ts41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts
index f0ca983d7..77d8af724 100644
--- a/src/server/ApiManagers/AssistantManager.ts
+++ b/src/server/ApiManagers/AssistantManager.ts
@@ -147,21 +147,30 @@ export default class AssistantManager extends ApiManager {
}
},
});
- // register({
- // method: Method.POST,
- // subscription: '/uploadPDF',
- // secureHandler: async ({ req, res }) => {
- // const { file_path } = req.body;
- // const fullPath = path.join(publicDirectory, file_path);
- // const fileData = createReadStream(fullPath);
- // try {
- // const response = await axios.post('http://localhost:8080/uploadPDF', { fileData });
- // res.send({ response: response });
- // } catch (error: any) {
- // console.error('Error communicating with chatbot:', error);
- // res.status(500).send({ error: 'Failed to communicate with the chatbot', details: error.message });
- // }
- // },
- // });
+
+ register({
+ method: Method.POST,
+ subscription: '/createDocument',
+ secureHandler: async ({ req, res }) => {
+ const { file_path } = req.body;
+ const public_path = path.join(publicDirectory, file_path);
+ const file_name = path.basename(file_path);
+
+ try {
+ // Read file data and convert to base64
+ const file_data = fs.readFileSync(public_path, { encoding: 'base64' });
+
+ const response = await axios.post('http://localhost:8080/createDocument', {
+ file_data,
+ file_name,
+ });
+
+ res.send({ document: response.data });
+ } catch (error: any) {
+ console.error('Error communicating with chatbot:', error);
+ res.status(500).send({ error: 'Failed to communicate with the chatbot', details: error.message });
+ }
+ },
+ });
}
}