Fixing the issues on the reset button

This commit is contained in:
2026-03-14 12:55:19 -04:00
parent ab3481706c
commit 3baa4bcc7f
2 changed files with 23 additions and 36 deletions

View File

@@ -4,26 +4,17 @@ import type { GenerateResult } from '@appTypes/qrcode';
const host = 'http://localhost:5001';
export async function generateQr(payload: { text: string; size: number }): Promise<GenerateResult> {
const url = `${host}/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 {}
const url = `${host}/api/qrcode/generate`;
const resp = await axios.post(url, payload, {
responseType: 'arraybuffer',
validateStatus: (status) => status >= 200 && status < 300,
});
const contentType = (resp.headers['content-type'] || '').toString();
if (contentType.startsWith('image/')) {
return { mime: contentType, data: resp.data as ArrayBuffer };
} catch (error) {
console.error(error);
}
return { mime: contentType || 'image/png', data: resp.data as ArrayBuffer };
}