diff --git a/modules/web/scripts/sync.js b/modules/web/scripts/sync.js index 1d761449e..88eb72262 100644 --- a/modules/web/scripts/sync.js +++ b/modules/web/scripts/sync.js @@ -3,8 +3,8 @@ import fs from "node:fs"; import process from "node:process"; if (!process.env.GITHUB_ENV) { - console.log("非Github WorkFlows环境,取消文件复制") - process.exit() + console.log("非Github WorkFlows环境,取消文件复制"); + process.exit(); } const LEGADO_ASSETS_WEB_VUE_DIR = new URL( "../../../app/src/main/assets/web/vue", diff --git a/modules/web/src/api/axios.js b/modules/web/src/api/axios.js index f3931c9ad..fe1a9a235 100644 --- a/modules/web/src/api/axios.js +++ b/modules/web/src/api/axios.js @@ -3,7 +3,10 @@ import axios from "axios"; const SECOND = 1000; const ajax = axios.create({ - baseURL: import.meta.env.VITE_API || localStorage.getItem("remoteIp") || location.origin, + baseURL: + import.meta.env.VITE_API || + localStorage.getItem("remoteIp") || + location.origin, timeout: 120 * SECOND, }); diff --git a/modules/web/src/api/index.js b/modules/web/src/api/index.js index 454db8f4b..cf424ce78 100644 --- a/modules/web/src/api/index.js +++ b/modules/web/src/api/index.js @@ -4,8 +4,8 @@ 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 */ -let legado_http_origin -let legado_webSocket_origin +let legado_http_origin; +let legado_webSocket_origin; const setLeagdoHttpUrl = (http_url) => { let legado_webSocket_port; @@ -19,29 +19,28 @@ const setLeagdoHttpUrl = (http_url) => { } else { legado_webSocket_port = protocol.startsWith("https:") ? "444" : "81"; } - legado_webSocket_origin = - `${protocol.startsWith("https:") ? "wss://" : "ws://"}${hostname}:${legado_webSocket_port}`; + legado_webSocket_origin = `${protocol.startsWith("https:") ? "wss://" : "ws://"}${hostname}:${legado_webSocket_port}`; console.info("legado_server_config:"); - console.table({legado_http_origin, legado_webSocket_origin}); + console.table({ legado_http_origin, legado_webSocket_origin }); }; // 手动初始化 阅读web服务地址 setLeagdoHttpUrl(ajax.defaults.baseURL); const testLeagdoHttpUrlConnection = async (http_url) => { - const {data = {}} = await ajax.get("/getReadConfig", { + const { data = {} } = await ajax.get("/getReadConfig", { baseURL: http_url, - timeout: 3000 - }) + timeout: 3000, + }); // 返回结果应该是JSON 并有键值isSuccess try { - if ("isSuccess" in data) return data.data - throw new Error("ReadConfig后端返回格式错误" ) + if ("isSuccess" in data) return data.data; + throw new Error("ReadConfig后端返回格式错误"); } catch { - throw new Error("ReadConfig后端返回格式错误" ) + throw new Error("ReadConfig后端返回格式错误"); } -} +}; const isSourecEditor = /source/i.test(location.href); const APIExceptionHandler = (error) => { @@ -59,7 +58,7 @@ ajax.interceptors.response.use((response) => response, APIExceptionHandler); // 书架API // Http /** @returns {Promise>} */ -const getReadConfig = () => ajax.get("/getReadConfig", {timeout: 3000}); +const getReadConfig = () => ajax.get("/getReadConfig", { timeout: 3000 }); const saveReadConfig = (config) => ajax.post("/saveReadConfig", config); const saveBookProgress = (bookProgress) => @@ -70,7 +69,7 @@ const saveBookProgressWithBeacon = (bookProgress) => { // 常规请求可能会被取消 使用Fetch keep-alive 或者 navigator.sendBeacon navigator.sendBeacon( `${legado_http_origin}/saveBookProgress`, - JSON.stringify(bookProgress) + JSON.stringify(bookProgress), ); }; @@ -81,22 +80,21 @@ const getChapterList = (/** @type {string} */ bookUrl) => const getBookContent = ( /** @type {string} */ bookUrl, - /** @type {number} */ chapterIndex + /** @type {number} */ chapterIndex, ) => ajax.get( "/getBookContent?url=" + encodeURIComponent(bookUrl) + "&index=" + - chapterIndex + chapterIndex, ); // webSocket const search = ( /** @type {string} */ searchKey, /** @type {(data: string) => void} */ onReceive, - /** @type {() => void} */ onFinish + /** @type {() => void} */ onFinish, ) => { - const url = `${legado_webSocket_origin}/searchBook`; const socket = new WebSocket(url); @@ -140,9 +138,8 @@ const debug = ( /** @type {string} */ sourceUrl, /** @type {string} */ searchKey, /** @type {(data: string) => void} */ onReceive, - /** @type {() => void} */ onFinish + /** @type {() => void} */ onFinish, ) => { - const url = `${legado_webSocket_origin}/${ isBookSource ? "bookSource" : "rssSource" }Debug`; @@ -168,16 +165,16 @@ const debug = ( * @param {string} coverUrl */ const getProxyCoverUrl = (coverUrl) => { - if(coverUrl.startsWith(legado_http_origin)) return coverUrl + if (coverUrl.startsWith(legado_http_origin)) return coverUrl; return legado_http_origin + "/cover?path=" + encodeURIComponent(coverUrl); -} +}; /** * 从阅读获取需要特定处理的图片 * @param {string} src * @param {number|`${number}`} width */ const getProxyImageUrl = (src, width) => { - if (src.startsWith(legado_http_origin)) return src + if (src.startsWith(legado_http_origin)) return src; return ( legado_http_origin + "/image?path=" + @@ -187,7 +184,7 @@ const getProxyImageUrl = (src, width) => { "&width=" + width ); -} +}; export default { getReadConfig, diff --git a/modules/web/src/components/BookItems.vue b/modules/web/src/components/BookItems.vue index cb503dfa8..f5bfa0bd0 100644 --- a/modules/web/src/components/BookItems.vue +++ b/modules/web/src/components/BookItems.vue @@ -57,14 +57,12 @@ const props = defineProps(["books", "isSearch"]); const emit = defineEmits(["bookClick"]); const handleClick = (book) => emit("bookClick", book); const getCover = (coverUrl) => { - return isLegadoUrl(coverUrl) - ? API.getProxyCoverUrl(coverUrl) : coverUrl + return isLegadoUrl(coverUrl) ? API.getProxyCoverUrl(coverUrl) : coverUrl; }; const proxyImage = (event) => { event.target.src = API.getProxyCoverUrl(event.target.src); }; - const subJustify = computed(() => props.isSearch ? "space-between" : "flex-start", ); diff --git a/modules/web/src/components/ChapterContent.vue b/modules/web/src/components/ChapterContent.vue index 28b8c805b..2052cfe6a 100644 --- a/modules/web/src/components/ChapterContent.vue +++ b/modules/web/src/components/ChapterContent.vue @@ -34,11 +34,15 @@ const props = defineProps({ const getImageSrc = (content) => { const imgPattern = /]*src="([^"]*(?:"[^>]+\})?)"[^>]*>/; const src = content.match(imgPattern)[1]; - if (isLegadoUrl(src)) return API.getProxyImageUrl(src, useBookStore().config.readWidth) + if (isLegadoUrl(src)) + return API.getProxyImageUrl(src, useBookStore().config.readWidth); return src; }; const proxyImage = (event) => { - event.target.src = API.getProxyImageUrl(event.target.src, useBookStore().config.readWidth); + event.target.src = API.getProxyImageUrl( + event.target.src, + useBookStore().config.readWidth, + ); }; const calculateWordCount = (paragraph) => { diff --git a/modules/web/src/components/PopCatalog.vue b/modules/web/src/components/PopCatalog.vue index 0b1f9e373..223937161 100644 --- a/modules/web/src/components/PopCatalog.vue +++ b/modules/web/src/components/PopCatalog.vue @@ -27,10 +27,7 @@ import CatalogItem from "./CatalogItem.vue"; const store = useBookStore(); -const { - catalog, - popCataVisible, miniInterface -} = storeToRefs(store); +const { catalog, popCataVisible, miniInterface } = storeToRefs(store); //主题 const isNight = computed(() => store.theme); @@ -89,7 +86,6 @@ const gotoChapter = (note) => { store.saveBookProgress(); emit("getContent", chapterIndex); }; -