Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
putyy committed Nov 18, 2024
1 parent edd0978 commit bb0e97c
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ yarn run build --universal --mac
# 打包win
yarn run build --win

# 打包win
# 打包linux
yarn run build --linux
```

Expand Down
3 changes: 2 additions & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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']
Expand Down
28 changes: 10 additions & 18 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
Expand All @@ -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) => {
Expand All @@ -214,7 +209,6 @@ function createAria2Process() {
console.log(`aria2 error: ${data}`);
});
}
console.log("aria2 成功启动")
} catch (e) {
console.log(`aria2 process start err`, e);
}
Expand All @@ -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(() => {
Expand Down
32 changes: 18 additions & 14 deletions electron/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
});
});
});
Expand Down
24 changes: 7 additions & 17 deletions electron/main/proxyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -18,6 +17,7 @@ if (process.platform === 'win32') {
const resObject = {
url: "",
url_sign: "",
referer: "",
cover_url: "",
file_format: "",
platform: "",
Expand All @@ -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: {
Expand All @@ -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--------------");
}
}

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
// @ts-ignore
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
</script>

Expand Down
36 changes: 14 additions & 22 deletions src/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,19 +33,21 @@ const tableData = ref<resData[]>([])
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)
});
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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: "设置系统代理失败",
Expand Down Expand Up @@ -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
Expand All @@ -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="资源大小")
Expand Down
11 changes: 5 additions & 6 deletions src/views/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
}
Expand All @@ -67,9 +64,11 @@ const onSetting = () => {
<template lang="pug">
el-form(style="max-width: 600px")
el-form-item(label="代理端口")
el-input(v-model="formData.proxy" placeholder="默认: 8899" )
el-input(v-model="formData.port" placeholder="默认: 8899" )
el-form-item(label="保存位置")
el-link(@click="selectSaveDir") {{saveDir ? saveDir : '选择'}}
div(style="display:flex;flex-direction: row;align-items: center;")
el-input(v-model="formData.save_dir" placeholder="请选择" disabled )
el-button(style="margin-left: 10px;" type="primary" @click="selectSaveDir") 选择
el-form-item(label="视频号画质")
el-select(v-model="formData.quality" placeholder="请选择")
el-option( v-for="item in qualityOptions"
Expand Down

0 comments on commit bb0e97c

Please sign in to comment.