Skip to content

Commit

Permalink
replace node-fetch with native
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelCaso committed Oct 3, 2024
1 parent 9db820d commit 716475f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/nextjs/app/api/check-copyright/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import crypto from "crypto";
import FormData from "form-data";
import fetch from "node-fetch";

const ACR_SECRET: string = process.env.NEXT_PUBLIC_ACR_SECRET || "";

Expand Down Expand Up @@ -67,20 +65,20 @@ export async function POST(req: NextRequest) {
);
const signature = sign(stringToSign, defaultOptions.access_secret);

// Use native FormData API in Node.js 18+
const form = new FormData();
form.append("sample", buffer, { filename: "sample.mp3" });
form.append("sample", new Blob([buffer]), "sample.mp3");
form.append("sample_bytes", buffer.length.toString());
form.append("access_key", defaultOptions.access_key);
form.append("data_type", defaultOptions.data_type);
form.append("signature_version", defaultOptions.signature_version);
form.append("signature", signature);
form.append("timestamp", timestamp.toString());

const formStream = form as unknown as NodeJS.ReadableStream;

// Native fetch in Node.js 18+
const acrResponse = await fetch(`https://${defaultOptions.host}${defaultOptions.endpoint}`, {
method: "POST",
body: formStream,
body: form,
});

const acrResponseText = await acrResponse.text();
Expand Down

0 comments on commit 716475f

Please sign in to comment.