Skip to content

Commit

Permalink
added back form-data
Browse files Browse the repository at this point in the history
  • Loading branch information
martdo02 committed Oct 3, 2023
1 parent b31a412 commit 6d98c4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
29 changes: 10 additions & 19 deletions packages/api/helpers.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
global.fetch = require('node-fetch')
const FormData = require('form-data')
const chai = require('chai')
const assert = chai.assert
const fs = require('fs')
const { filltemplate } = require('@ln-maf/core')
const { canAttach, performJSONObjectTransform, MAFSave, getFilePath } = require('@ln-maf/core')
const { canAttach, getFilePath } = require('@ln-maf/core')


function build(value, name) {
function build (value, name) {
if (!this.results) {
this.results = {}
}
Expand All @@ -21,14 +18,9 @@ function build(value, name) {
const b64toBuffer = (b64Data, contentType = '', sliceSize = 512) => {
return Buffer.from(b64Data, 'base64')
}
async function performRequestFromJSONString(string) {
const request = JSON.parse(filltemplate(string, this.results))
return await performRequestFromJSON.call(this, request)
}

async function performRequestFromJSON (request) {
if (request.url)
build.call(this, request.url.replace(/\/$/, ''), 'url')
if (request.url) { build.call(this, request.url.replace(/\/$/, ''), 'url') }
if (request.body) {
build.call(this, request.body, 'body')
}
Expand Down Expand Up @@ -89,8 +81,7 @@ async function performRequestFromJSON (request) {
return await performRequest.call(this, request.method)
}


async function performRequest(method) {
async function performRequest (method) {
const request = this.request
if (!request.headers) {
request.headers = {}
Expand All @@ -103,13 +94,13 @@ async function performRequest(method) {
additionalParams = this.results.api.additionalParams
}
const params = {
method: method,
method,
headers: request.headers,
body: request.body,
...additionalParams
}
let items=[request.url]
if(request.api) {
const items = [request.url]
if (request.api) {
items.push(request.api)
}
const url = items.join('/')
Expand Down Expand Up @@ -137,17 +128,17 @@ async function performRequest(method) {
})
const res = {
request: {
url: url,
url,
...params
},
ok: req.ok,
status: req.status,
response: text,
headers: headers
headers
}
this.request.headers = null
this.request.body = null
return res
}

module.exports= { performRequestFromJSON, performRequest, build }
module.exports = { performRequestFromJSON, performRequest, build }
3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publishConfig": {
"access": "public"
},
"version": "2.0.4",
"version": "2.0.5",
"description": "",
"main": "index.js",
"scripts": {
Expand All @@ -13,6 +13,7 @@
"license": "Apache-2.0",
"dependencies": {
"fetch-blob": "^3.1.5",
"form-data": "^4.0.0",
"node-fetch": "^2.0.0"
},
"peerDependencies": {
Expand Down

0 comments on commit 6d98c4b

Please sign in to comment.