Skip to content

Commit

Permalink
Support AList
Browse files Browse the repository at this point in the history
  • Loading branch information
gavingaozhangmin committed Aug 25, 2023
1 parent 357945c commit 8b27124
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 123 deletions.
74 changes: 45 additions & 29 deletions electron/main/core/ipcEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand All @@ -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
})
}

Expand Down
3 changes: 0 additions & 3 deletions src/layout/PageMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -197,7 +196,6 @@ const handleCheckVer = () => {
<a-menu-item key="share" title="Alt+5">资源&分享</a-menu-item>
<a-menu-item key="rss" title="Alt+6">插件</a-menu-item>
<a-menu-item key="movie" title="Alt+7">4K影视</a-menu-item>
<a-menu-item key="alist" title="Alt+7">AList</a-menu-item>
</a-menu>

<div class="flexauto"></div>
Expand Down Expand Up @@ -230,7 +228,6 @@ const handleCheckVer = () => {
<a-tab-pane key="setting" title="7"><Setting /></a-tab-pane>
<a-tab-pane v-if='appStore.isVip' key="movie" title="8"><Movie /></a-tab-pane>
<a-tab-pane v-if='!appStore.isVip' key="movie" title="8"><VipInformPage /></a-tab-pane>
<a-tab-pane key="alist" title="9"><Alist /></a-tab-pane>
</a-tabs>
</a-layout-content>
<a-layout-footer id="xbyfoot" draggable="false">
Expand Down
85 changes: 39 additions & 46 deletions src/resource/alist.vue
Original file line number Diff line number Diff line change
@@ -1,68 +1,61 @@
<template>
<div>
<iframe class="custom-webview" src="http://127.0.0.1:5244" ref="iframeRef"></iframe>
<iframe class="custom-webview" :src="iframeSrc" ref="iframeRef"></iframe>
</div>
</template>

<script lang="ts">
import { ref, onMounted } from 'vue';
import { modalDaoRuShareLink } from '../utils/modal';
import { IAliGetFileModel } from '../aliapi/alimodels'
import { useSettingStore, useUserStore } from '../store'
import path from 'path'
import { humanSize } from '../utils/format'
import UserDAL from '../user/userdal'
import DownDAL from '../down/DownDAL'
import useSettingStore from '../setting/settingstore'
export default {
setup: function() {
const iframeRef = ref(null)
setup() {
const iframeRef = ref(null);
const iframeSrc = ref(''); // 初始的 iframe URL
onMounted(() => {
// const iframe = iframeRef.value
setTimeout(() => {
iframeSrc.value = 'http://127.0.0.1:5244/';
}, 5000);
const iframe = iframeRef.value;
if (iframe) {
const intervalId = setInterval(() => {
// @ts-ignore
iframe.addEventListener('load', () => {
// @ts-ignore
const iframeDocument = iframe.contentDocument || iframe.contentWindow.document
const usernameInput = iframeDocument.querySelector('input[name="username"]');
const passwordInput = iframeDocument.querySelector('input[name="password"]');
const loginButton = iframeDocument.querySelector('.login-button');
// if (iframe) {
// // @ts-ignore
// iframe.addEventListener('load', () => {
// // @ts-ignore
// const iframeDocument = iframe.contentDocument || iframe.contentWindow.document
//
// const element = iframeDocument.querySelector('.swal2-close')
// if (element) {
// element.click()
// }
// const iframeElements = iframeDocument.querySelectorAll('iframe[src^="https://player.bilibili.com/"]')
// // @ts-ignore
// iframeElements.forEach((iframeElement) => {
// if (iframeElement) {
// iframeElement.remove()
// }
// })
//
// iframeDocument.addEventListener('click', (event: any) => {
// const target = event.target
// const url = target.href || ''
//
// if (url.includes('aliyundrive')) {
// event.preventDefault()
// modalDaoRuShareLink(url)
// }
// })
// })
// }
if (usernameInput && passwordInput && loginButton && useSettingStore().alistPwd != '') {
// @ts-ignore
usernameInput.value = 'admin';
// @ts-ignore
passwordInput.value = useSettingStore().alistPwd
// @ts-ignore
loginButton.click();
clearInterval(intervalId)
}
});
}, 1000)
}
})
return {
iframeRef
}
iframeRef,
iframeSrc
};
}
}
};
</script>

<style scoped>
.custom-webview {
width: 100%;
height: 1000px;
width: 100%;
height: 1000px;
}
</style>
31 changes: 0 additions & 31 deletions src/resource/movieIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/setting/SettingAria.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -88,6 +89,13 @@ const handleAriaOff = (tip: boolean) => {
message.error('已经从远程断开,连接到本地Aria失败')
})
}
const handleResetAListPwd = () => {
if (window.WebResetAlistPwd) {
window.WebResetAlistPwd({ cmd: alistPwd.value })
message.info("重置成功")
}
}
</script>

<template>
Expand Down Expand Up @@ -173,6 +181,12 @@ const handleAriaOff = (tip: boolean) => {
<div class="settingrow" v-show="!settingStore.AriaIsLocal">
<a-button type="primary" size="small" tabindex="-1" :loading="settingStore.ariaLoading" @click="handleAriaOff(false)">当前是 远程Aria模式,点击切换</a-button>
</div>
<div class="settingspace"></div>
<div class="settinghead">重置AList登录密码</div>
<div class="settingrow">
<a-input tabindex="-1" :style="{ width: '100px' }" placeholder="AList登录密码" v-model:model-value="alistPwd" />
<a-button type="primary" size="small" tabindex="-1" @click="handleResetAListPwd()">重置AList登录密码</a-button>
</div>
</div>
</template>

Expand Down
4 changes: 4 additions & 0 deletions src/setting/settingstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export interface SettingState {

ariaPwd: string

alistPwd: string

ariaHttps: boolean

ariaState: string
Expand Down Expand Up @@ -217,6 +219,7 @@ const setting: SettingState = {
ariaSavePath: '',
ariaUrl: '',
ariaPwd: '',
alistPwd: '',
ariaHttps: false,
ariaState: 'local',
ariaLoading: false,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/share/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -59,6 +60,10 @@ appStore.$subscribe(async (mutation) => {
<template #icon><i class="iconfont iconrvip" /></template>
全网资源搜索
</a-menu-item>
<a-menu-item key="alist">
<template #icon><i class="iconfont iconrvip" /></template>
AList 挂载
</a-menu-item>
</a-menu>
</a-layout-sider>
<a-layout-content class="xbyright">
Expand All @@ -70,6 +75,7 @@ appStore.$subscribe(async (mutation) => {
<a-tab-pane key="OtherFollowingRight" title="6"><OtherFollowingRight /></a-tab-pane>
<a-tab-pane v-if='vipIdentity' key="ShareSiteRight" title="5"><SearchRes /></a-tab-pane>
<a-tab-pane v-if='!vipIdentity' key="ShareSiteRight" title="5"><VipInformPage /></a-tab-pane>
<a-tab-pane key="alist" title="6"><AList /></a-tab-pane>
</a-tabs>
</a-layout-content>
</a-layout>
Expand Down
Loading

0 comments on commit 8b27124

Please sign in to comment.