update set ip

This commit is contained in:
Cjsah
2024-06-16 10:27:43 +08:00
parent 0337e465de
commit f3d055c9bb
7 changed files with 91 additions and 25 deletions

View File

@@ -2,8 +2,12 @@ import axios from "axios";
const SECOND = 1000;
export const baseUrl = () => {
return localStorage.getItem("remoteIp");
};
const ajax = axios.create({
baseURL: import.meta.env.VITE_API || location.origin,
// baseURL: import.meta.env.VITE_API || location.origin,
timeout: 120 * SECOND,
});

View File

@@ -1,10 +1,13 @@
import ajax from "./axios";
import ajax, { baseUrl } from "./axios";
import { ElMessage } from "element-plus/es";
/** https://github.com/gedoor/legado/tree/master/app/src/main/java/io/legado/app/api */
/** https://github.com/gedoor/legado/tree/master/app/src/main/java/io/legado/app/web */
const { hostname, port } = new URL(import.meta.env.VITE_API || location.origin);
const getUrl = () => {
const { hostname, port } = new URL(baseUrl());
return `${hostname}:${Number(port) + 1}`;
};
const isSourecEditor = /source/i.test(location.href);
const APIExceptionHandler = (error) => {
@@ -29,7 +32,7 @@ const saveBookProgressWithBeacon = (bookProgress) => {
if (!bookProgress) return;
// 常规请求可能会被取消 使用Fetch keep-alive 或者 navigator.sendBeacon
navigator.sendBeacon(
`${import.meta.env.VITE_API || location.origin}/saveBookProgress`,
`${baseUrl()}/saveBookProgress`,
JSON.stringify(bookProgress),
);
};
@@ -56,7 +59,7 @@ const search = (
/** @type {() => void} */ onFinish,
) => {
// webSocket
const url = `ws://${hostname}:${Number(port) + 1}/searchBook`;
const url = `ws://${getUrl()}/searchBook`;
const socket = new WebSocket(url);
socket.onopen = () => {
@@ -100,7 +103,7 @@ const debug = (
/** @type {() => void} */ onFinish,
) => {
// webSocket
const url = `ws://${hostname}:${Number(port) + 1}/${
const url = `ws://${getUrl()}/${
isBookSource ? "bookSource" : "rssSource"
}Debug`;