Signal API updates
This commit is contained in:
parent
83653ef23b
commit
c729a46a0c
25 changed files with 501 additions and 279 deletions
|
|
@ -24,6 +24,7 @@ export type FieldDescription = {
|
|||
label: string;
|
||||
kind?: "text" | "phone" | "select" | "multi" | "qrcode";
|
||||
getValue?: (token: string) => Promise<string>;
|
||||
getQRCode?: (token: string) => Promise<Record<string, string>>;
|
||||
refreshInterval?: number;
|
||||
getOptions?: (formState: any) => Promise<SelectOption[]>;
|
||||
autogenerated?: "token";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,45 @@
|
|||
import { Service } from "./service";
|
||||
import { NextResponse } from "next/server";
|
||||
import { db } from "@link-stack/bridge-common";
|
||||
import { Configuration, DevicesApi } from "@link-stack/signal-api";
|
||||
// import { revalidatePath } from "next/cache";
|
||||
import { Service, ServiceParams } from "./service";
|
||||
|
||||
export class Signal extends Service {}
|
||||
const fetchNoCache = async (url: string, options = {}) => {
|
||||
// @ts-ignore
|
||||
options.cache = options.cache || "no-store";
|
||||
return fetch(url, options);
|
||||
};
|
||||
|
||||
export class Signal extends Service {
|
||||
async getBot({ params: { token } }: ServiceParams) {
|
||||
const row = await db
|
||||
.selectFrom("SignalBot")
|
||||
.selectAll()
|
||||
.where("token", "=", token as string)
|
||||
.executeTakeFirstOrThrow();
|
||||
const { name } = row;
|
||||
if (!row.verified) {
|
||||
const config = new Configuration({
|
||||
basePath: process.env.BRIDGE_SIGNAL_URL,
|
||||
fetchApi: fetchNoCache,
|
||||
});
|
||||
|
||||
const devicesClient = new DevicesApi(config);
|
||||
const blob: Blob = await devicesClient.v1QrcodelinkGet({
|
||||
deviceName: name.replaceAll(" ", "_"),
|
||||
});
|
||||
const arrayBuffer = await blob.arrayBuffer();
|
||||
const buffer = Buffer.from(arrayBuffer);
|
||||
const qrString = buffer.toString("base64");
|
||||
const qr = `data:${blob.type};base64,${qrString}`;
|
||||
const finalRow = {
|
||||
...row,
|
||||
qr,
|
||||
};
|
||||
|
||||
return NextResponse.json(finalRow);
|
||||
} else {
|
||||
return NextResponse.json(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue