mirror of
https://github.com/MengMengCode/VoCat.git
synced 2026-08-20 23:03:44 +08:00
- Introduced a new field `custom_phone_number` in the CardPolicy model and database schema. - Updated the API to handle custom phone number input, including validation and normalization. - Modified the CardPolicyPanel component to allow users to set and save a custom phone number. - Enhanced the settings API to include the custom phone number in responses and updates. - Added tests to ensure the correct functionality of custom phone number handling. - Removed hardcoded environment variable for VOCAT_ADDR in service files.
86 lines
2.8 KiB
TypeScript
86 lines
2.8 KiB
TypeScript
import { api } from "../../api";
|
|
import type { CardPolicy } from "../../types";
|
|
|
|
async function ok(p: Promise<unknown>): Promise<{ ok: boolean }> {
|
|
try {
|
|
await p;
|
|
return { ok: true };
|
|
} catch {
|
|
return { ok: false };
|
|
}
|
|
}
|
|
|
|
export function enableVoWiFi(deviceId: string) {
|
|
return ok(api(`/devices/${deviceId}/vowifi`, { method: "PATCH", body: { enabled: true } }));
|
|
}
|
|
export function disableVoWiFi(deviceId: string) {
|
|
return ok(api(`/devices/${deviceId}/vowifi`, { method: "PATCH", body: { enabled: false } }));
|
|
}
|
|
export function setFlightMode(deviceId: string, enabled: boolean) {
|
|
return ok(api(`/devices/${deviceId}/flight-mode`, { method: "PATCH", body: { enabled } }));
|
|
}
|
|
export function getCardPolicy(iccid: string) {
|
|
return api<CardPolicy>(`/cards/${iccid}/policy`);
|
|
}
|
|
export interface CardPolicyUpdate {
|
|
vowifiEnabled?: boolean;
|
|
airplaneEnabled?: boolean;
|
|
apn?: string;
|
|
ipVersion?: "IP" | "IPV6" | "IPV4V6";
|
|
customPhoneNumber?: string;
|
|
}
|
|
export function updateCardPolicy(iccid: string, body: CardPolicyUpdate) {
|
|
return api<CardPolicy>(`/cards/${iccid}/policy`, { method: "PUT", body });
|
|
}
|
|
export function putCardPolicy(iccid: string, body: { vowifiEnabled: boolean; airplaneEnabled: boolean }) {
|
|
return ok(updateCardPolicy(iccid, body));
|
|
}
|
|
|
|
export interface ModemAPNProfile {
|
|
cid: number;
|
|
apn: string;
|
|
ipVersion: "IP" | "IPV6" | "IPV4V6";
|
|
}
|
|
export function getDeviceAPNs(deviceId: string) {
|
|
return api<{ items: ModemAPNProfile[] }>(`/devices/${deviceId}/network/apns`);
|
|
}
|
|
|
|
export interface CardAPNProfile {
|
|
id: number;
|
|
iccid: string;
|
|
apn: string;
|
|
username: string;
|
|
hasPassword: boolean;
|
|
proxy: string;
|
|
mcc: string;
|
|
mnc: string;
|
|
ipVersion: "IP" | "IPV6" | "IPV4V6";
|
|
roamingIpVersion: "IP" | "IPV6" | "IPV4V6";
|
|
authType: "NONE" | "PAP" | "CHAP" | "PAP_OR_CHAP";
|
|
createdAt?: string;
|
|
updatedAt?: string;
|
|
}
|
|
export function getCardAPNs(iccid: string) {
|
|
return api<{ items: CardAPNProfile[] }>(`/cards/${iccid}/apns`);
|
|
}
|
|
export interface CardAPNCreate {
|
|
apn: string;
|
|
username: string;
|
|
password: string;
|
|
proxy: string;
|
|
mcc: string;
|
|
mnc: string;
|
|
ipVersion: "IP" | "IPV6" | "IPV4V6";
|
|
roamingIpVersion: "IP" | "IPV6" | "IPV4V6";
|
|
authType: "NONE" | "PAP" | "CHAP" | "PAP_OR_CHAP";
|
|
}
|
|
export function createCardAPN(iccid: string, body: CardAPNCreate) {
|
|
return api<CardAPNProfile>(`/cards/${iccid}/apns`, { method: "POST", body });
|
|
}
|
|
export function updateCardAPN(iccid: string, id: number, body: Omit<CardAPNCreate, "password"> & { password?: string; clearPassword?: boolean }) {
|
|
return api<CardAPNProfile>(`/cards/${iccid}/apns/${id}`, { method: "PATCH", body });
|
|
}
|
|
export function deleteCardAPN(iccid: string, id: number) {
|
|
return api<{ deleted: boolean; id: number }>(`/cards/${iccid}/apns/${id}`, { method: "DELETE" });
|
|
}
|