fix: qr base64 > qr uri
This commit is contained in:
parent
ae9c18b771
commit
7ba11614e7
|
|
@ -25,8 +25,18 @@ export async function getAddressInfoBulk(addresses: string[]): Promise<Record<st
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getQrUrl(text: string): string {
|
export async function fetchQrBase64(text: string): Promise<string> {
|
||||||
return `${API}/invoice/qr/${encodeURIComponent(text)}`;
|
const url = `${API}/invoice/qr/${encodeURIComponent(text)}`;
|
||||||
|
try {
|
||||||
|
const res = await fetch(url);
|
||||||
|
if (!res.ok) return url;
|
||||||
|
const buf = await res.arrayBuffer();
|
||||||
|
const type = res.headers.get("content-type") || "image/png";
|
||||||
|
const b64 = Buffer.from(buf).toString("base64");
|
||||||
|
return `data:${type};base64,${b64}`;
|
||||||
|
} catch {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getAvailableCoins(): Promise<string[]> {
|
export async function getAvailableCoins(): Promise<string[]> {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { Elysia, t } from "elysia";
|
import { Elysia, t } from "elysia";
|
||||||
import sql from "./db";
|
import sql from "./db";
|
||||||
import { derive } from "./address";
|
import { derive } from "./address";
|
||||||
import { getExchangeRates, getAvailableCoins, getQrUrl } from "./freedom";
|
import { getExchangeRates, getAvailableCoins, fetchQrBase64 } from "./freedom";
|
||||||
import { PLANS, COINS } from "./plans";
|
import { PLANS, COINS } from "./plans";
|
||||||
import { watchPayment } from "./monitor";
|
import { watchPayment } from "./monitor";
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ export const routes = new Elysia()
|
||||||
status: payment.status,
|
status: payment.status,
|
||||||
expires_at: payment.expires_at,
|
expires_at: payment.expires_at,
|
||||||
txs: [],
|
txs: [],
|
||||||
qr_url: getQrUrl(uri),
|
qr_url: await fetchQrBase64(uri),
|
||||||
coin_label: coinInfo.label,
|
coin_label: coinInfo.label,
|
||||||
coin_ticker: coinInfo.ticker,
|
coin_ticker: coinInfo.ticker,
|
||||||
};
|
};
|
||||||
|
|
@ -170,7 +170,7 @@ export const routes = new Elysia()
|
||||||
expires_at: payment.expires_at,
|
expires_at: payment.expires_at,
|
||||||
paid_at: payment.paid_at,
|
paid_at: payment.paid_at,
|
||||||
txs: txs.map((t: any) => ({ txid: t.txid, amount: t.amount, confirmed: t.confirmed, detected_at: t.detected_at })),
|
txs: txs.map((t: any) => ({ txid: t.txid, amount: t.amount, confirmed: t.confirmed, detected_at: t.detected_at })),
|
||||||
qr_url: getQrUrl(uri),
|
qr_url: await fetchQrBase64(uri),
|
||||||
coin_label: coinInfo?.label,
|
coin_label: coinInfo?.label,
|
||||||
coin_ticker: coinInfo?.ticker,
|
coin_ticker: coinInfo?.ticker,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue