Skip to content

Commit 93cdba3

Browse files
committed
feat: moving some code over to using the new post processing system
1 parent 4126ef4 commit 93cdba3

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/targets/node/request/client.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const request: Client = {
2727
};
2828

2929
let includeFS = false;
30-
const { push, blank, join, unshift } = new CodeBuilder({ indent: opts.indent });
30+
const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
3131

3232
push("const request = require('request');");
3333
blank();
@@ -89,6 +89,8 @@ export const request: Client = {
8989

9090
reqOpts.formData[param.name] = attachment;
9191
});
92+
93+
addPostProcessor(code => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
9294
break;
9395

9496
default:
@@ -107,6 +109,7 @@ export const request: Client = {
107109
push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
108110
});
109111
blank();
112+
addPostProcessor(code => code.replace(/'JAR'/, 'jar'));
110113
}
111114

112115
if (includeFS) {
@@ -122,8 +125,6 @@ export const request: Client = {
122125
push('console.log(body);', 1);
123126
push('});');
124127

125-
return join()
126-
.replace("'JAR'", 'jar')
127-
.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')");
128+
return join();
128129
},
129130
};

src/targets/python/requests/client.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const requests: Client<RequestsOptions> = {
3131
...options,
3232
};
3333
// Start snippet
34-
const { push, blank, join } = new CodeBuilder({ indent: opts.indent });
34+
const { push, blank, join, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
3535

3636
// Import requests
3737
push('import requests');
@@ -94,6 +94,9 @@ export const requests: Client<RequestsOptions> = {
9494
hasPayload = true;
9595
}
9696
}
97+
98+
// The `open()` call must be a literal in the code snippet.
99+
addPostProcessor(code => code.replace(/"open\('(.+)', 'rb'\)"/g, 'open("$1", "rb")'));
97100
break;
98101

99102
default: {
@@ -167,10 +170,6 @@ export const requests: Client<RequestsOptions> = {
167170
// Print response
168171
push('print(response.text)');
169172

170-
return (
171-
join()
172-
// The `open()` call must be a literal in the code snippet.
173-
.replace(/"open\('(.+)', 'rb'\)"/g, 'open("$1", "rb")')
174-
);
173+
return join();
175174
},
176175
};

0 commit comments

Comments
 (0)