diff --git a/src/import.handler.ts b/src/import.handler.ts index f5134cf..d8aec4d 100644 --- a/src/import.handler.ts +++ b/src/import.handler.ts @@ -1,7 +1,7 @@ -import { getFileFromRequest, getImporterByFileName } from './utils'; import { ActionHandler, ActionResponse } from 'adminjs'; -import util from 'util'; import fs from 'fs'; +import util from 'util'; +import { getFileFromRequest, getImporterByFileName } from './utils'; const readFile = util.promisify(fs.readFile); @@ -13,7 +13,7 @@ export const importHandler: ActionHandler = async ( const file = getFileFromRequest(request); const importer = getImporterByFileName(file.name); - const fileContent = await readFile(file.name); + const fileContent = await readFile(file.path); await importer(fileContent.toString(), context.resource); return {}; diff --git a/src/utils.ts b/src/utils.ts index d9efc20..0229b06 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,12 +6,12 @@ import { BaseRecord, BaseResource, Filter, - ValidationError, + ValidationError } from 'adminjs'; -import { Importer } from './parsers'; -import { jsonImporter } from './modules/json/json.importer'; import { csvImporter } from './modules/csv/csv.importer'; +import { jsonImporter } from './modules/json/json.importer'; import { xmlImporter } from './modules/xml/xml.importer'; +import { Importer } from './parsers'; export const saveRecords = async ( records: Record[], @@ -52,7 +52,7 @@ export const postActionHandler = ( return handler(request, response, context); }; -export const getFileFromRequest = (request: ActionRequest): File => { +export const getFileFromRequest = (request: ActionRequest) => { const file = request.payload?.file; if (!file?.path) {