mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
control the sub-store proxy and catch logs
This commit is contained in:
parent
955b3fe666
commit
f85e1ecd55
@ -1,7 +1,8 @@
|
|||||||
import { getAppConfig, getControledMihomoConfig } from '../config'
|
import { getAppConfig, getControledMihomoConfig } from '../config'
|
||||||
import { Worker } from 'worker_threads'
|
import { Worker } from 'worker_threads'
|
||||||
import { mihomoWorkDir, resourcesFilesDir, subStoreDir } from '../utils/dirs'
|
import { mihomoWorkDir, resourcesFilesDir, subStoreDir, substoreLogPath } from '../utils/dirs'
|
||||||
import subStoreIcon from '../../../resources/subStoreIcon.png?asset'
|
import subStoreIcon from '../../../resources/subStoreIcon.png?asset'
|
||||||
|
import { createWriteStream } from 'fs'
|
||||||
import http from 'http'
|
import http from 'http'
|
||||||
import net from 'net'
|
import net from 'net'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
@ -89,6 +90,7 @@ export async function startSubStoreBackendServer(): Promise<void> {
|
|||||||
const {
|
const {
|
||||||
useSubStore = true,
|
useSubStore = true,
|
||||||
useCustomSubStore = false,
|
useCustomSubStore = false,
|
||||||
|
useProxyInSubStore = false,
|
||||||
subStoreHost = '127.0.0.1',
|
subStoreHost = '127.0.0.1',
|
||||||
subStoreBackendSyncCron = '',
|
subStoreBackendSyncCron = '',
|
||||||
subStoreBackendDownloadCron = '',
|
subStoreBackendDownloadCron = '',
|
||||||
@ -101,6 +103,8 @@ export async function startSubStoreBackendServer(): Promise<void> {
|
|||||||
subStorePort = await findAvailablePort(38324)
|
subStorePort = await findAvailablePort(38324)
|
||||||
const icon = nativeImage.createFromPath(subStoreIcon)
|
const icon = nativeImage.createFromPath(subStoreIcon)
|
||||||
icon.toDataURL()
|
icon.toDataURL()
|
||||||
|
const stdout = createWriteStream(substoreLogPath(), { flags: 'a' })
|
||||||
|
const stderr = createWriteStream(substoreLogPath(), { flags: 'a' })
|
||||||
subStoreBackendWorker = new Worker(path.join(resourcesFilesDir(), 'sub-store.bundle.js'), {
|
subStoreBackendWorker = new Worker(path.join(resourcesFilesDir(), 'sub-store.bundle.js'), {
|
||||||
env: {
|
env: {
|
||||||
SUB_STORE_BACKEND_API_PORT: subStorePort.toString(),
|
SUB_STORE_BACKEND_API_PORT: subStorePort.toString(),
|
||||||
@ -113,11 +117,13 @@ export async function startSubStoreBackendServer(): Promise<void> {
|
|||||||
SUB_STORE_BACKEND_UPLOAD_CRON: subStoreBackendUploadCron,
|
SUB_STORE_BACKEND_UPLOAD_CRON: subStoreBackendUploadCron,
|
||||||
SUB_STORE_MMDB_COUNTRY_PATH: path.join(mihomoWorkDir(), 'country.mmdb'),
|
SUB_STORE_MMDB_COUNTRY_PATH: path.join(mihomoWorkDir(), 'country.mmdb'),
|
||||||
SUB_STORE_MMDB_ASN_PATH: path.join(mihomoWorkDir(), 'ASN.mmdb'),
|
SUB_STORE_MMDB_ASN_PATH: path.join(mihomoWorkDir(), 'ASN.mmdb'),
|
||||||
HTTP_PROXY: `http://127.0.0.1:${port}`,
|
HTTP_PROXY: useProxyInSubStore ? `http://127.0.0.1:${port}` : undefined,
|
||||||
HTTPS_PROXY: `http://127.0.0.1:${port}`,
|
HTTPS_PROXY: useProxyInSubStore ? `http://127.0.0.1:${port}` : undefined,
|
||||||
ALL_PROXY: `http://127.0.0.1:${port}`
|
ALL_PROXY: useProxyInSubStore ? `http://127.0.0.1:${port}` : undefined
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
subStoreBackendWorker.stdout.pipe(stdout)
|
||||||
|
subStoreBackendWorker.stderr.pipe(stderr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -127,3 +127,9 @@ export function logPath(): string {
|
|||||||
const name = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
const name = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||||
return path.join(logDir(), `${name}.log`)
|
return path.join(logDir(), `${name}.log`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function substoreLogPath(): string {
|
||||||
|
const date = new Date()
|
||||||
|
const name = `sub-store-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
|
||||||
|
return path.join(logDir(), `${name}.log`)
|
||||||
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ const SubStoreConfig: React.FC = () => {
|
|||||||
const {
|
const {
|
||||||
useSubStore = true,
|
useSubStore = true,
|
||||||
useCustomSubStore = false,
|
useCustomSubStore = false,
|
||||||
|
useProxyInSubStore = false,
|
||||||
subStoreHost = '127.0.0.1',
|
subStoreHost = '127.0.0.1',
|
||||||
customSubStoreUrl,
|
customSubStoreUrl,
|
||||||
subStoreBackendSyncCron,
|
subStoreBackendSyncCron,
|
||||||
@ -111,6 +112,20 @@ const SubStoreConfig: React.FC = () => {
|
|||||||
</SettingItem>
|
</SettingItem>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
<SettingItem title="为 Sub-Store 内所有请求启用代理" divider>
|
||||||
|
<Switch
|
||||||
|
size="sm"
|
||||||
|
isSelected={useProxyInSubStore}
|
||||||
|
onValueChange={async (v) => {
|
||||||
|
try {
|
||||||
|
await patchAppConfig({ useProxyInSubStore: v })
|
||||||
|
await startSubStoreBackendServer()
|
||||||
|
} catch (e) {
|
||||||
|
alert(e)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
<SettingItem title="定时同步订阅/文件" divider>
|
<SettingItem title="定时同步订阅/文件" divider>
|
||||||
<div className="flex w-[60%] gap-2">
|
<div className="flex w-[60%] gap-2">
|
||||||
{subStoreBackendSyncCronValue !== subStoreBackendSyncCron && (
|
{subStoreBackendSyncCronValue !== subStoreBackendSyncCron && (
|
||||||
|
|||||||
1
src/shared/types.d.ts
vendored
1
src/shared/types.d.ts
vendored
@ -239,6 +239,7 @@ interface IAppConfig {
|
|||||||
autoQuitWithoutCore?: boolean
|
autoQuitWithoutCore?: boolean
|
||||||
autoQuitWithoutCoreDelay?: number
|
autoQuitWithoutCoreDelay?: number
|
||||||
useCustomSubStore?: boolean
|
useCustomSubStore?: boolean
|
||||||
|
useProxyInSubStore?: boolean
|
||||||
customSubStoreUrl?: string
|
customSubStoreUrl?: string
|
||||||
diffWorkDir?: boolean
|
diffWorkDir?: boolean
|
||||||
autoSetDNS?: boolean
|
autoSetDNS?: boolean
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user