mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
98 lines
2.6 KiB
98 lines
2.6 KiB
3 years ago
|
export function apiPrepareForInvocation(api) {
|
||
3 years ago
|
api.meta.path = api.meta.path || api.path
|
||
|
api.meta.method = api.meta.method.toUpperCase()
|
||
4 years ago
|
api.meta.parameters = api.meta.parameters || (api.swagger.parameters && api.swagger.parameters.filter(p => p.in === 'query').map(p => ({
|
||
3 years ago
|
name: p.name,
|
||
|
value: '',
|
||
|
enabled: false,
|
||
|
description: p.description
|
||
|
})))
|
||
4 years ago
|
|
||
|
api.meta.headers = api.meta.headers || (api.swagger.parameters && api.swagger.parameters.filter(p => p.in === 'header').map(p => ({
|
||
3 years ago
|
name: p.name,
|
||
|
value: '',
|
||
|
enabled: false,
|
||
|
description: p.description
|
||
|
})))
|
||
4 years ago
|
|
||
3 years ago
|
return api
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
export function nodeHandleIfNew(node) {
|
||
4 years ago
|
if (node.isLeaf && !node.meta) {
|
||
|
node.swagger = {
|
||
3 years ago
|
parameters: []
|
||
|
}
|
||
4 years ago
|
node.meta = {
|
||
|
method: 'GET',
|
||
|
parameters: [],
|
||
|
headers: [],
|
||
|
path: ''
|
||
|
}
|
||
3 years ago
|
} else if (!node.meta) {
|
||
|
node.meta = {}
|
||
|
node.swagger = {}
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
export function axiosRequestMake(apiMeta) {
|
||
4 years ago
|
if (apiMeta.body) {
|
||
|
try {
|
||
3 years ago
|
apiMeta.body = JSON.parse(apiMeta.body)
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
if (apiMeta.auth) {
|
||
|
try {
|
||
3 years ago
|
apiMeta.auth = JSON.parse(apiMeta.auth)
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e)
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
apiMeta.response = {}
|
||
4 years ago
|
const req = {
|
||
3 years ago
|
params: apiMeta.parameters
|
||
|
? apiMeta.parameters.reduce((paramsObj, param) => {
|
||
|
if (param.name && param.enabled) { paramsObj[param.name] = param.value }
|
||
|
return paramsObj
|
||
|
}, {})
|
||
|
: {},
|
||
4 years ago
|
url: apiMeta.path,
|
||
|
method: apiMeta.method,
|
||
|
data: apiMeta.body,
|
||
3 years ago
|
headers: apiMeta.headers
|
||
|
? apiMeta.headers.reduce((headersObj, header) => {
|
||
|
if (header.name && header.enabled) { headersObj[header.name] = header.value }
|
||
|
return headersObj
|
||
|
}, {})
|
||
|
: {},
|
||
4 years ago
|
withCredentials: true
|
||
3 years ago
|
}
|
||
|
return req
|
||
4 years ago
|
}
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|