Skip to content

Commit 012e727

Browse files
committed
fix text response
1 parent cdb999f commit 012e727

File tree

7 files changed

+81
-38
lines changed

7 files changed

+81
-38
lines changed

Diff for: nodes/Browserless/v2/helpers/hooks.ts

+11-24
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,23 @@ function getresponseContentType (response: IN8nHttpFullResponse): string {
5656
}
5757

5858
function getFileTypeFromContentType (contentType: string): string {
59+
// application/pdf -> pdf
60+
// image/jpeg -> jpeg
5961
const type = contentType.split(';')[0].trim()
62+
63+
// any/thing -> any
64+
if (type.includes('/')) {
65+
return type.split('/')[0]
66+
}
67+
6068
return type
6169
}
6270

6371
function getFileExtensionFromContentType (contentType: string): string {
6472
const type = contentType.split(';')[0].trim()
6573

66-
// @ts-ignore
67-
console.log('type', contentType, type, type.split('/')[1])
68-
69-
if (/^image\//.test(type)) {
70-
return type.split('/')[1]
71-
}
72-
73-
if (/^audio\//.test(type)) {
74-
return type.split('/')[1]
75-
}
76-
77-
if (/^video\//.test(type)) {
78-
return type.split('/')[1]
79-
}
80-
81-
if (/^text\//.test(type)) {
82-
return type.split('/')[1]
83-
}
84-
85-
if (/^application\//.test(type)) {
74+
// any/thing -> thing
75+
if (typeof type === 'string' && type.includes('/')) {
8676
return type.split('/')[1]
8777
}
8878

@@ -99,14 +89,11 @@ export const postReceiveActionBinaryData: PostReceiveAction =
9989

10090
const { binary } = items[0]
10191

102-
if (binary && binary.data) {
92+
if (binary && binary.data && binary.data.mimeType === 'text/plain') {
10393
const data = binary.data as IBinaryData
10494
data.mimeType = contentType
10595
data.fileType = getFileTypeFromContentType(contentType) as BinaryFileType
10696
data.fileExtension = getFileExtensionFromContentType(contentType)
107-
108-
// @ts-ignore
109-
console.log('data', data)
11097
}
11198

11299
return items

Diff for: nodes/Browserless/v2/properties.json

+36-8
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,11 @@
5151
"output": {
5252
"postReceive": [
5353
{
54-
"type": "binaryData",
54+
"type": "setKeyValue",
5555
"properties": {
56-
"destinationProperty": "data"
56+
"data": "={{$response.body}}"
5757
}
58-
},
59-
"${helpers.hooks.postReceiveActionBinaryData}"
58+
}
6059
]
6160
}
6261
}
@@ -74,12 +73,11 @@
7473
"output": {
7574
"postReceive": [
7675
{
77-
"type": "binaryData",
76+
"type": "setKeyValue",
7877
"properties": {
79-
"destinationProperty": "data"
78+
"data": "={{$response.body}}"
8079
}
81-
},
82-
"${helpers.hooks.postReceiveActionBinaryData}"
80+
}
8381
]
8482
}
8583
}
@@ -93,6 +91,16 @@
9391
"request": {
9492
"method": "POST",
9593
"url": "=/content"
94+
},
95+
"output": {
96+
"postReceive": [
97+
{
98+
"type": "setKeyValue",
99+
"properties": {
100+
"data": "={{$response.body}}"
101+
}
102+
}
103+
]
96104
}
97105
}
98106
},
@@ -105,6 +113,16 @@
105113
"request": {
106114
"method": "POST",
107115
"url": "=/download"
116+
},
117+
"output": {
118+
"postReceive": [
119+
{
120+
"type": "setKeyValue",
121+
"properties": {
122+
"data": "={{$response.body}}"
123+
}
124+
}
125+
]
108126
}
109127
}
110128
},
@@ -117,6 +135,16 @@
117135
"request": {
118136
"method": "POST",
119137
"url": "=/function"
138+
},
139+
"output": {
140+
"postReceive": [
141+
{
142+
"type": "setKeyValue",
143+
"properties": {
144+
"data": "={{$response.body}}"
145+
}
146+
}
147+
]
120148
}
121149
}
122150
},

Diff for: nodes/Browserless/v2/resources/browser-rest-apis/content/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ const rawOption: INodePropertyOptions = {
2525
method: 'POST',
2626
url: '=/content',
2727
},
28+
output: {
29+
postReceive: [
30+
{
31+
type: 'setKeyValue',
32+
properties: {
33+
data: '={{$response.body}}',
34+
},
35+
},
36+
],
37+
},
2838
},
2939
}
3040

Diff for: nodes/Browserless/v2/resources/browser-rest-apis/download/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ const rawOption: INodePropertyOptions = {
2525
method: 'POST',
2626
url: '=/download',
2727
},
28+
output: {
29+
postReceive: [
30+
{
31+
type: 'setKeyValue',
32+
properties: {
33+
data: '={{$response.body}}',
34+
},
35+
},
36+
],
37+
},
2838
},
2939
}
3040

Diff for: nodes/Browserless/v2/resources/browser-rest-apis/execute-function/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ const rawOption: INodePropertyOptions = {
2525
method: 'POST',
2626
url: '=/function',
2727
},
28+
output: {
29+
postReceive: [
30+
{
31+
type: 'setKeyValue',
32+
properties: {
33+
data: '={{$response.body}}',
34+
},
35+
},
36+
],
37+
},
2838
},
2939
}
3040

Diff for: nodes/Browserless/v2/resources/browser-rest-apis/pdf/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ const rawOption: INodePropertyOptions = {
2828
output: {
2929
postReceive: [
3030
{
31-
type: 'binaryData',
31+
type: 'setKeyValue',
3232
properties: {
33-
destinationProperty: 'data',
33+
data: '={{$response.body}}',
3434
},
3535
},
36-
helpers.hooks.postReceiveActionBinaryData,
3736
],
3837
},
3938
},

Diff for: nodes/Browserless/v2/resources/browser-rest-apis/screenshot/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ const rawOption: INodePropertyOptions = {
2828
output: {
2929
postReceive: [
3030
{
31-
type: 'binaryData',
31+
type: 'setKeyValue',
3232
properties: {
33-
destinationProperty: 'data',
33+
data: '={{$response.body}}',
3434
},
3535
},
36-
helpers.hooks.postReceiveActionBinaryData,
3736
],
3837
},
3938
},

0 commit comments

Comments
 (0)