mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
fix
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import axios from "axios";
|
||||
|
||||
/** @type {string} localStorage保存自定义阅读http服务接口的键值 */
|
||||
export const baseURL_localStorage_key = "remoteUrl"
|
||||
const SECOND = 1000;
|
||||
|
||||
const ajax = axios.create({
|
||||
baseURL:
|
||||
import.meta.env.VITE_API ||
|
||||
localStorage.getItem("remoteUrl") ||
|
||||
localStorage.getItem(baseURL_localStorage_key) ||
|
||||
location.origin,
|
||||
timeout: 120 * SECOND,
|
||||
});
|
||||
|
||||
@@ -5,9 +5,9 @@ import { ElMessage } from "element-plus/es";
|
||||
/** https://github.com/gedoor/legado/tree/master/app/src/main/java/io/legado/app/web */
|
||||
|
||||
/**@type string */
|
||||
export let legado_http_entry_point;
|
||||
export let legado_http_entry_point = "";
|
||||
/**@type string */
|
||||
export let legado_webSocket_entry_point;
|
||||
export let legado_webSocket_entry_point = "";
|
||||
|
||||
/**
|
||||
* @param {string|URL} http_url
|
||||
@@ -45,7 +45,7 @@ export const setLeagdoHttpUrl = (http_url) => {
|
||||
"setLeagdoHttpUrl: FallBack to location.origin: " + location.origin,
|
||||
);
|
||||
}
|
||||
const { protocol, port, href } = url;
|
||||
const { protocol, port } = url;
|
||||
// websocket服务端口 为http服务端口 + 1
|
||||
let legado_webSocket_port, legado_webSocket_protocol;
|
||||
if (port !== "") {
|
||||
@@ -58,14 +58,12 @@ export const setLeagdoHttpUrl = (http_url) => {
|
||||
? "wss://"
|
||||
: "ws://";
|
||||
|
||||
ajax.defaults.baseURL = href;
|
||||
//持久化
|
||||
localStorage.setItem("remoteUrl", href);
|
||||
legado_http_entry_point = href;
|
||||
ajax.defaults.baseURL = url.toString();
|
||||
legado_http_entry_point = url.toString();
|
||||
|
||||
url.protocol = legado_webSocket_protocol;
|
||||
url.port = legado_webSocket_port;
|
||||
legado_webSocket_entry_point = url.href;
|
||||
legado_webSocket_entry_point = url.toString();
|
||||
|
||||
console.info("legado_api_config:");
|
||||
console.table({
|
||||
@@ -77,7 +75,7 @@ export const setLeagdoHttpUrl = (http_url) => {
|
||||
// 手动初始化 阅读web服务地址
|
||||
setLeagdoHttpUrl(ajax.defaults.baseURL);
|
||||
/**
|
||||
* @param {string|URL|undefined} http_url
|
||||
* @param {string|URL|undefined} http_url 不传为当前阅读HTTP服务接口
|
||||
* @returns
|
||||
*/
|
||||
const testLeagdoHttpUrlConnection = async (http_url = legado_http_entry_point) => {
|
||||
@@ -223,7 +221,7 @@ const getProxyCoverUrl = (coverUrl) => {
|
||||
return new URL(
|
||||
"/cover?path=" + encodeURIComponent(coverUrl),
|
||||
legado_http_entry_point,
|
||||
).href;
|
||||
).toString();
|
||||
};
|
||||
/**
|
||||
* 从阅读获取需要特定处理的图片
|
||||
@@ -240,7 +238,7 @@ const getProxyImageUrl = (src, width) => {
|
||||
"&width=" +
|
||||
width,
|
||||
legado_http_entry_point,
|
||||
);
|
||||
).toString();
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
@@ -85,6 +85,7 @@ import { useBookStore } from "@/store";
|
||||
import githubUrl from "@/assets/imgs/github.png";
|
||||
import { useLoading } from "@/hooks/loading";
|
||||
import { Search as SearchIcon } from "@element-plus/icons-vue";
|
||||
import {baseURL_localStorage_key} from "@/api/axios"
|
||||
import API, {
|
||||
legado_http_entry_point,
|
||||
validatorHttpUrl,
|
||||
@@ -203,7 +204,7 @@ export default defineComponent({
|
||||
instance.confirmButtonLoading = true;
|
||||
instance.confirmButtonText = "校验中……";
|
||||
// instance.inputValue
|
||||
const url = new URL(instance.inputValue);
|
||||
const url = new URL(instance.inputValue).toString();
|
||||
API.testLeagdoHttpUrlConnection(url)
|
||||
//API.getBookShelf()
|
||||
.then(function (configStr) {
|
||||
@@ -213,6 +214,11 @@ export default defineComponent({
|
||||
store.clearSearchBooks();
|
||||
store.setNewConnect(false);
|
||||
setLeagdoHttpUrl(url);
|
||||
if (url === location.origin) {
|
||||
localStorage.removeItem(baseURL_localStorage_key);
|
||||
} else {
|
||||
localStorage.setItem(baseURL_localStorage_key, url);
|
||||
}
|
||||
store.setConnectStatus("已连接 " + url.toString());
|
||||
fetchBookShelfData();
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user