|
@@ -2851,9 +2851,72 @@ export class RemoteDriveManager {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 在WebDAV服务器上创建文件夹
|
|
|
|
|
+ * @param account WebDAV账户
|
|
|
|
|
+ * @param folderName 要创建的文件夹名称
|
|
|
|
|
+ * @param parentPath 父级路径,默认为当前路径
|
|
|
|
|
+ * @returns Promise<string> 创建成功后的完整路径
|
|
|
|
|
+ */
|
|
|
|
|
+ public async createWebDavFolder(account: WebDavAccount, folderName: string, parentPath?: string): Promise<string> {
|
|
|
|
|
+ if (!account || account.webType !== RemoteDriveType.WebDav) {
|
|
|
|
|
+ throw new Error('只支持在WebDAV账户中创建文件夹');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ if (!folderName || folderName.trim().length === 0) {
|
|
|
|
|
+ throw new Error('文件夹名称不能为空');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ // 检查文件夹名称是否包含非法字符
|
|
|
|
|
+ const invalidChars = /[\\/:*?"<>|]/;
|
|
|
|
|
+ if (invalidChars.test(folderName.trim())) {
|
|
|
|
|
+ throw new Error('文件夹名称不能包含 \\ / : * ? " < > | 字符');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确定服务器地址
|
|
|
|
|
+ const host = account.isUseLocalHost && account.localHost ? account.localHost : account.host;
|
|
|
|
|
+ if (!host || host.length === 0) {
|
|
|
|
|
+ throw new Error('WebDAV账户缺少服务器地址');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!account.account || account.account.length === 0) {
|
|
|
|
|
+ throw new Error('WebDAV账户缺少用户名');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!account.password || account.password.length === 0) {
|
|
|
|
|
+ throw new Error('WebDAV账户缺少密码');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确定父级路径
|
|
|
|
|
+ const basePath = parentPath || this.currentPath;
|
|
|
|
|
+
|
|
|
|
|
+ // 构建完整的文件夹路径
|
|
|
|
|
+ const fullPath = basePath === '' || basePath === '/'
|
|
|
|
|
+ ? `/${folderName.trim()}`
|
|
|
|
|
+ : `${basePath.replace(/\/$/, '')}/${folderName.trim()}`;
|
|
|
|
|
+
|
|
|
|
|
+ Logger.info(TAG, `heanup 准备在WebDAV服务器创建文件夹: ${fullPath}`);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 调用RcpSocket的createDirectory方法(使用MKCOL协议)
|
|
|
|
|
+ await this.rcpSocket.createDirectory(
|
|
|
|
|
+ host,
|
|
|
|
|
+ account.port,
|
|
|
|
|
+ account.account,
|
|
|
|
|
+ account.password,
|
|
|
|
|
+ fullPath,
|
|
|
|
|
+ account.enableHttps
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ Logger.info(TAG, `heanup WebDAV文件夹创建成功: ${fullPath}`);
|
|
|
|
|
+ return fullPath;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ const err = error as Error;
|
|
|
|
|
+ Logger.error(TAG, `heanup WebDAV文件夹创建失败: ${err.message}`);
|
|
|
|
|
+ throw err;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 构建HTTP请求头,特别处理WebDAV认证
|
|
* 构建HTTP请求头,特别处理WebDAV认证
|