From bb0e97c402526e1a1abd84728a3c417965bf8553 Mon Sep 17 00:00:00 2001 From: putyy Date: Mon, 18 Nov 2024 22:04:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- components.d.ts | 3 ++- electron/main/index.ts | 28 ++++++++++------------------ electron/main/ipc.ts | 32 ++++++++++++++++++-------------- electron/main/proxyServer.ts | 24 +++++++----------------- package.json | 2 +- src/App.vue | 1 + src/views/Index.vue | 36 ++++++++++++++---------------------- src/views/Setting.vue | 11 +++++------ 9 files changed, 59 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 4ca1bd7..137b991 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ yarn run build --universal --mac # 打包win yarn run build --win -# 打包win +# 打包linux yarn run build --linux ``` diff --git a/components.d.ts b/components.d.ts index a384f3b..f1b4c41 100755 --- a/components.d.ts +++ b/components.d.ts @@ -8,6 +8,8 @@ export {} declare module 'vue' { export interface GlobalComponents { ElButton: typeof import('element-plus/es')['ElButton'] + ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] + ElCheckboxGroup: typeof import('element-plus/es')['ElCheckboxGroup'] ElConfigProvider: typeof import('element-plus/es')['ElConfigProvider'] ElContainer: typeof import('element-plus/es')['ElContainer'] ElFooter: typeof import('element-plus/es')['ElFooter'] @@ -16,7 +18,6 @@ declare module 'vue' { ElHeader: typeof import('element-plus/es')['ElHeader'] ElIcon: typeof import('element-plus/es')['ElIcon'] ElInput: typeof import('element-plus/es')['ElInput'] - ElLink: typeof import('element-plus/es')['ElLink'] ElMain: typeof import('element-plus/es')['ElMain'] ElMenu: typeof import('element-plus/es')['ElMenu'] ElMenuItem: typeof import('element-plus/es')['ElMenuItem'] diff --git a/electron/main/index.ts b/electron/main/index.ts index 92a4cad..dd647a1 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -173,14 +173,11 @@ function createPreviewWindow(parent: BrowserWindow) { previewWin.setTitle("预览") previewWin.on("page-title-updated", (event) => { - // 阻止该事件 event.preventDefault() }) previewWin.on("close", (event) => { - // 不关闭窗口 event.preventDefault() - // 影藏窗口 previewWin.hide() }) } @@ -197,14 +194,12 @@ function createAria2Process() { aria2Path = path.join(CONFIG.EXECUTABLE_PATH, `./${process.platform}/aria2` + (CONFIG.IS_DEV ? `/${process.arch}` : '/') + "/aria2c"); aria2Conf = path.join(CONFIG.EXECUTABLE_PATH, `./${process.platform}/aria2/aria2.conf`) } - // 启动 aria2 - console.log("启动 aria2") aria2Process = spawn(aria2Path, [`--conf-path=${aria2Conf}`, `--rpc-listen-port=${CONFIG.ARIA_PORT}`], { windowsHide: false, stdio: CONFIG.IS_DEV ? 'pipe' : 'ignore' }); if(!aria2Process){ - console.log("启动 aria2 失败") + console.log("start aria2 error") } if (CONFIG.IS_DEV) { aria2Process.stdout.on('data', (data) => { @@ -214,7 +209,6 @@ function createAria2Process() { console.log(`aria2 error: ${data}`); }); } - console.log("aria2 成功启动") } catch (e) { console.log(`aria2 process start err`, e); } @@ -225,19 +219,17 @@ function initConfig(){ if (!fs.existsSync(configPath)) { return } - fs.readFile(configPath, (err, data) => { - if (!err) { - try { - const jsonData = JSON.parse(data) - console.log("jsonData:", jsonData) - global.resdConfig = Object.assign({}, global.resdConfig, jsonData) - if (!global.resdConfig.proxy) { - global.resdConfig.proxy = "8899" - } - } catch (parseErr) { + const buff = fs.readFileSync(configPath); + if (buff) { + try { + const jsonData = JSON.parse(buff) + global.resdConfig = Object.assign({}, global.resdConfig, jsonData) + if (!global.resdConfig.port) { + global.resdConfig.port = 8899 } + } catch (parseErr) { } - }); + } } app.whenReady().then(() => { diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts index 2b9dfe9..4927e23 100755 --- a/electron/main/ipc.ts +++ b/electron/main/ipc.ts @@ -7,7 +7,7 @@ import {hexMD5} from '../../src/common/md5' import {Aria2RPC} from './aria2Rpc' import fs from "fs" import urlTool from "url"; -import {setProxy} from "./setProxy"; +import {closeProxy, setProxy} from "./setProxy"; import path from 'path' let win: BrowserWindow @@ -44,7 +44,11 @@ export default function initIPC() { return false } try { - await setProxy('127.0.0.1', global.resdConfig.proxy) + if (arg.proxy) { + await setProxy('127.0.0.1', global.resdConfig.port) + }else{ + await closeProxy('127.0.0.1', global.resdConfig.port) + } return true } catch (err) { console.error(err); @@ -132,18 +136,18 @@ export default function initIPC() { return new Promise((resolve, reject) => { - if (down_url.includes("douyin")) { - headers['Referer'] = down_url + if (data?.referer) { + headers['Referer'] = data?.referer } aria2RpcClient.addUri([down_url], save_path, fileName, headers).then((response) => { - let currentGid = response.result // 保存当前下载的 gid + let currentGid = response.result let progressIntervalId = null // // 开始定时查询下载进度 progressIntervalId = setInterval(() => { aria2RpcClient.tellStatus(currentGid).then((status) => { if (status.result.status !== "complete") { - const progress = aria2RpcClient.calculateDownloadProgress(status.result.bitfield); + const progress = aria2RpcClient.calculateDownloadProgress(status.result.bitfield) win?.webContents.send('on_down_file_schedule', {schedule: `已下载${progress}%`}) } else { clearInterval(progressIntervalId); @@ -152,26 +156,26 @@ export default function initIPC() { decodeWxFile(save_path_file, data.decode_key, save_path_file.replace(".mp4", "_wx.mp4")).then((res) => { fs.unlink(save_path_file, (err) => { }) - resolve(res); + resolve(res) }).catch((error) => { console.log("err:", error) resolve(false); - }); + }) } else { resolve({ fullFileName: save_path_file, - }); + }) } } }).catch((error) => { - console.error(error); - clearInterval(progressIntervalId); - resolve(false); + console.error(error) + clearInterval(progressIntervalId) + resolve(false) }); - }, 1000); + }, 1000) }).catch((error) => { console.log("err:", error) - resolve(false); + resolve(false) }); }); }); diff --git a/electron/main/proxyServer.ts b/electron/main/proxyServer.ts index 2984460..4a120cb 100755 --- a/electron/main/proxyServer.ts +++ b/electron/main/proxyServer.ts @@ -6,7 +6,6 @@ import {toSize, typeSuffix} from "./utils" // @ts-ignore import {hexMD5} from '../../src/common/md5' import pkg from '../../package.json' -import {dialog} from "electron"; const hoXy = require('hoxy') @@ -18,6 +17,7 @@ if (process.platform === 'win32') { const resObject = { url: "", url_sign: "", + referer: "", cover_url: "", file_format: "", platform: "", @@ -38,6 +38,7 @@ export function startServer(win) { if (global.resdConfig.proxy && !global.resdConfig.proxy.includes(':' + global.resdConfig.port)) { upstreamProxy = global.resdConfig?.proxy } + console.log("global.resdConfig.port:", global.resdConfig.port) const proxy = hoXy.createServer({ upstreamProxy: upstreamProxy, certAuthority: { @@ -47,27 +48,13 @@ export function startServer(win) { }) .listen(global.resdConfig.port, () => { global.isStartProxy = true - // try { - // await setProxy('127.0.0.1', port) - // resolve() - // } catch (err) { - // console.error(err); - // setProxyErrorCallback(err) - // reject("请手动设置系统代理" + err.toString()) - // } }) .on('error', err => { - console.error(err); - dialog.showMessageBoxSync({ - type: 'error', - message: err.toString(), - }); - // setProxyErrorCallback(err) - // reject('proxy service err: ' + err.toString()) + console.error("hoXy err:", err); }) intercept(proxy, win) } catch (e) { - log.log("--------------proxy catch err--------------", e) + console.error("--------------proxy catch err--------------"); } } @@ -96,6 +83,7 @@ function intercept(proxy, win) { url_sign: url_sign, url: media.url + media.urlToken, cover_url: media.coverUrl, + referer: "", file_format: media.spec.map((res) => res.fileFormat).join('#'), platform: urlInfo.hostname, size: toSize(media.fileSize), @@ -165,9 +153,11 @@ function intercept(proxy, win) { const contentLength = res?._data?.headers?.['content-length'] if (global.videoList.hasOwnProperty(url_sign) === false) { global.videoList[url_sign] = res_url + let referer = req?._data?.headers?.['referer'] win.webContents.send('on_get_queue', Object.assign({}, resObject, { url: res_url, url_sign: url_sign, + referer: referer ? referer : "", platform: urlInfo.hostname, size: toSize(contentLength ? contentLength : 0), type: contentType, diff --git a/package.json b/package.json index 0d402ed..407a670 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "res-downloader", - "version": "2.1.3", + "version": "2.2.0", "main": "dist-electron/main/index.js", "description": "res-downloader(爱享素材下载器),支持视频号、小程序、抖音、快手、小红书、酷狗音乐、qq音乐、qq短视频等", "homepage": "https://github.com/putyy/res-downloader", diff --git a/src/App.vue b/src/App.vue index 8019bc6..d10c89c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,4 +1,5 @@ diff --git a/src/views/Index.vue b/src/views/Index.vue index 0c231ca..76f820f 100755 --- a/src/views/Index.vue +++ b/src/views/Index.vue @@ -8,6 +8,8 @@ import {Delete, Filter, Promotion} from "@element-plus/icons-vue" interface resData { url: string, url_sign: string, + referer: string, + cover_url: string, size: any, platform: string, type: string, @@ -31,19 +33,21 @@ const tableData = ref([]) const filteredData = computed(() => { if (filtersAction.value.descValue && filtersAction.value.typeValue.length === 0) { - return tableData.value.filter(item => { + return tableData.value.filter((item: resData) => { return item.description.includes(filtersAction.value.descValue) }); } if (!filtersAction.value.descValue && filtersAction.value.typeValue.length > 0) { - return tableData.value.filter(item => { + return tableData.value.filter((item: resData) => { + // @ts-ignore return filtersAction.value.typeValue.includes(item.type_str) }); } if (filtersAction.value.descValue && filtersAction.value.typeValue.length > 0) { - return tableData.value.filter(item => { + return tableData.value.filter((item: resData) => { + // @ts-ignore return item.description.includes(filtersAction.value.descValue) && filtersAction.value.typeValue.includes(item.type_str) }); } @@ -107,7 +111,7 @@ onMounted(() => { ipcRenderer.on('on_get_queue', (res, data) => { // @ts-ignore - if (resType.value.includes("all") || resType.value.includes(data.type_str)) { + if (isSetProxy.value && resType.value.includes("all") || resType.value.includes(data.type_str)) { tableData.value.push(data) localStorageCache.set("res-table-data", tableData.value, -1) } @@ -204,8 +208,7 @@ const handleBatchDown = async () => { multipleTableRef.value!.clearSelection() } - -const handleDown = async (index: number, row: any) => { +const handleDown = (index: number, row: any) => { const config = resdConfig() const save_dir = config?.save_dir if (!save_dir) { @@ -338,7 +341,7 @@ const handleInitApp = () => { const setProxy = ()=>{ isSetProxy.value = !isSetProxy.value ipcRenderer.invoke('invoke_set_proxy', {proxy: isSetProxy.value}).then((res) => { - if (res) { + if (!res) { ElMessage({ type: "warning", message: "设置系统代理失败", @@ -410,7 +413,7 @@ el-container.container el-button(size="small" @click="filtersAction.descVisible = false") 关闭 el-button(size="small" type="primary" @click="handleFilter('desc')") 筛选 template(#reference) - el-icon(@click="filtersAction.descVisible = true") + el-icon(@click="filtersAction.descVisible = true" :color="filtersAction.typeValue.length > 0 ? '#409eff' : ''") Filter template(#default="scope") div.show_res @@ -426,24 +429,13 @@ el-container.container span(:style="filtersAction.typeValue.length > 0 ? 'color: #409eff' : ''") 类型 el-popover(:visible="filtersAction.typeVisible") div - el-select( - v-model="filtersAction.typeInput" - multiple - collapse-tags - collapse-tags-tooltip - :max-collapse-tags="3" - placeholder="资源拦截类型" - style="width: auto;min-width:130px" - ) - el-option(v-for="item in typeFilters" - :key="item.value" - :label="item.label" - :value="item.value") + el-checkbox-group(v-model="filtersAction.typeInput" style="display:flex;flex-direction: column;") + el-checkbox(v-for="item in typeFilters" :label="item.label" :value="item.value") div(style="margin-top:10px;display:flex;justify-content: center;") el-button(size="small" @click="filtersAction.typeVisible = false") 关闭 el-button(size="small" type="primary" @click="handleFilter('type')") 筛选 template(#reference) - el-icon(@click="filtersAction.typeVisible = true") + el-icon(@click="filtersAction.typeVisible = true" :color="filtersAction.typeValue.length > 0 ? '#409eff' : ''") Filter el-table-column(prop="platform" label="主机地址") el-table-column(prop="size" label="资源大小") diff --git a/src/views/Setting.vue b/src/views/Setting.vue index 0ee69f5..55aa855 100755 --- a/src/views/Setting.vue +++ b/src/views/Setting.vue @@ -13,10 +13,6 @@ const formData = ref({ const proxy_old = ref("") const port_old = ref("") -const saveDir = ref("") -const upstream_proxy = ref("") -const upstream_proxy_old = ref("") -const quality = ref("-1") const qualityOptions = ref([ { value: '-1', @@ -44,6 +40,7 @@ onMounted(() => { const selectSaveDir = () => { ipcRenderer.invoke('invoke_select_down_dir').then(save_dir => { + console.log("save_dir", save_dir) if (save_dir !== false) { formData.value.save_dir = save_dir } @@ -67,9 +64,11 @@ const onSetting = () => {