fix(mini-utilities): proxy compress-pdf through Next.js API route to bypass CORS
This commit is contained in:
@@ -486,14 +486,14 @@ function PdfReducer() {
|
||||
const formData = new FormData();
|
||||
formData.append("fileInput", file);
|
||||
formData.append("optimizeLevel", optimizeLevel);
|
||||
const res = await fetch(
|
||||
"http://10.10.10.166:8087/api/v1/misc/compress-pdf",
|
||||
{
|
||||
method: "POST",
|
||||
body: formData,
|
||||
},
|
||||
);
|
||||
if (!res.ok) throw new Error(`Eroare server: ${res.status}`);
|
||||
const res = await fetch("/api/compress-pdf", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
throw new Error(data.error ?? `Eroare server: ${res.status}`);
|
||||
}
|
||||
const blob = await res.blob();
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement("a");
|
||||
@@ -501,9 +501,11 @@ function PdfReducer() {
|
||||
a.download = file.name.replace(/\.pdf$/i, "-comprimat.pdf");
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
setError(
|
||||
"Nu s-a putut conecta la Stirling PDF. Folosește linkul de mai jos pentru a deschide aplicația manual.",
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "Nu s-a putut contacta Stirling PDF.",
|
||||
);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user