mirror of
https://github.com/luckfox-eng29/kvm.git
synced 2026-01-18 03:28:19 +01:00
feat: use the api url from device config (#161)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { LoaderFunctionArgs, redirect } from "react-router-dom";
|
||||
import api from "../api";
|
||||
import { CLOUD_API, CLOUD_APP, SIGNAL_API } from "@/ui.config";
|
||||
|
||||
const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
const url = new URL(request.url);
|
||||
@@ -11,17 +12,17 @@ const loader = async ({ request }: LoaderFunctionArgs) => {
|
||||
const clientId = searchParams.get("clientId");
|
||||
|
||||
const res = await api.POST(
|
||||
`${import.meta.env.VITE_SIGNAL_API}/cloud/register`,
|
||||
`${SIGNAL_API}/cloud/register`,
|
||||
{
|
||||
token: tempToken,
|
||||
cloudApi: import.meta.env.VITE_CLOUD_API,
|
||||
cloudApi: CLOUD_API,
|
||||
oidcGoogle,
|
||||
clientId,
|
||||
},
|
||||
);
|
||||
|
||||
if (!res.ok) throw new Error("Failed to register device");
|
||||
return redirect(import.meta.env.VITE_CLOUD_APP + `/devices/${deviceId}/setup`);
|
||||
return redirect(CLOUD_APP + `/devices/${deviceId}/setup`);
|
||||
};
|
||||
|
||||
export default function AdoptRoute() {
|
||||
|
||||
@@ -14,6 +14,7 @@ import { User } from "@/hooks/stores";
|
||||
import { checkAuth } from "@/main";
|
||||
import Fieldset from "@components/Fieldset";
|
||||
import { ChevronLeftIcon } from "@heroicons/react/16/solid";
|
||||
import { CLOUD_API } from "@/ui.config";
|
||||
|
||||
interface LoaderData {
|
||||
device: { id: string; name: string; user: { googleId: string } };
|
||||
@@ -24,7 +25,7 @@ const action = async ({ request }: ActionFunctionArgs) => {
|
||||
const { deviceId } = Object.fromEntries(await request.formData());
|
||||
|
||||
try {
|
||||
const res = await fetch(`${import.meta.env.VITE_CLOUD_API}/devices/${deviceId}`, {
|
||||
const res = await fetch(`${CLOUD_API}/devices/${deviceId}`, {
|
||||
method: "DELETE",
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@@ -46,7 +47,7 @@ const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${import.meta.env.VITE_CLOUD_API}/devices/${id}`, {
|
||||
const res = await fetch(`${CLOUD_API}/devices/${id}`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
mode: "cors",
|
||||
|
||||
@@ -16,6 +16,7 @@ import { User } from "@/hooks/stores";
|
||||
import { checkAuth } from "@/main";
|
||||
import Fieldset from "@components/Fieldset";
|
||||
import api from "../api";
|
||||
import { CLOUD_API } from "@/ui.config";
|
||||
|
||||
interface LoaderData {
|
||||
device: { id: string; name: string; user: { googleId: string } };
|
||||
@@ -31,7 +32,7 @@ const action = async ({ params, request }: ActionFunctionArgs) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await api.PUT(`${import.meta.env.VITE_CLOUD_API}/devices/${id}`, {
|
||||
const res = await api.PUT(`${CLOUD_API}/devices/${id}`, {
|
||||
name,
|
||||
});
|
||||
if (!res.ok) {
|
||||
@@ -49,7 +50,7 @@ const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const res = await fetch(`${import.meta.env.VITE_CLOUD_API}/devices/${id}`, {
|
||||
const res = await fetch(`${CLOUD_API}/devices/${id}`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
mode: "cors",
|
||||
|
||||
@@ -16,10 +16,11 @@ import { InputFieldWithLabel } from "@components/InputField";
|
||||
import { Button } from "@components/Button";
|
||||
import { checkAuth } from "@/main";
|
||||
import api from "../api";
|
||||
import { CLOUD_API } from "@/ui.config";
|
||||
|
||||
const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
await checkAuth();
|
||||
const res = await fetch(`${import.meta.env.VITE_CLOUD_API}/devices/${params.id}`, {
|
||||
const res = await fetch(`${CLOUD_API}/devices/${params.id}`, {
|
||||
method: "GET",
|
||||
mode: "cors",
|
||||
credentials: "include",
|
||||
@@ -35,7 +36,7 @@ const loader = async ({ params }: LoaderFunctionArgs) => {
|
||||
const action = async ({ request }: ActionFunctionArgs) => {
|
||||
// Handle form submission
|
||||
const { name, id, returnTo } = Object.fromEntries(await request.formData());
|
||||
const res = await api.PUT(`${import.meta.env.VITE_CLOUD_API}/devices/${id}`, { name });
|
||||
const res = await api.PUT(`${CLOUD_API}/devices/${id}`, { name });
|
||||
|
||||
if (res.ok) {
|
||||
return redirect(returnTo?.toString() ?? `/devices/${id}`);
|
||||
|
||||
@@ -36,6 +36,7 @@ import { DeviceStatus } from "./welcome-local";
|
||||
import FocusTrap from "focus-trap-react";
|
||||
import OtherSessionConnectedModal from "@/components/OtherSessionConnectedModal";
|
||||
import TerminalWrapper from "../components/Terminal";
|
||||
import { CLOUD_API, SIGNAL_API } from "@/ui.config";
|
||||
|
||||
interface LocalLoaderResp {
|
||||
authMode: "password" | "noPassword" | null;
|
||||
@@ -56,12 +57,12 @@ export interface LocalDevice {
|
||||
|
||||
const deviceLoader = async () => {
|
||||
const res = await api
|
||||
.GET(`${import.meta.env.VITE_SIGNAL_API}/device/status`)
|
||||
.GET(`${SIGNAL_API}/device/status`)
|
||||
.then(res => res.json() as Promise<DeviceStatus>);
|
||||
|
||||
if (!res.isSetup) return redirect("/welcome");
|
||||
|
||||
const deviceRes = await api.GET(`${import.meta.env.VITE_SIGNAL_API}/device`);
|
||||
const deviceRes = await api.GET(`${SIGNAL_API}/device`);
|
||||
if (deviceRes.status === 401) return redirect("/login-local");
|
||||
if (deviceRes.ok) {
|
||||
const device = (await deviceRes.json()) as LocalDevice;
|
||||
@@ -74,11 +75,11 @@ const deviceLoader = async () => {
|
||||
const cloudLoader = async (params: Params<string>): Promise<CloudLoaderResp> => {
|
||||
const user = await checkAuth();
|
||||
|
||||
const iceResp = await api.POST(`${import.meta.env.VITE_CLOUD_API}/webrtc/ice_config`);
|
||||
const iceResp = await api.POST(`${CLOUD_API}/webrtc/ice_config`);
|
||||
const iceConfig = await iceResp.json();
|
||||
|
||||
const deviceResp = await api.GET(
|
||||
`${import.meta.env.VITE_CLOUD_API}/devices/${params.id}`,
|
||||
`${CLOUD_API}/devices/${params.id}`,
|
||||
);
|
||||
|
||||
if (!deviceResp.ok) {
|
||||
@@ -142,7 +143,7 @@ export default function KvmIdRoute() {
|
||||
|
||||
try {
|
||||
const sd = btoa(JSON.stringify(pc.localDescription));
|
||||
const res = await api.POST(`${import.meta.env.VITE_SIGNAL_API}/webrtc/session`, {
|
||||
const res = await api.POST(`${SIGNAL_API}/webrtc/session`, {
|
||||
sd,
|
||||
// When on device, we don't need to specify the device id, as it's already known
|
||||
...(isOnDevice ? {} : { id: params.id }),
|
||||
@@ -317,7 +318,7 @@ export default function KvmIdRoute() {
|
||||
}
|
||||
|
||||
// Fire and forget
|
||||
api.POST(`${import.meta.env.VITE_CLOUD_API}/webrtc/turn_activity`, {
|
||||
api.POST(`${CLOUD_API}/webrtc/turn_activity`, {
|
||||
bytesReceived: bytesReceivedDelta,
|
||||
bytesSent: bytesSentDelta,
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import { User } from "@/hooks/stores";
|
||||
import EmptyCard from "@components/EmptyCard";
|
||||
import { LuMonitorSmartphone } from "react-icons/lu";
|
||||
import { ArrowRightIcon } from "@heroicons/react/16/solid";
|
||||
import { CLOUD_API } from "@/ui.config";
|
||||
|
||||
interface LoaderData {
|
||||
devices: { id: string; name: string; online: boolean; lastSeen: string }[];
|
||||
@@ -19,7 +20,7 @@ export const loader = async () => {
|
||||
const user = await checkAuth();
|
||||
|
||||
try {
|
||||
const res = await fetch(`${import.meta.env.VITE_CLOUD_API}/devices`, {
|
||||
const res = await fetch(`${CLOUD_API}/devices`, {
|
||||
method: "GET",
|
||||
credentials: "include",
|
||||
mode: "cors",
|
||||
|
||||
@@ -12,15 +12,16 @@ import LogoWhiteIcon from "@/assets/logo-white.svg";
|
||||
import api from "../api";
|
||||
import { DeviceStatus } from "./welcome-local";
|
||||
import ExtLink from "../components/ExtLink";
|
||||
import { SIGNAL_API } from "@/ui.config";
|
||||
|
||||
const loader = async () => {
|
||||
const res = await api
|
||||
.GET(`${import.meta.env.VITE_SIGNAL_API}/device/status`)
|
||||
.GET(`${SIGNAL_API}/device/status`)
|
||||
.then(res => res.json() as Promise<DeviceStatus>);
|
||||
|
||||
if (!res.isSetup) return redirect("/welcome");
|
||||
|
||||
const deviceRes = await api.GET(`${import.meta.env.VITE_SIGNAL_API}/device`);
|
||||
const deviceRes = await api.GET(`${SIGNAL_API}/device`);
|
||||
if (deviceRes.ok) return redirect("/");
|
||||
return null;
|
||||
};
|
||||
@@ -31,7 +32,7 @@ const action = async ({ request }: ActionFunctionArgs) => {
|
||||
|
||||
try {
|
||||
const response = await api.POST(
|
||||
`${import.meta.env.VITE_SIGNAL_API}/auth/login-local`,
|
||||
`${SIGNAL_API}/auth/login-local`,
|
||||
{
|
||||
password,
|
||||
},
|
||||
|
||||
@@ -9,10 +9,11 @@ import LogoWhiteIcon from "@/assets/logo-white.svg";
|
||||
import { cx } from "../cva.config";
|
||||
import api from "../api";
|
||||
import { DeviceStatus } from "./welcome-local";
|
||||
import { SIGNAL_API } from "@/ui.config";
|
||||
|
||||
const loader = async () => {
|
||||
const res = await api
|
||||
.GET(`${import.meta.env.VITE_SIGNAL_API}/device/status`)
|
||||
.GET(`${SIGNAL_API}/device/status`)
|
||||
.then(res => res.json() as Promise<DeviceStatus>);
|
||||
|
||||
if (res.isSetup) return redirect("/login-local");
|
||||
@@ -30,7 +31,7 @@ const action = async ({ request }: ActionFunctionArgs) => {
|
||||
|
||||
if (localAuthMode === "noPassword") {
|
||||
try {
|
||||
await api.POST(`${import.meta.env.VITE_SIGNAL_API}/device/setup`, {
|
||||
await api.POST(`${SIGNAL_API}/device/setup`, {
|
||||
localAuthMode,
|
||||
});
|
||||
return redirect("/");
|
||||
|
||||
@@ -10,10 +10,11 @@ import LogoBlueIcon from "@/assets/logo-blue.png";
|
||||
import LogoWhiteIcon from "@/assets/logo-white.svg";
|
||||
import api from "../api";
|
||||
import { DeviceStatus } from "./welcome-local";
|
||||
import { SIGNAL_API } from "@/ui.config";
|
||||
|
||||
const loader = async () => {
|
||||
const res = await api
|
||||
.GET(`${import.meta.env.VITE_SIGNAL_API}/device/status`)
|
||||
.GET(`${SIGNAL_API}/device/status`)
|
||||
.then(res => res.json() as Promise<DeviceStatus>);
|
||||
|
||||
if (res.isSetup) return redirect("/login-local");
|
||||
@@ -30,7 +31,7 @@ const action = async ({ request }: ActionFunctionArgs) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await api.POST(`${import.meta.env.VITE_SIGNAL_API}/device/setup`, {
|
||||
const response = await api.POST(`${SIGNAL_API}/device/setup`, {
|
||||
localAuthMode: "password",
|
||||
password,
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import LogoMark from "@/assets/logo-mark.png";
|
||||
import { cx } from "cva";
|
||||
import api from "../api";
|
||||
import { redirect } from "react-router-dom";
|
||||
import { SIGNAL_API } from "@/ui.config";
|
||||
|
||||
export interface DeviceStatus {
|
||||
isSetup: boolean;
|
||||
@@ -16,7 +17,7 @@ export interface DeviceStatus {
|
||||
|
||||
const loader = async () => {
|
||||
const res = await api
|
||||
.GET(`${import.meta.env.VITE_SIGNAL_API}/device/status`)
|
||||
.GET(`${SIGNAL_API}/device/status`)
|
||||
.then(res => res.json() as Promise<DeviceStatus>);
|
||||
|
||||
if (res.isSetup) return redirect("/login-local");
|
||||
|
||||
Reference in New Issue
Block a user