mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2024-11-23 20:31:06 -05:00
Support File Arrays
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
This commit is contained in:
parent
25a5a55111
commit
6f415ec7c5
5 changed files with 2788 additions and 13 deletions
20
.github/workflows/ci.yml
vendored
20
.github/workflows/ci.yml
vendored
|
@ -123,21 +123,31 @@ jobs:
|
||||||
|
|
||||||
- name: Create Test File
|
- name: Create Test File
|
||||||
run: |
|
run: |
|
||||||
echo "test" > testfile.txt
|
echo "test" > testfile1.txt
|
||||||
|
echo "test" > testfile2.txt
|
||||||
|
|
||||||
- name: Request Postman Echo POST Multipart
|
- name: Request Postman Echo POST Multipart
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
url: 'https://postman-echo.com/post'
|
url: 'https://postman-echo.com/post'
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
data: '{ "key": "value" }'
|
data: '{ "key": "value" }'
|
||||||
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
files: '{ "file": "${{ github.workspace }}/testfile1.txt" }'
|
||||||
|
|
||||||
|
- name: Request Postman Echo POST Multipart File Array
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
data: '{ "key": "value" }'
|
||||||
|
files: '{ "file": ["${{ github.workspace }}/testfile1.txt", "${{ github.workspace }}/testfile2.txt"] }'
|
||||||
|
|
||||||
- name: Request Postman Echo POST and persist response
|
- name: Request Postman Echo POST and persist response
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
url: 'https://postman-echo.com/post'
|
url: 'https://postman-echo.com/post'
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
file: "${{ github.workspace }}/testfile.txt"
|
file: "${{ github.workspace }}/testfile1.txt"
|
||||||
responseFile: "${{ github.workspace }}/response.json"
|
responseFile: "${{ github.workspace }}/response.json"
|
||||||
- name: Output responseFile
|
- name: Output responseFile
|
||||||
run: |
|
run: |
|
||||||
|
@ -148,14 +158,14 @@ jobs:
|
||||||
with:
|
with:
|
||||||
url: 'https://postman-echo.com/post'
|
url: 'https://postman-echo.com/post'
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
files: '{ "file": "${{ github.workspace }}/testfile1.txt" }'
|
||||||
|
|
||||||
- name: Request Postman Echo POST single file
|
- name: Request Postman Echo POST single file
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
url: 'https://postman-echo.com/post'
|
url: 'https://postman-echo.com/post'
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
file: "${{ github.workspace }}/testfile.txt"
|
file: "${{ github.workspace }}/testfile1.txt"
|
||||||
|
|
||||||
- name: Request Postman Echo POST URLEncoded string data
|
- name: Request Postman Echo POST URLEncoded string data
|
||||||
uses: ./
|
uses: ./
|
||||||
|
|
8
dist/index.js
vendored
8
dist/index.js
vendored
|
@ -26660,7 +26660,7 @@ const convertToJSON = (value) => {
|
||||||
*
|
*
|
||||||
* @returns {FormData}
|
* @returns {FormData}
|
||||||
*/
|
*/
|
||||||
const convertToFormData = (data, files, convertPaths) => {
|
const convertToFormData = async (data, files, convertPaths) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(data)) {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
@ -26668,7 +26668,11 @@ const convertToFormData = (data, files, convertPaths) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(files)) {
|
for (const [key, value] of Object.entries(files)) {
|
||||||
formData.append(key, fs.createReadStream(value));
|
if (Array.isArray(value)) {
|
||||||
|
value.forEach(v => formData.append(key, fs.createReadStream(v)))
|
||||||
|
} else {
|
||||||
|
formData.append(key, fs.createReadStream(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formData;
|
return formData;
|
||||||
|
|
2761
package-lock.json
generated
2761
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -25,7 +25,9 @@
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1"
|
"@actions/core": "^1.10.1",
|
||||||
|
"install": "^0.13.0",
|
||||||
|
"npm": "^10.2.4"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16.0.0"
|
"node": ">=16.0.0"
|
||||||
|
|
|
@ -24,7 +24,7 @@ const convertToJSON = (value) => {
|
||||||
*
|
*
|
||||||
* @returns {FormData}
|
* @returns {FormData}
|
||||||
*/
|
*/
|
||||||
const convertToFormData = (data, files, convertPaths) => {
|
const convertToFormData = async (data, files, convertPaths) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(data)) {
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
@ -32,7 +32,11 @@ const convertToFormData = (data, files, convertPaths) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(files)) {
|
for (const [key, value] of Object.entries(files)) {
|
||||||
formData.append(key, fs.createReadStream(value));
|
if (Array.isArray(value)) {
|
||||||
|
value.forEach(v => formData.append(key, fs.createReadStream(v)))
|
||||||
|
} else {
|
||||||
|
formData.append(key, fs.createReadStream(value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return formData;
|
return formData;
|
||||||
|
|
Loading…
Reference in a new issue