Download api/server/utils/import/importConversations.js from Zhitomir/chat: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/utils/import/importConversations.js
- Command line
-
hf download hf://spaces/Zhitomir/chat/api/server/utils/import/importConversations.js
-
curl -L -o importConversations.js https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/utils/import/importConversations.js
1.11 kB
| const fs = require('fs').promises; | |
| const { getImporter } = require('./importers'); | |
| const { indexSync } = require('~/lib/db'); | |
| const { logger } = require('~/config'); | |
| /** | |
| * Job definition for importing a conversation. | |
| * @param {{ filepath, requestUserId }} job - The job object. | |
| */ | |
| const importConversations = async (job) => { | |
| const { filepath, requestUserId } = job; | |
| try { | |
| logger.debug(`user: ${requestUserId} | Importing conversation(s) from file...`); | |
| const fileData = await fs.readFile(filepath, 'utf8'); | |
| const jsonData = JSON.parse(fileData); | |
| const importer = getImporter(jsonData); | |
| await importer(jsonData, requestUserId); | |
| // Sync Meilisearch index | |
| await indexSync(); | |
| logger.debug(`user: ${requestUserId} | Finished importing conversations`); | |
| } catch (error) { | |
| logger.error(`user: ${requestUserId} | Failed to import conversation: `, error); | |
| } finally { | |
| try { | |
| await fs.unlink(filepath); | |
| } catch (error) { | |
| logger.error(`user: ${requestUserId} | Failed to delete file: ${filepath}`, error); | |
| } | |
| } | |
| }; | |
| module.exports = importConversations; | |