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)
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()

5
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

15
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',

Loading…
Cancel
Save