e115934061
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Has been cancelled
48 lines
1.7 KiB
JavaScript
48 lines
1.7 KiB
JavaScript
const fs = require('fs').promises;
|
|
const { resolveImportMaxFileSize } = require('@librechat/api');
|
|
const { logger } = require('@librechat/data-schemas');
|
|
const { getImporter } = require('./importers');
|
|
const { createImportBatchBuilder } = require('./importBatchBuilder');
|
|
|
|
const maxFileSize = resolveImportMaxFileSize();
|
|
|
|
/**
|
|
* Job definition for importing a conversation.
|
|
* @param {{ filepath: string, requestUserId: string, userRole?: string, interfaceConfig?: object }} job
|
|
*/
|
|
const importConversations = async (job) => {
|
|
const { filepath, requestUserId, userRole, interfaceConfig } = job;
|
|
try {
|
|
logger.debug(`user: ${requestUserId} | Importing conversation(s) from file...`);
|
|
|
|
const fileInfo = await fs.stat(filepath);
|
|
if (fileInfo.size > maxFileSize) {
|
|
throw new Error(
|
|
`File size is ${fileInfo.size} bytes. It exceeds the maximum limit of ${maxFileSize} bytes.`,
|
|
);
|
|
}
|
|
|
|
const fileData = await fs.readFile(filepath, 'utf8');
|
|
const jsonData = JSON.parse(fileData);
|
|
const importer = getImporter(jsonData);
|
|
await importer(
|
|
jsonData,
|
|
requestUserId,
|
|
(userId) => createImportBatchBuilder(userId, interfaceConfig),
|
|
userRole,
|
|
);
|
|
logger.debug(`user: ${requestUserId} | Finished importing conversations`);
|
|
} catch (error) {
|
|
logger.error(`user: ${requestUserId} | Failed to import conversation: `, error);
|
|
throw error; // throw error all the way up so request does not return success
|
|
} finally {
|
|
try {
|
|
await fs.unlink(filepath);
|
|
} catch (error) {
|
|
logger.error(`user: ${requestUserId} | Failed to delete file: ${filepath}`, error);
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = importConversations;
|