48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { BUN_SQLITE_WGUI_HOSTS } from "@/db/types/db";
|
|
import fetchApi from "@/src/components/twui/utils/fetch/fetchApi";
|
|
import type { ApiReqParams } from "@/src/types";
|
|
import type { APIResponseObject } from "@moduletrace/bunext/types";
|
|
import type { Dispatch, SetStateAction } from "react";
|
|
|
|
type Params = {
|
|
iface: string;
|
|
local: boolean;
|
|
setLoading: Dispatch<SetStateAction<boolean>>;
|
|
setForm: Dispatch<SetStateAction<BUN_SQLITE_WGUI_HOSTS>>;
|
|
};
|
|
|
|
export default async function clientFetchIP({
|
|
iface,
|
|
local,
|
|
setLoading,
|
|
setForm,
|
|
}: Params) {
|
|
if (!iface) return;
|
|
|
|
const endpoint = local
|
|
? `/api/admin/interface-local-ip?interface=${iface}`
|
|
: `/api/admin/public-ip?interface=${iface}`;
|
|
|
|
setLoading(true);
|
|
|
|
fetchApi<ApiReqParams, APIResponseObject>(endpoint, {
|
|
method: "GET",
|
|
})
|
|
.then((res) => {
|
|
if (res.success && res.stringRes) {
|
|
setForm((prev) => ({
|
|
...prev,
|
|
public_ip_address: res.stringRes!,
|
|
}));
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
console.log(err);
|
|
})
|
|
.finally(() => {
|
|
setTimeout(() => {
|
|
setLoading(false);
|
|
}, 1000);
|
|
});
|
|
}
|