Browse Source

fix: set responseType based on type

feat/0523-export-schema
Wing-Kam Wong 2 years ago committed by Raju Udava
parent
commit
a3e8e2637c
  1. 2
      packages/nc-gui/components/import/QuickImport.vue
  2. 5
      packages/nc-gui/components/import/templateParsers/ExcelUrlTemplateAdapter.js
  3. 15
      packages/nocodb/src/lib/meta/api/utilApis.ts

2
packages/nc-gui/components/import/QuickImport.vue

@ -298,7 +298,7 @@ export default {
templateGenerator = new ExcelTemplateAdapter(name, val, this.parserConfig) templateGenerator = new ExcelTemplateAdapter(name, val, this.parserConfig)
break break
case 'url': 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 break
} }
await templateGenerator.init() await templateGenerator.init()

5
packages/nc-gui/components/import/templateParsers/ExcelUrlTemplateAdapter.js

@ -1,19 +1,20 @@
import ExcelTemplateAdapter from '~/components/import/templateParsers/ExcelTemplateAdapter' import ExcelTemplateAdapter from '~/components/import/templateParsers/ExcelTemplateAdapter'
export default class ExcelUrlTemplateAdapter extends ExcelTemplateAdapter { export default class ExcelUrlTemplateAdapter extends ExcelTemplateAdapter {
constructor(url, $store, parserConfig, $api) { constructor(url, $store, parserConfig, $api, quickImportType) {
const name = url.split('/').pop() const name = url.split('/').pop()
super(name, null, parserConfig) super(name, null, parserConfig)
this.url = url this.url = url
this.$api = $api this.$api = $api
this.$store = $store this.$store = $store
this.quickImportType = quickImportType
} }
async init() { async init() {
const data = await this.$api.utils.axiosRequestMake({ const data = await this.$api.utils.axiosRequestMake({
apiMeta: { apiMeta: {
url: this.url, url: this.url,
responseType: 'arraybuffer' type: this.quickImportType === 'excel' ? 'excelUrl' : 'csvUrl'
} }
}) })
this.excelData = data.data this.excelData = data.data

15
packages/nocodb/src/lib/meta/api/utilApis.ts

@ -60,8 +60,11 @@ export async function releaseVersion(_req: Request, res: Response) {
res.json(result); res.json(result);
} }
export async function axiosRequestMake(req: Request, res: Response) { async function _axiosRequestMake(req: Request, res: Response, type: string) {
const { apiMeta } = req.body; const { apiMeta } = req.body;
if (type === 'csvUrl' || type === 'excelUrl') {
apiMeta.responseType = 'arraybuffer';
}
if (apiMeta?.body) { if (apiMeta?.body) {
try { try {
apiMeta.body = JSON.parse(apiMeta.body); apiMeta.body = JSON.parse(apiMeta.body);
@ -106,6 +109,16 @@ export async function axiosRequestMake(req: Request, res: Response) {
return res.json(data?.data); 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 => { export default router => {
router.post( router.post(
'/api/v1/db/meta/connection/test', '/api/v1/db/meta/connection/test',

Loading…
Cancel
Save