import { NextResponse } from 'next/server';

import { withAuth, withPermission } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { getDownloadUrl } from '@/lib/services/files';

export const GET = withAuth(
  withPermission('files', 'view', async (req, ctx, params) => {
    try {
      const result = await getDownloadUrl(params.id!, ctx.portId);
      return NextResponse.json({ data: result });
    } catch (error) {
      return errorResponse(error);
    }
  }),
);
