From 0a8466d3f5a2bd1175f6fbb87015905d930a5ff3 Mon Sep 17 00:00:00 2001 From: Nier Date: Sun, 12 Mar 2023 12:53:06 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96ui=E6=98=BE=E7=A4=BA=202.?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=BB=84=E4=BB=B6=E4=B8=BA=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E5=8C=96=E7=BB=84=E4=BB=B6=203.B=E7=AB=99?= =?UTF-8?q?=E7=83=AD=E7=82=B9=E6=96=B0=E5=A2=9E=E5=9B=BE=E7=89=87=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 44 +++------- src/App.vue | 27 +++--- src/components/BiliBiliHot.vue | 25 ++++-- src/components/CommonNews.vue | 43 ++++++---- .../OpenSourceSoftwareUpdateNews.vue | 11 ++- src/components/ReadHub.vue | 76 +++++++---------- src/components/WeiboHot.vue | 82 ++++++------------- src/main.js | 2 + 8 files changed, 134 insertions(+), 176 deletions(-) diff --git a/public/preload.js b/public/preload.js index 468cc73..0f5082d 100644 --- a/public/preload.js +++ b/public/preload.js @@ -1,4 +1,8 @@ const https = require("https"); +const http = require("http"); +const crypto = require("crypto"); +const fs = require("fs"); +const urlParser = require('url'); /** * 全局函数(preload种可以调用electron/node函数) @@ -24,21 +28,6 @@ window.fetchJsonHttps = (host, path, config = {}) => new Promise((resolve) => { } ) - -const fetchHost = (url) => { - // 默认组装Referer header头 - let domainType = ".cn" - if (url.indexOf(".com") > -1) { - domainType = ".com" - } - - const [host, path] = url.split(domainType) - return { - host: `${host}${domainType}` - , path - } -} - function fetchSuffix(url) { const urlSegments = url.split(".") let fileSuffix = urlSegments[urlSegments.length - 1] @@ -50,15 +39,11 @@ function fetchSuffix(url) { } const fetchFile = (url, filePath, config) => { - const {host, path} = fetchHost(url) + const {host, path} = urlParser.parse(url) const request = url.startsWith('https') ? https : http return new Promise(resolve => request.get({ - host: - - `${host.replace('https://', '').replace('http://', '')}` - - , + host: `${host.replace('https://', '').replace('http://', '')}`, path: path, method: 'get', headers: config['headers'] || {} @@ -86,23 +71,16 @@ const getFileSize = (filePath) => { window.composeFilePath = (url) => { // 文件名采用随机方式,避免文件冲突 - let fileName = - - `${crypto.createHash('md5').update(url).digest('hex')}` - + let fileName = `${crypto.createHash('md5').update(url).digest('hex')}` let fileSuffix = fetchSuffix(url) // 组装文件路径,需要将文件后缀拼接上 - return - - `${utools.getPath("temp")}/${fileName}.${fileSuffix}` - - + return `${utools.getPath("temp")}/${fileName}.${fileSuffix}` } window.downloadImage = async (url, config = {}) => { // 默认组装Referer header头 - const {host} = fetchHost(url) + const {host} = urlParser.parse(url) config = Object.assign({'headers': {'Referer': host}, ...config}) // 组装文件路径,需要将文件后缀拼接上 @@ -124,8 +102,6 @@ window.downloadImage = async (url, config = {}) => { return { imgSrc: url, - fileSrc: - - `file://${filePath}`, + fileSrc: `file://${filePath}`, } } diff --git a/src/App.vue b/src/App.vue index f64518a..990ecdd 100644 --- a/src/App.vue +++ b/src/App.vue @@ -28,15 +28,12 @@ export default { updateConfig(config.value) } - const triggerUpdate = () => emitter.emit(REFRESH_EVENT) - - return { loading, config, sources, switchSource, - triggerUpdate, + triggerUpdate: () => emitter.emit(REFRESH_EVENT), RefreshSharp, InfoOutlined, theme: computed(() => osThemeRef.value === "dark" ? darkTheme : null), } @@ -48,14 +45,17 @@ export default { - - - - {{ source['title'] }} - + + + + - + @@ -67,14 +67,15 @@ export default { - + - + diff --git a/src/components/BiliBiliHot.vue b/src/components/BiliBiliHot.vue index d1f9692..d621c3d 100644 --- a/src/components/BiliBiliHot.vue +++ b/src/components/BiliBiliHot.vue @@ -1,5 +1,14 @@