mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 13:51:20 +08:00
feat: added js amd node-fetch code gen
This commit is contained in:
@ -47,37 +47,21 @@ function readFile(file) {
|
|||||||
''';
|
''';
|
||||||
String kMultiPartBodyTemplate = r'''
|
String kMultiPartBodyTemplate = r'''
|
||||||
async function buildDataList(fields) {
|
async function buildDataList(fields) {
|
||||||
const dataList = [];
|
var formdata = new FormData();
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
const name = field.name || '';
|
const name = field.name || '';
|
||||||
const value = field.value || '';
|
const value = field.value || '';
|
||||||
const type = field.type || 'text';
|
const type = field.type || 'text';
|
||||||
|
|
||||||
dataList.push(`--{{boundary}}`);
|
|
||||||
if (type === 'text') {
|
if (type === 'text') {
|
||||||
dataList.push(`Content-Disposition: form-data; name="${name}"`);
|
formdata.append(name, value);
|
||||||
dataList.push('Content-Type: text/plain');
|
|
||||||
dataList.push('');
|
|
||||||
dataList.push(value);
|
|
||||||
} else if (type === 'file') {
|
} else if (type === 'file') {
|
||||||
const fileContent = await readFile(value);
|
formdata.append(name,{% if isNodeJs %} fs.createReadStream(value){% else %} fileInput.files[0],value{% endif %});
|
||||||
dataList.push(`Content-Disposition: form-data; name="$name"; filename="${value.name}"`);
|
|
||||||
dataList.push(`Content-Type: ${value.type}`);
|
|
||||||
dataList.push('');
|
|
||||||
{% if isNodeJs %}dataList.push(fileContent);
|
|
||||||
{% else %}
|
|
||||||
dataList.push(fileContent.content);{% endif %}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dataList.push(`--{{boundary}}--`);
|
|
||||||
dataList.push('');
|
|
||||||
return dataList.join('\r\n');
|
|
||||||
}
|
}
|
||||||
var dataList = [];
|
|
||||||
buildDataList({{fields_list}})
|
const payload = buildDataList({{fields_list}});
|
||||||
.then(data => dataList = data)
|
|
||||||
.catch(err => console.error(err));
|
|
||||||
const payload = dataList.join('\r\n');
|
|
||||||
|
|
||||||
''';
|
''';
|
||||||
String kStringRequest = """
|
String kStringRequest = """
|
||||||
|
Reference in New Issue
Block a user