From f3d055c9bbd88d1c6a809ff6994b74b4b94c9de4 Mon Sep 17 00:00:00 2001 From: Cjsah Date: Sun, 16 Jun 2024 10:27:43 +0800 Subject: [PATCH 1/3] update set ip --- modules/web/src/api/axios.js | 6 +- modules/web/src/api/index.js | 13 ++-- modules/web/src/auto-imports.d.ts | 3 +- modules/web/src/components/BookItems.vue | 7 +-- modules/web/src/store/bookStore.js | 8 +++ modules/web/src/utils/utils.js | 3 +- modules/web/src/views/BookShelf.vue | 76 ++++++++++++++++++++---- 7 files changed, 91 insertions(+), 25 deletions(-) diff --git a/modules/web/src/api/axios.js b/modules/web/src/api/axios.js index cb2c50f6b..352ce6f60 100644 --- a/modules/web/src/api/axios.js +++ b/modules/web/src/api/axios.js @@ -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, }); diff --git a/modules/web/src/api/index.js b/modules/web/src/api/index.js index aeb9f1838..c71f876dd 100644 --- a/modules/web/src/api/index.js +++ b/modules/web/src/api/index.js @@ -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`; diff --git a/modules/web/src/auto-imports.d.ts b/modules/web/src/auto-imports.d.ts index 964ac4fd0..567fdd4b1 100644 --- a/modules/web/src/auto-imports.d.ts +++ b/modules/web/src/auto-imports.d.ts @@ -82,5 +82,6 @@ declare global { // for type re-export declare global { // @ts-ignore - export type { Component, ComponentPublicInstance, ComputedRef, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' + export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' + import('vue') } diff --git a/modules/web/src/components/BookItems.vue b/modules/web/src/components/BookItems.vue index 333d4a969..c8543882c 100644 --- a/modules/web/src/components/BookItems.vue +++ b/modules/web/src/components/BookItems.vue @@ -50,15 +50,14 @@