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