mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 21:03:46 +00:00
15 lines
534 B
TypeScript
15 lines
534 B
TypeScript
import { escapeSingleQuotes } from "./format";
|
|
|
|
export const buildCurl = (method: string, url: string, body?: string, token?: string) => {
|
|
const headers: string[] = [];
|
|
if (token) {
|
|
headers.push(`-H 'Authorization: Bearer ${escapeSingleQuotes(token)}'`);
|
|
}
|
|
if (body) {
|
|
headers.push(`-H 'Content-Type: application/json'`);
|
|
}
|
|
const data = body ? `-d '${escapeSingleQuotes(body)}'` : "";
|
|
return `curl -X ${method} ${headers.join(" ")} ${data} '${escapeSingleQuotes(url)}'`
|
|
.replace(/\s+/g, " ")
|
|
.trim();
|
|
};
|