|
@@ -20,6 +20,43 @@ export class RcpSocket {
|
|
|
console.info(UtilName, 'testTag', 'RcpSocketUtil单例已创建')
|
|
console.info(UtilName, 'testTag', 'RcpSocketUtil单例已创建')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private encodeUrlPath(path?: string): string {
|
|
|
|
|
+ if (!path || path.length === 0) {
|
|
|
|
|
+ return '/';
|
|
|
|
|
+ }
|
|
|
|
|
+ let normalized = path.replace(/\\/g, '/');
|
|
|
|
|
+ if (!normalized.startsWith('/')) {
|
|
|
|
|
+ normalized = `/${normalized}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ normalized = normalized.replace(/\/+/g, '/');
|
|
|
|
|
+ const segments = normalized.split('/').map((segment) => {
|
|
|
|
|
+ if (!segment || segment.length === 0) {
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ let decoded = segment;
|
|
|
|
|
+ try {
|
|
|
|
|
+ decoded = decodeURIComponent(segment);
|
|
|
|
|
+ } catch (_err) {
|
|
|
|
|
+ // ignore decode errors and keep raw segment
|
|
|
|
|
+ }
|
|
|
|
|
+ return encodeURIComponent(decoded);
|
|
|
|
|
+ });
|
|
|
|
|
+ let encodedPath = segments.join('/');
|
|
|
|
|
+ if (!encodedPath.startsWith('/')) {
|
|
|
|
|
+ encodedPath = `/${encodedPath}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (encodedPath.length === 0) {
|
|
|
|
|
+ encodedPath = '/';
|
|
|
|
|
+ }
|
|
|
|
|
+ return encodedPath;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private buildRequestUrl(host: string, port: number, path: string, enableHttps: boolean): string {
|
|
|
|
|
+ const protocol = enableHttps ? "https" : "http";
|
|
|
|
|
+ const encodedPath = this.encodeUrlPath(path);
|
|
|
|
|
+ return `${protocol}://${host}:${port}${encodedPath}`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
static getInstance(): RcpSocket {
|
|
static getInstance(): RcpSocket {
|
|
|
if (!RcpSocket.instance) {
|
|
if (!RcpSocket.instance) {
|
|
|
RcpSocket.instance = new RcpSocket();
|
|
RcpSocket.instance = new RcpSocket();
|
|
@@ -30,7 +67,7 @@ export class RcpSocket {
|
|
|
public RcpSendHead(host: string, port: number, account: string, password: string, path: string,
|
|
public RcpSendHead(host: string, port: number, account: string, password: string, path: string,
|
|
|
enableHttps: boolean): Promise<number> {
|
|
enableHttps: boolean): Promise<number> {
|
|
|
return new Promise<number>((resolve, reject) => {
|
|
return new Promise<number>((resolve, reject) => {
|
|
|
- const url = `${enableHttps ? "https" : "http"}://${host}:${port}${path}`;
|
|
|
|
|
|
|
+ const url = this.buildRequestUrl(host, port, path, enableHttps);
|
|
|
const timeoutDuration: number = 10000;
|
|
const timeoutDuration: number = 10000;
|
|
|
const speedThreshold: number = 5000; // 设置速度测试的时间阈值
|
|
const speedThreshold: number = 5000; // 设置速度测试的时间阈值
|
|
|
console.info(UtilName, 'testTag', '发送HEAD的url:' + url)
|
|
console.info(UtilName, 'testTag', '发送HEAD的url:' + url)
|
|
@@ -110,7 +147,7 @@ export class RcpSocket {
|
|
|
public RcpSendDelete(host: string, port: number, account: string, password: string, path: string,
|
|
public RcpSendDelete(host: string, port: number, account: string, password: string, path: string,
|
|
|
enableHttps: boolean): Promise<void> {
|
|
enableHttps: boolean): Promise<void> {
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
- const url = `${enableHttps ? "https" : "http"}://${host}:${port}${path}`;
|
|
|
|
|
|
|
+ const url = this.buildRequestUrl(host, port, path, enableHttps);
|
|
|
const timeoutDuration: number = 10000;
|
|
const timeoutDuration: number = 10000;
|
|
|
console.info(UtilName, 'testTag', '发送Delete的url:' + url)
|
|
console.info(UtilName, 'testTag', '发送Delete的url:' + url)
|
|
|
// 创建 RCP 会话配置
|
|
// 创建 RCP 会话配置
|
|
@@ -173,8 +210,8 @@ export class RcpSocket {
|
|
|
public RcpSendMove(host: string, port: number, account: string, password: string, path: string, enableHttps: boolean,
|
|
public RcpSendMove(host: string, port: number, account: string, password: string, path: string, enableHttps: boolean,
|
|
|
newPath: string): Promise<void> {
|
|
newPath: string): Promise<void> {
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
- const url = `${enableHttps ? "https" : "http"}://${host}:${port}${path}`;
|
|
|
|
|
- const destinationUrl = `${enableHttps ? "https" : "http"}://${host}:${port}${newPath}`
|
|
|
|
|
|
|
+ const url = this.buildRequestUrl(host, port, path, enableHttps);
|
|
|
|
|
+ const destinationUrl = this.buildRequestUrl(host, port, newPath, enableHttps)
|
|
|
const timeoutDuration: number = 10000;
|
|
const timeoutDuration: number = 10000;
|
|
|
console.info(UtilName, 'testTag', '发送MOVE的url:' + url)
|
|
console.info(UtilName, 'testTag', '发送MOVE的url:' + url)
|
|
|
// 创建 RCP 会话配置
|
|
// 创建 RCP 会话配置
|
|
@@ -245,7 +282,7 @@ export class RcpSocket {
|
|
|
enableHttps: boolean
|
|
enableHttps: boolean
|
|
|
): Promise<FileInfo[]> {
|
|
): Promise<FileInfo[]> {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
|
- const url = `${enableHttps ? "https" : "http"}://${host}:${port.toString()}${path}`;
|
|
|
|
|
|
|
+ const url = this.buildRequestUrl(host, port, path, enableHttps);
|
|
|
const timeoutDuration: number = 10000;
|
|
const timeoutDuration: number = 10000;
|
|
|
console.info(UtilName, 'testTag', '发送PROPFIND请求的url:' + url)
|
|
console.info(UtilName, 'testTag', '发送PROPFIND请求的url:' + url)
|
|
|
// 创建 RCP 会话配置
|
|
// 创建 RCP 会话配置
|
|
@@ -373,7 +410,7 @@ export class RcpSocket {
|
|
|
cachePath: string
|
|
cachePath: string
|
|
|
): Promise<FileInfo[]> {
|
|
): Promise<FileInfo[]> {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
|
- const url = `${enableHttps ? "https" : "http"}://${host}:${port.toString()}${path}`;
|
|
|
|
|
|
|
+ const url = this.buildRequestUrl(host, port, path, enableHttps);
|
|
|
const timeoutDuration: number = 10000;
|
|
const timeoutDuration: number = 10000;
|
|
|
console.info(UtilName, 'testTag', '发送PROPFIND递归请求的url:' + url)
|
|
console.info(UtilName, 'testTag', '发送PROPFIND递归请求的url:' + url)
|
|
|
let cacheFileInfos_str: string = ''
|
|
let cacheFileInfos_str: string = ''
|
|
@@ -820,7 +857,7 @@ export class RcpSocket {
|
|
|
onProgress?: (uploaded: number, total: number) => void
|
|
onProgress?: (uploaded: number, total: number) => void
|
|
|
): Promise<void> {
|
|
): Promise<void> {
|
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
|
- const url = `${enableHttps ? "https" : "http"}://${host}:${port}${remotePath}`;
|
|
|
|
|
|
|
+ const url = this.buildRequestUrl(host, port, remotePath, enableHttps);
|
|
|
const timeoutDuration: number = 120000; // 上传超时时间设置为120秒
|
|
const timeoutDuration: number = 120000; // 上传超时时间设置为120秒
|
|
|
console.info(UtilName, 'testTag', '开始上传文件到:', url);
|
|
console.info(UtilName, 'testTag', '开始上传文件到:', url);
|
|
|
|
|
|