mirror of
https://github.com/VirtualHotBar/NetMount.git
synced 2026-05-31 08:18:59 +08:00
fix
This commit is contained in:
@@ -7,7 +7,7 @@ import { reupMount } from "./storage/mount/mount"
|
||||
import { reupStorage } from "./storage/storage"
|
||||
import { listenWindow, windowsHide } from "./window"
|
||||
import { NMConfig } from "../type/config"
|
||||
import { randomString, restartSelf } from "../utils/utils"
|
||||
import { randomString, restartSelf, sleep } from "../utils/utils"
|
||||
import { t } from "i18next"
|
||||
import { startRclone, stopRclone } from "../utils/rclone/process"
|
||||
import { getOsInfo } from "../utils/tauri/osInfo"
|
||||
@@ -85,6 +85,7 @@ async function reupRcloneVersion() {
|
||||
async function reupAlistVersion() {
|
||||
let version = await alist_api_get('/api/admin/setting/get', { key: 'version' })
|
||||
if (version.code !== 200) {
|
||||
await sleep(500)
|
||||
await reupAlistVersion()
|
||||
return
|
||||
}
|
||||
@@ -98,6 +99,7 @@ function main() {
|
||||
|
||||
async function exit(isRestartSelf: boolean = false) {
|
||||
try {
|
||||
await saveNmConfig()
|
||||
await stopRclone()
|
||||
await stopAlist()
|
||||
await saveNmConfig()
|
||||
|
||||
@@ -3,7 +3,7 @@ import { hooks } from "../../services/hook"
|
||||
import { rcloneInfo } from "../../services/rclone"
|
||||
import { FileInfo, StorageList, StorageSpace } from "../../type/rclone/rcloneInfo"
|
||||
import { ParametersType } from "../../type/defaults"
|
||||
import { rclone_api_post, rcloneApiHeaders } from "../../utils/rclone/request"
|
||||
import { getRcloneApiHeaders, rclone_api_post } from "../../utils/rclone/request"
|
||||
import { alist_api_get, alist_api_post } from "../../utils/alist/request"
|
||||
import { formatPath } from "../../utils/utils"
|
||||
import { alistInfo } from "../../services/alist"
|
||||
@@ -311,7 +311,7 @@ const uploadFileRequest = (option: RequestOptions, storageName: string, path: st
|
||||
xhr.onerror = () => onError(xhr);
|
||||
|
||||
xhr.open('POST', `${rcloneInfo.endpoint.url}/operations/uploadfile?fs=${convertStoragePath(storageName,undefined,undefined,undefined,true)}&remote=${convertStoragePath(storageName,path,true,true,undefined)}`, true);
|
||||
xhr.setRequestHeader('Authorization', `Bearer ${rcloneApiHeaders.Authorization}`);
|
||||
xhr.setRequestHeader('Authorization', `Bearer ${getRcloneApiHeaders().Authorization}`);
|
||||
xhr.send(formData);
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next';
|
||||
import { copyDir, copyFile, delDir, delFile, filterHideStorage, formatPathRclone, getFileList, mkDir, moveDir, moveFile, uploadFileRequest } from '../../controller/storage/storage';
|
||||
import { FileInfo } from '../../type/rclone/rcloneInfo';
|
||||
import { formatSize, getURLSearchParam } from '../../utils/utils';
|
||||
import { rcloneApiHeaders } from '../../utils/rclone/request';
|
||||
import { RequestOptions } from '@arco-design/web-react/es/Upload';
|
||||
import { NoData_module } from '../other/noData';
|
||||
import { clipListItem } from '../../type/page/storage/explorer';
|
||||
|
||||
@@ -68,8 +68,8 @@ let nmConfig: NMConfig = {
|
||||
},
|
||||
framework: {
|
||||
rclone: {
|
||||
user: process.env.NODE_ENV != 'development' ? randomString(32) : '',
|
||||
password: process.env.NODE_ENV != 'development' ? randomString(128) : '',
|
||||
user: randomString(32),
|
||||
password: randomString(128),
|
||||
},
|
||||
alist: {
|
||||
user: 'admin',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { invoke } from "@tauri-apps/api";
|
||||
import { Command } from "@tauri-apps/api/shell";
|
||||
import { rcloneInfo } from "../../services/rclone";
|
||||
import { formatPath, randomString } from "../utils";
|
||||
import { formatPath, randomString, sleep } from "../utils";
|
||||
import { alistInfo } from "../../services/alist";
|
||||
import { homeDir } from "@tauri-apps/api/path";
|
||||
import { nmConfig, osInfo, roConfig } from "../../services/config";
|
||||
@@ -45,7 +45,7 @@ async function startAlist() {
|
||||
alistInfo.process.child = await alistInfo.process.command.spawn()
|
||||
|
||||
while (true) {
|
||||
await setTimeout(() => { }, 1500);
|
||||
await sleep(500)
|
||||
if (await alist_api_ping()&&alistInfo.process.log.includes('start HTTP server')) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { invoke } from "@tauri-apps/api";
|
||||
import { Command } from "@tauri-apps/api/shell";
|
||||
import { rcloneInfo } from "../../services/rclone";
|
||||
import { rclone_api_noop, rclone_api_post } from "./request";
|
||||
import { formatPath, randomString } from "../utils";
|
||||
import { formatPath, randomString, sleep } from "../utils";
|
||||
import { alistInfo } from "../../services/alist";
|
||||
import { delStorage } from "../../controller/storage/storage";
|
||||
import { nmConfig, osInfo, roConfig } from "../../services/config";
|
||||
@@ -16,7 +16,7 @@ async function startRclone() {
|
||||
await stopRclone()
|
||||
}
|
||||
|
||||
/* if (process.env.NODE_ENV != 'development') {
|
||||
/*if (process.env.NODE_ENV != 'development') {
|
||||
rcloneInfo.endpoint.auth.user = randomString(32)
|
||||
rcloneInfo.endpoint.auth.pass = randomString(128)
|
||||
} */
|
||||
@@ -31,7 +31,7 @@ async function startRclone() {
|
||||
`--rc-user=${nmConfig.framework.rclone.user}`,
|
||||
`--rc-pass=${nmConfig.framework.rclone.password}`,
|
||||
'--rc-allow-origin=' + window.location.origin || '*',
|
||||
'--config=' + rcloneDataDir() + '/rclone.conf',
|
||||
'--config=' +formatPath( rcloneDataDir() + '/rclone.conf', osInfo.osType === 'Windows_NT'),
|
||||
];
|
||||
|
||||
if (nmConfig.framework.rclone.user === '') {
|
||||
@@ -52,7 +52,7 @@ async function startRclone() {
|
||||
rcloneInfo.process.child = await rcloneInfo.process.command.spawn()
|
||||
|
||||
while (true) {
|
||||
await setTimeout(() => { }, 1000);
|
||||
await sleep(500)
|
||||
if (await rclone_api_noop()/* &&rcloneInfo.process.log.includes('Serving remote control on') */) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,16 @@ import { Message } from "@arco-design/web-react";
|
||||
import { rcloneInfo } from "../../services/rclone";
|
||||
import { nmConfig } from "../../services/config";
|
||||
|
||||
let rcloneApiHeaders = {
|
||||
Authorization: `Basic ${btoa(`${nmConfig.framework.rclone.user}:${nmConfig.framework.rclone.password}`)}`,
|
||||
'Content-Type': 'application/json'
|
||||
let getRcloneApiHeaders = () => {
|
||||
return {
|
||||
Authorization: `Basic ${btoa(`${nmConfig.framework.rclone.user}:${nmConfig.framework.rclone.password}`)}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
async function rclone_api_noop(): Promise<boolean> {
|
||||
try {
|
||||
return await fetch(rcloneInfo.endpoint.url + '/rc/noop', { method: 'POST' }).then(data => data.ok)
|
||||
return await fetch(rcloneInfo.endpoint.url + '/rc/noop', { method: 'POST', headers: { Authorization: getRcloneApiHeaders().Authorization } }).then(data => data.ok)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return false;
|
||||
@@ -17,18 +19,10 @@ async function rclone_api_noop(): Promise<boolean> {
|
||||
}
|
||||
|
||||
function rclone_api_post(path: string, bodyData: object = {}, ignoreError?: boolean) {
|
||||
// 以 base64 编码的方式来设置账密字符串
|
||||
const base64Credentials = btoa(`${nmConfig.framework.rclone.user}:${nmConfig.framework.rclone.password}`);
|
||||
|
||||
// 定义请求头部,包括授权头部
|
||||
rcloneApiHeaders = {
|
||||
Authorization: `Basic ${base64Credentials}`,
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
return fetch(rcloneInfo.endpoint.url + path, {
|
||||
method: 'POST',
|
||||
headers: rcloneApiHeaders,
|
||||
headers: getRcloneApiHeaders(),
|
||||
body: JSON.stringify(bodyData)
|
||||
}).then((response) => {
|
||||
if (!response.ok && !ignoreError) {
|
||||
@@ -70,4 +64,4 @@ async function printError(error: Response) {
|
||||
})
|
||||
} */
|
||||
|
||||
export { rclone_api_post, rcloneApiHeaders, rclone_api_noop }
|
||||
export { rclone_api_post, getRcloneApiHeaders, rclone_api_noop }
|
||||
@@ -205,4 +205,9 @@ export async function showPathInExplorer(path: string, isDir?: boolean) {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export async function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
Reference in New Issue
Block a user