Skip to content

Commit

Permalink
style(modules/web): lint code with eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwite committed Oct 3, 2024
1 parent 2b835c0 commit ad27bd8
Show file tree
Hide file tree
Showing 16 changed files with 195 additions and 196 deletions.
4 changes: 2 additions & 2 deletions modules/web/scripts/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion modules/web/src/api/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
45 changes: 21 additions & 24 deletions modules/web/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => {
Expand All @@ -59,7 +58,7 @@ ajax.interceptors.response.use((response) => response, APIExceptionHandler);
// 书架API
// Http
/** @returns {Promise<import("axios").AxiosResponse<{isSuccess: boolean, data: string, errorMsg:string}>>} */
const getReadConfig = () => ajax.get("/getReadConfig", {timeout: 3000});
const getReadConfig = () => ajax.get("/getReadConfig", { timeout: 3000 });
const saveReadConfig = (config) => ajax.post("/saveReadConfig", config);

const saveBookProgress = (bookProgress) =>
Expand All @@ -70,7 +69,7 @@ const saveBookProgressWithBeacon = (bookProgress) => {
// 常规请求可能会被取消 使用Fetch keep-alive 或者 navigator.sendBeacon
navigator.sendBeacon(
`${legado_http_origin}/saveBookProgress`,
JSON.stringify(bookProgress)
JSON.stringify(bookProgress),
);
};

Expand All @@ -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);

Expand Down Expand Up @@ -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`;
Expand All @@ -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=" +
Expand All @@ -187,7 +184,7 @@ const getProxyImageUrl = (src, width) => {
"&width=" +
width
);
}
};

export default {
getReadConfig,
Expand Down
4 changes: 1 addition & 3 deletions modules/web/src/components/BookItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
Expand Down
8 changes: 6 additions & 2 deletions modules/web/src/components/ChapterContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ const props = defineProps({
const getImageSrc = (content) => {
const imgPattern = /<img[^>]*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) => {
Expand Down
6 changes: 1 addition & 5 deletions modules/web/src/components/PopCatalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -89,7 +86,6 @@ const gotoChapter = (note) => {
store.saveBookProgress();
emit("getContent", chapterIndex);
};
</script>

<style lang="scss" scoped>
Expand Down
97 changes: 44 additions & 53 deletions modules/web/src/components/ReadSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@
"
>确定</el-button
>
<el-button
type="primary"
size="small"
@click="loadFontFromURL"
<el-button type="primary" size="small" @click="loadFontFromURL"
>网络下载</el-button
>
</div>
Expand Down Expand Up @@ -196,14 +193,14 @@ watch(
API.saveReadConfig(newValue);
},
{
deep: 2 //深度为2
}
)
deep: 2, //深度为2
},
);
//主题颜色
const theme = computed(() => store.theme);
const isNight = computed(() => store.isNight);
const moonIcon = computed(() => theme.value == 6 ? "" : "");
const moonIcon = computed(() => (theme.value == 6 ? "" : ""));
const themeColors = [
{
background: "rgba(250, 245, 235, 0.8)",
Expand Down Expand Up @@ -234,7 +231,7 @@ const popupTheme = computed(() => {
});
const setTheme = (theme) => {
store.config.theme = theme;
}
};
//预置字体
const fonts = ref(["雅黑", "宋体", "楷书"]);
Expand All @@ -253,51 +250,45 @@ const setCustomFont = () => {
};
// 加载网络字体
const loadFontFromURL = () => {
ElMessageBox.prompt(
"请输入 字体网络链接",
"提示",
{
confirmButtonText: "确定",
cancelButtonText: "取消",
inputPattern: /^https?:.+$/,
inputErrorMessage: "url 形式不正确",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
instance.confirmButtonLoading = true;
instance.confirmButtonText = "下载中……";
// instance.inputValue
const url = instance.inputValue
if (typeof FontFace !== "function") {
ElMessage.error("浏览器不支持FontFace");
return done();
}
const fontface = new FontFace(
customFontName.value,
`url("${url}")`
)
//@ts-ignore
document.fonts.add(fontface);
fontface.load()
//API.getBookShelf()
.then(function () {
instance.confirmButtonLoading = false;
ElMessage.info("字体加载成功!");
setCustomFont();
done();
})
.catch(function (error) {
instance.confirmButtonLoading = false;
instance.confirmButtonText = "确定";
ElMessage.error("下载失败,请检查您输入的 url");
throw error;
});
} else {
done();
ElMessageBox.prompt("请输入 字体网络链接", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
inputPattern: /^https?:.+$/,
inputErrorMessage: "url 形式不正确",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
instance.confirmButtonLoading = true;
instance.confirmButtonText = "下载中……";
// instance.inputValue
const url = instance.inputValue;
if (typeof FontFace !== "function") {
ElMessage.error("浏览器不支持FontFace");
return done();
}
},
}
);
}
const fontface = new FontFace(customFontName.value, `url("${url}")`);
//@ts-ignore
document.fonts.add(fontface);
fontface
.load()
//API.getBookShelf()
.then(function () {
instance.confirmButtonLoading = false;
ElMessage.info("字体加载成功!");
setCustomFont();
done();
})
.catch(function (error) {
instance.confirmButtonLoading = false;
instance.confirmButtonText = "确定";
ElMessage.error("下载失败,请检查您输入的 url");
throw error;
});
} else {
done();
}
},
});
};
//字体大小
const fontSize = computed(() => {
Expand Down
4 changes: 2 additions & 2 deletions modules/web/src/components/SourceDebug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const startDebug = async () => {
try {
await API.saveSource(store.currentSource);
} catch (e) {
store.debugFinish()
throw e
store.debugFinish();
throw e;
}
API.debug(
store.currentSourceUrl,
Expand Down
8 changes: 4 additions & 4 deletions modules/web/src/components/SourceHelp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import { Link } from "@element-plus/icons-vue";
<el-link :icon="Link" href="/help/#httpTTSHelp" target="_blank"
>在线朗读规则</el-link
><br />
<el-link :icon="Link" href="/help/#webDavBookHelp" target="_blank"
> WebDav书籍简明使用教程</el-link
<el-link :icon="Link" href="/help/#webDavBookHelp" target="_blank">
WebDav书籍简明使用教程</el-link
><br />
<el-link :icon="Link" href="/help/#webDavHelp" target="_blank"
> WebDav备份教程</el-link
<el-link :icon="Link" href="/help/#webDavHelp" target="_blank">
WebDav备份教程</el-link
><br />
<el-link :icon="Link" href="https://regexr-cn.com/" target="_blank"
>正则表达式在线验证工具</el-link
Expand Down
2 changes: 1 addition & 1 deletion modules/web/src/components/SourceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import SourceItem from "./SourceItem.vue";
const store = useSourceStore();
const sourceUrlSelect = ref([]);
const searchKey = ref("");
const sources = computed(() => store.sources);
const sources = computed(() => store.sources);
// 筛选源
/** @type Ref<import('@/source').Source[]> */
Expand Down
Loading

0 comments on commit ad27bd8

Please sign in to comment.