adding the logic to generate the image
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user