adding the logic to generate the image

This commit is contained in:
2026-03-14 02:50:54 -04:00
parent 6b651d3c4f
commit 21533ff4f5
14 changed files with 188 additions and 56 deletions

View File

@@ -1,8 +1,10 @@
import axios from 'axios';
import type { GenerateResult } from '@types/qrcode';
import type { GenerateResult } from '@appTypes/qrcode';
const host = 'http://localhost:5001';
export async function generateQr(payload: { text: string; size: number }): Promise<GenerateResult> {
const url = 'http://localhost:5000/api/qrcode/generate';
const url = `${host}/api/qrcode/generate`;
const resp = await axios.post(url, payload, {
responseType: 'arraybuffer',
validateStatus: (s) => s >= 200 && s < 300,
@@ -14,10 +16,10 @@ export async function generateQr(payload: { text: string; size: number }): Promi
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 (parsed?.imageUrl) {
return { imageUrl: parsed.imageUrl };
}
} catch {}
if (contentType.startsWith('image/')) {
return { mime: contentType, data: resp.data as ArrayBuffer };