Adding the form and the api call

This commit is contained in:
2026-03-14 00:40:03 -04:00
parent 6ce0fc0768
commit 6b651d3c4f
9 changed files with 463 additions and 75 deletions

View File

@@ -0,0 +1,27 @@
import axios from 'axios';
import type { GenerateResult } from '@types/qrcode';
export async function generateQr(payload: { text: string; size: number }): Promise<GenerateResult> {
const url = 'http://localhost:5000/api/qrcode/generate';
const resp = await axios.post(url, payload, {
responseType: 'arraybuffer',
validateStatus: (s) => s >= 200 && s < 300,
});
const contentType = (resp.headers['content-type'] || '').toString();
// Try JSON parse in case backend returns { imageUrl }
try {
const decoded = new TextDecoder().decode(resp.data);
const parsed = JSON.parse(decoded);
if (parsed?.imageUrl) return { imageUrl: parsed.imageUrl };
} catch (error) {
console.error(error);
}
if (contentType.startsWith('image/')) {
return { mime: contentType, data: resp.data as ArrayBuffer };
}
return { mime: contentType || 'image/png', data: resp.data as ArrayBuffer };
}