mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Make curl virtual command use configured corsProxy instead of hardcoded
This commit is contained in:
6 files changed
+20
-11
No files matched your search
@@ -23,9 +23,10 @@ const mockFS: JSRuntimeFS = {
|
||||
|
||||
describe('CurlCommand', () => {
|
||||
let curlCommand: CurlCommand;
|
||||
const testCorsProxy = 'https://proxy.shakespeare.diy/?url={href}';
|
||||
|
||||
beforeEach(() => {
|
||||
curlCommand = new CurlCommand(mockFS);
|
||||
curlCommand = new CurlCommand(mockFS, testCorsProxy);
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { JSRuntimeFS } from "../JSRuntime";
|
||||
import type { ShellCommand, ShellCommandResult } from "./ShellCommand";
|
||||
import { createSuccessResult, createErrorResult } from "./ShellCommand";
|
||||
import { isAbsolutePath, validateWritePath } from "../security";
|
||||
import { proxyUrl } from "../proxyUrl";
|
||||
|
||||
/**
|
||||
* Parsed curl options
|
||||
@@ -35,9 +36,11 @@ export class CurlCommand implements ShellCommand {
|
||||
usage = 'curl [options] <url>';
|
||||
|
||||
private fs: JSRuntimeFS;
|
||||
private corsProxy: string;
|
||||
|
||||
constructor(fs: JSRuntimeFS) {
|
||||
constructor(fs: JSRuntimeFS, corsProxy: string) {
|
||||
this.fs = fs;
|
||||
this.corsProxy = corsProxy;
|
||||
}
|
||||
|
||||
async execute(args: string[], cwd: string, _input?: string): Promise<ShellCommandResult> {
|
||||
@@ -61,9 +64,9 @@ export class CurlCommand implements ShellCommand {
|
||||
return createErrorResult(`${this.name}: unsupported protocol: ${url.protocol}`);
|
||||
}
|
||||
|
||||
// Proxy the URL through CorsProxy
|
||||
// Proxy the URL through configured CorsProxy
|
||||
const originalUrl = url.toString();
|
||||
const proxiedUrl = `https://proxy.shakespeare.diy/?url=${encodeURIComponent(originalUrl)}`;
|
||||
const proxiedUrl = proxyUrl(this.corsProxy, originalUrl);
|
||||
|
||||
// Prepare request
|
||||
const requestInit: RequestInit = {
|
||||
|
||||
@@ -35,12 +35,13 @@ describe('ShellTool', () => {
|
||||
let mockNostr: NPool;
|
||||
let shellTool: ShellTool;
|
||||
const testCwd = '/test/dir';
|
||||
const testCorsProxy = 'https://proxy.shakespeare.diy/?url={href}';
|
||||
|
||||
beforeEach(() => {
|
||||
mockFS = createMockFS();
|
||||
mockNostr = createMockNostr();
|
||||
mockGit = new Git({ fs: mockFS, nostr: mockNostr });
|
||||
shellTool = new ShellTool(mockFS, testCwd, mockGit);
|
||||
shellTool = new ShellTool(mockFS, testCwd, mockGit, '/projects', testCorsProxy);
|
||||
});
|
||||
|
||||
it('should have correct tool properties', () => {
|
||||
|
||||
@@ -53,6 +53,7 @@ export class ShellTool implements Tool<ShellToolParams> {
|
||||
private commands: Map<string, ShellCommand>;
|
||||
private projectsPath: string;
|
||||
private signer?: NostrSigner;
|
||||
private corsProxy: string;
|
||||
|
||||
readonly description = "Execute shell commands like cat, ls, cd, pwd, rm, cp, mv, echo, head, tail, grep, find, wc, touch, mkdir, sort, uniq, cut, tr, sed, diff, which, whoami, date, env, clear, git, curl, unzip, hexdump. Supports compound commands with &&, ||, ;, and | operators, and output redirection with > and >> operators";
|
||||
|
||||
@@ -62,11 +63,12 @@ export class ShellTool implements Tool<ShellToolParams> {
|
||||
),
|
||||
});
|
||||
|
||||
constructor(fs: JSRuntimeFS, cwd: string, git: Git, projectsPath: string = '/projects', signer?: NostrSigner) {
|
||||
constructor(fs: JSRuntimeFS, cwd: string, git: Git, projectsPath: string = '/projects', corsProxy: string, signer?: NostrSigner) {
|
||||
this.fs = fs;
|
||||
this.cwd = cwd;
|
||||
this.git = git;
|
||||
this.projectsPath = projectsPath;
|
||||
this.corsProxy = corsProxy;
|
||||
this.signer = signer;
|
||||
this.commands = new Map();
|
||||
|
||||
@@ -75,7 +77,7 @@ export class ShellTool implements Tool<ShellToolParams> {
|
||||
this.registerCommand(new CdCommand(fs));
|
||||
this.registerCommand(new ClearCommand());
|
||||
this.registerCommand(new CpCommand(fs));
|
||||
this.registerCommand(new CurlCommand(fs));
|
||||
this.registerCommand(new CurlCommand(fs, this.corsProxy));
|
||||
this.registerCommand(new CutCommand(fs));
|
||||
this.registerCommand(new DateCommand());
|
||||
this.registerCommand(new DiffCommand(fs));
|
||||
|
||||
Reference in new issue
Block a user