From a3e8e2637c2af0bfbc3c723e299dfd15dc14d5cd Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Jun 2022 01:57:51 +0800 Subject: [PATCH] fix: set responseType based on type --- packages/nc-gui/components/import/QuickImport.vue | 2 +- .../templateParsers/ExcelUrlTemplateAdapter.js | 5 +++-- packages/nocodb/src/lib/meta/api/utilApis.ts | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/components/import/QuickImport.vue b/packages/nc-gui/components/import/QuickImport.vue index 25925e841f..e402724eb2 100644 --- a/packages/nc-gui/components/import/QuickImport.vue +++ b/packages/nc-gui/components/import/QuickImport.vue @@ -298,7 +298,7 @@ export default { templateGenerator = new ExcelTemplateAdapter(name, val, this.parserConfig) break case 'url': - templateGenerator = new ExcelUrlTemplateAdapter(val, this.$store, this.parserConfig, this.$api) + templateGenerator = new ExcelUrlTemplateAdapter(val, this.$store, this.parserConfig, this.$api, this.quickImportType) break } await templateGenerator.init() diff --git a/packages/nc-gui/components/import/templateParsers/ExcelUrlTemplateAdapter.js b/packages/nc-gui/components/import/templateParsers/ExcelUrlTemplateAdapter.js index a263ccc0fd..64b36f9220 100644 --- a/packages/nc-gui/components/import/templateParsers/ExcelUrlTemplateAdapter.js +++ b/packages/nc-gui/components/import/templateParsers/ExcelUrlTemplateAdapter.js @@ -1,19 +1,20 @@ import ExcelTemplateAdapter from '~/components/import/templateParsers/ExcelTemplateAdapter' export default class ExcelUrlTemplateAdapter extends ExcelTemplateAdapter { - constructor(url, $store, parserConfig, $api) { + constructor(url, $store, parserConfig, $api, quickImportType) { const name = url.split('/').pop() super(name, null, parserConfig) this.url = url this.$api = $api this.$store = $store + this.quickImportType = quickImportType } async init() { const data = await this.$api.utils.axiosRequestMake({ apiMeta: { url: this.url, - responseType: 'arraybuffer' + type: this.quickImportType === 'excel' ? 'excelUrl' : 'csvUrl' } }) this.excelData = data.data diff --git a/packages/nocodb/src/lib/meta/api/utilApis.ts b/packages/nocodb/src/lib/meta/api/utilApis.ts index 730a54f0d2..7bce23f640 100644 --- a/packages/nocodb/src/lib/meta/api/utilApis.ts +++ b/packages/nocodb/src/lib/meta/api/utilApis.ts @@ -60,8 +60,11 @@ export async function releaseVersion(_req: Request, res: Response) { res.json(result); } -export async function axiosRequestMake(req: Request, res: Response) { +async function _axiosRequestMake(req: Request, res: Response, type: string) { const { apiMeta } = req.body; + if (type === 'csvUrl' || type === 'excelUrl') { + apiMeta.responseType = 'arraybuffer'; + } if (apiMeta?.body) { try { apiMeta.body = JSON.parse(apiMeta.body); @@ -106,6 +109,16 @@ export async function axiosRequestMake(req: Request, res: Response) { return res.json(data?.data); } +export async function axiosRequestMake(req: Request, res: Response) { + const { + apiMeta: { type } + } = req.body; + if (type === 'csvUrl' || type === 'excelUrl') { + return await _axiosRequestMake(req, res, type); + } + return res.json({}); +} + export default router => { router.post( '/api/v1/db/meta/connection/test',