import { proxyWorker, withOwnedJob } from '@/lib/agent-worker-proxy';

export const GET = async (
  request: Request,
  context: { params: Promise<{ jobId: string }> },
) =>
  await withOwnedJob(context, async (jobId) => {
    const url = new URL(request.url);
    return await proxyWorker(
      jobId,
      'file',
      { method: 'GET' },
      new URLSearchParams({ path: url.searchParams.get('path') ?? '' }),
    );
  });

export const PUT = async (
  request: Request,
  context: { params: Promise<{ jobId: string }> },
) =>
  await withOwnedJob(
    context,
    async (jobId) =>
      await proxyWorker(jobId, 'file', {
        method: 'PUT',
        body: await request.text(),
      }),
  );
