From 8b27124961e6150963451d723a5001c1c196c417 Mon Sep 17 00:00:00 2001 From: gavingaozhangmin Date: Fri, 25 Aug 2023 17:37:48 +0800 Subject: [PATCH] Support AList --- electron/main/core/ipcEvent.ts | 74 +++++++++++++++++------------ src/layout/PageMain.vue | 3 -- src/resource/alist.vue | 85 ++++++++++++++++------------------ src/resource/movieIndex.vue | 31 ------------- src/setting/SettingAria.vue | 14 ++++++ src/setting/settingstore.ts | 4 ++ src/share/index.vue | 6 +++ src/store/appstore.ts | 16 ++----- src/utils/aria2c.ts | 2 +- 9 files changed, 112 insertions(+), 123 deletions(-) diff --git a/electron/main/core/ipcEvent.ts b/electron/main/core/ipcEvent.ts index d7886b6..b588c0b 100644 --- a/electron/main/core/ipcEvent.ts +++ b/electron/main/core/ipcEvent.ts @@ -3,7 +3,7 @@ import path from 'path' import is from 'electron-is' import { app, BrowserWindow, dialog, ipcMain, session, shell } from 'electron' import { existsSync, writeFileSync } from 'fs' -import { exec, spawn, SpawnOptions } from 'child_process' +import { exec, execFile, spawn, SpawnOptions } from 'child_process' import { ShowError } from './dialog' // @ts-ignore import {getResourcesPath, getStaticPath, getUserDataPath} from '../utils/mainfile' @@ -317,22 +317,29 @@ export default class ipcEvent { const alistPath = is.windows() ? 'alist.exe' : 'alist' const basePath: string = path.join(enginePath, is.dev() ? path.join(process.platform, process.arch) : '') const alistFilePath: string = path.join(basePath, alistPath) + const alistDataPath = getUserDataPath('alist-data') if (!existsSync(alistFilePath)) { ShowError('找不到alist程序文件', alistFilePath) return 0 } const argsToStr = (args: any) => is.windows() ? `"${args}"` : `'${args}'` - const options: SpawnOptions = { + + const alistArgs = [ + 'server', + '--data ' + `${argsToStr(alistDataPath)}` + ] + const options = { shell: true, - stdio: is.dev() ? 'pipe' : 'ignore', - windowsHide: false, windowsVerbatimArguments: true } - const alistArgs = [ - `--stop-with-process=${argsToStr(process.pid)}`, - '-D' - ] - spawn(`${argsToStr(alistFilePath + ' start')}`, alistArgs, options) + console.log(`${argsToStr(alistFilePath + ' server')}`) + execFile(`${argsToStr(alistFilePath)}`, alistArgs, options, + async (error, stdout, stderr) => { + if (error) { + console.log(`启动AList失败 : ${error}`) + return 0 + } + }) return 0 } catch (e: any) { console.log(e) @@ -344,30 +351,39 @@ export default class ipcEvent { private static handleWebResetAlistPwd() { ipcMain.handle('WebResetAlistPwd', async (event, data) => { try { - if (data.cmd ) { - const password = data.cmd.password - const enginePath: string = getStaticPath('engine') - const alistPath = is.windows() ? 'alist.exe' : 'alist' - const basePath: string = path.join(enginePath, is.dev() ? path.join(process.platform, process.arch) : '') - const alistFilePath: string = path.join(basePath, alistPath) - if (!existsSync(alistFilePath)) { - ShowError('找不到alist程序文件', alistFilePath) - return 0 - } - const argsToStr = (args: any) => is.windows() ? `"${args}"` : `'${args}'` - const options: SpawnOptions = { - shell: true, - stdio: is.dev() ? 'pipe' : 'ignore', - windowsHide: false, - windowsVerbatimArguments: true - } - spawn(`${argsToStr(alistFilePath + ' admin set '+password)}`, options) + const enginePath: string = getStaticPath('engine') + const alistPath = is.windows() ? 'alist.exe' : 'alist' + const basePath: string = path.join(enginePath, is.dev() ? path.join(process.platform, process.arch) : '') + const alistFilePath: string = path.join(basePath, alistPath) + const alistDataPath = getUserDataPath('alist-data') + if (!existsSync(alistFilePath)) { + ShowError('找不到alist程序文件', alistFilePath) + return 0 } - return 0 + + const argsToStr = (args: any) => is.windows() ? `"${args}"` : `'${args}'` + const password = data.cmd + + const alistArgs = [ + 'admin set ' + `${argsToStr(password)}`, + '--data ' + `${argsToStr(alistDataPath)}` + ] + console.log(`修改AList密码 : `, password) + const options = { + shell: true, + windowsVerbatimArguments: true + } + execFile(`${argsToStr(alistFilePath)}`, alistArgs, options, + async (error, stdout, stderr) => { + if (error) { + console.log(`修改AList密码失败 : ${error}`) + } else { + console.log(`修改AList密码成功 : ${stdout}`) + } + }) } catch (e: any) { console.log(e) } - return 0 }) } diff --git a/src/layout/PageMain.vue b/src/layout/PageMain.vue index 16c31d3..33304bc 100644 --- a/src/layout/PageMain.vue +++ b/src/layout/PageMain.vue @@ -24,7 +24,6 @@ import Pan from '../pan/index.vue' import ResourcePan from '../resPan/index.vue' import Pic from '../pic/index.vue' import Movie from '../resource/movieIndex.vue' -import Alist from '../resource/alist.vue' import VipInformPage from '../resource/vipInfo.vue' import UserInfo from '../user/UserInfo.vue' import UserLogin from '../user/UserLogin.vue' @@ -197,7 +196,6 @@ const handleCheckVer = () => { 资源&分享 插件 4K影视 - AList
@@ -230,7 +228,6 @@ const handleCheckVer = () => { - diff --git a/src/resource/alist.vue b/src/resource/alist.vue index 69d87a4..f751de4 100644 --- a/src/resource/alist.vue +++ b/src/resource/alist.vue @@ -1,68 +1,61 @@ diff --git a/src/resource/movieIndex.vue b/src/resource/movieIndex.vue index 039b1f7..afc4a7a 100644 --- a/src/resource/movieIndex.vue +++ b/src/resource/movieIndex.vue @@ -18,37 +18,6 @@ import DownDAL from '../down/DownDAL' export default { setup: function() { const iframeRef = ref(null) - - - // const handleDownload = async (url: string, filmname:string) => { - // const user = UserDAL.GetUserToken(useUserStore().user_id) - // const settingStore = useSettingStore() - // const savePath = settingStore.AriaIsLocal ? settingStore.downSavePath : settingStore.ariaSavePath - // const fullSavePath = path.join(savePath, filmname) - // const fileList: IAliGetFileModel[] = [] - // fileList.push({ - // __v_skip: true, - // drive_id: UserDAL.GetUserToken(useUserStore().user_id).default_drive_id, - // file_id: '1234567', - // parent_file_id: '', - // name: filmname, - // namesearch: '', - // ext: 'ts', - // category: 'video', - // icon: '', - // size: 52.13*1024*1024*1024, - // sizeStr: '52.13G', - // time: 0, - // timeStr: '', - // starred: false, - // isDir: false, - // thumbnail: '', - // description: '', - // download_url: url, - // }) - // DownDAL.aAddDownload(fileList, fullSavePath, false) - // } - onMounted(() => { const iframe = iframeRef.value diff --git a/src/setting/SettingAria.vue b/src/setting/SettingAria.vue index ebb74ba..9af32d7 100644 --- a/src/setting/SettingAria.vue +++ b/src/setting/SettingAria.vue @@ -16,6 +16,7 @@ const ariaLoading = ref(settingStore.ariaLoading) const ariaSavePath = ref(settingStore.ariaSavePath) const ariaUrl = ref(settingStore.ariaUrl) const ariaPwd = ref(settingStore.ariaPwd) +const alistPwd = ref(settingStore.alistPwd) const handleAriaConn = () => { ariaSavePath.value = ariaSavePath.value.trim() @@ -88,6 +89,13 @@ const handleAriaOff = (tip: boolean) => { message.error('已经从远程断开,连接到本地Aria失败') }) } + +const handleResetAListPwd = () => { + if (window.WebResetAlistPwd) { + window.WebResetAlistPwd({ cmd: alistPwd.value }) + message.info("重置成功") + } +} diff --git a/src/setting/settingstore.ts b/src/setting/settingstore.ts index 66cdd99..7ef933f 100644 --- a/src/setting/settingstore.ts +++ b/src/setting/settingstore.ts @@ -109,6 +109,8 @@ export interface SettingState { ariaPwd: string + alistPwd: string + ariaHttps: boolean ariaState: string @@ -217,6 +219,7 @@ const setting: SettingState = { ariaSavePath: '', ariaUrl: '', ariaPwd: '', + alistPwd: '', ariaHttps: false, ariaState: 'local', ariaLoading: false, @@ -303,6 +306,7 @@ function _loadSetting(val: any) { setting.ariaUrl = defaultString(val.ariaUrl, '') if (setting.ariaUrl.indexOf(':') < 0) setting.ariaUrl = '' setting.ariaPwd = defaultString(val.ariaPwd, '') + setting.alistPwd = defaultString(val.alistPwd, '') setting.ariaHttps = defaultBool(val.ariaHttps, false) setting.ariaState = defaultValue(val.ariaState, ['local', 'remote']) setting.ariaLoading = false diff --git a/src/share/index.vue b/src/share/index.vue index 0363033..c5af519 100644 --- a/src/share/index.vue +++ b/src/share/index.vue @@ -6,6 +6,7 @@ import MyTransferShareRight from './share/MyTransferShareRight.vue' import OtherShareRight from './share/OtherShareRight.vue' import MyFollowingRight from './following/MyFollowingRight.vue' import OtherFollowingRight from './following/OtherFollowingRight.vue' +import AList from '../resource/alist.vue' import { useAppStore, useUserStore } from '../store' import ShareDAL from './share/ShareDAL' @@ -59,6 +60,10 @@ appStore.$subscribe(async (mutation) => { 全网资源搜索 + + + AList 挂载 + @@ -70,6 +75,7 @@ appStore.$subscribe(async (mutation) => { + diff --git a/src/store/appstore.ts b/src/store/appstore.ts index 19ebd3a..26a1f5d 100644 --- a/src/store/appstore.ts +++ b/src/store/appstore.ts @@ -86,8 +86,7 @@ const useAppStore = defineStore('app', { ['share', 'OtherShareRight'], ['rss', 'AppSame'], ['setting', ''], - ['movie', ''], - ['alist', ''] + ['movie', ''] ]), appDark: false, appShutDown: false @@ -139,8 +138,7 @@ const useAppStore = defineStore('app', { ['share', 'OtherShareRight'], ['rss', 'AppSame'], ['setting', ''], - ['movie', ''], - ['alist', ''] + ['movie', ''] ]) }) }, @@ -213,10 +211,6 @@ const useAppStore = defineStore('app', { this.appTab = 'movie' break } - case 'alist': { - this.appTab = 'alist' - break - } } onHideRightMenu() }, @@ -251,7 +245,7 @@ const useAppStore = defineStore('app', { break } case 'share': { - next(this.appTabMenuMap, this.appTab, ['OtherShareRight', 'MyShareRight', 'MyFollowingRight', 'OtherFollowingRight', 'ShareSiteRight']) + next(this.appTabMenuMap, this.appTab, ['OtherShareRight', 'MyShareRight', 'MyFollowingRight', 'OtherFollowingRight', 'ShareSiteRight', 'alist']) break } case 'rss': { @@ -268,10 +262,6 @@ const useAppStore = defineStore('app', { next(this.appTabMenuMap, this.appTab, ['movie', '']) break } - case 'alist': { - next(this.appTabMenuMap, this.appTab, ['alist', '']) - break - } } onHideRightMenu() diff --git a/src/utils/aria2c.ts b/src/utils/aria2c.ts index 54b91e3..9442cc6 100644 --- a/src/utils/aria2c.ts +++ b/src/utils/aria2c.ts @@ -165,7 +165,7 @@ export async function AriaChangeToLocal() { let port = 16800 if (Aria2EngineLocal == undefined) { port = window.WebRelaunchAria ? await window.WebRelaunchAria() : 16800 - await window.WebRelaunchAlist + const portAlist = window.WebRelaunchAlist ? await window.WebRelaunchAlist() : 5244 const options = { host: '127.0.0.1', port, secure: false, secret: localPwd, path: '/jsonrpc' } Aria2EngineLocal = new Aria2({ WebSocket: global.WebSocket, fetch: window.fetch.bind(window), ...options }) Aria2EngineLocal.on('close', () => {