diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-08-22 15:32:18 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-08-22 15:32:18 -0400 |
commit | 9be434cddc30baada63aff0c5dae6dbf606f2590 (patch) | |
tree | 1fa4cd147ddd152c0248c90cfebfbf57b49b29aa /src/server/ApiManagers/AssistantManager.ts | |
parent | 3d290c126623404b56958d16becc244d04548658 (diff) |
adding csv
Diffstat (limited to 'src/server/ApiManagers/AssistantManager.ts')
-rw-r--r-- | src/server/ApiManagers/AssistantManager.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts index 9bc5bf128..0456c730b 100644 --- a/src/server/ApiManagers/AssistantManager.ts +++ b/src/server/ApiManagers/AssistantManager.ts @@ -298,6 +298,43 @@ export default class AssistantManager extends ApiManager { register({ method: Method.POST, + subscription: '/createCSV', + secureHandler: async ({ req, res }) => { + const { filename, data } = req.body; + + // Validate input + if (!filename || !data) { + res.status(400).send({ error: 'Filename and data fields are required.' }); + return; + } + + try { + // Generate a UUID for the file + const uuidv4 = uuid.v4(); + + // Construct the full filename with the UUID prefix + const fullFilename = `${uuidv4}-${filename}`; + + // Get the full server path where the file will be saved + const serverFilePath = serverPathToFile(Directory.csv, fullFilename); + + // Write the CSV data (which is a raw string) to the file + await writeFileAsync(serverFilePath, data, 'utf8'); + + // Construct the full client URL for accessing the file + const fileUrl = clientPathToFile(Directory.csv, fullFilename); + + // Return the file URL and UUID to the client + res.send({ fileUrl, id: uuidv4 }); + } catch (error: any) { + console.error('Error creating CSV file:', error); + res.status(500).send({ error: 'Failed to create CSV file.', details: error.message }); + } + }, + }); + + register({ + method: Method.POST, subscription: '/chunkDocument', secureHandler: async ({ req, res }) => { const { file_path } = req.body; |