|
|
@@ -17,7 +17,7 @@ import { CommonConstants } from '../constants/CommonConstants';
|
|
|
import { GlobalContext, PreferencesUtil } from '@pura/harmony-utils';
|
|
|
import { MusicInfo, parseMusicFileName, Utility } from './Utility';
|
|
|
import { RemoteDriveType } from '../enums/RemoteDriveType';
|
|
|
-import { deleteSmbEntry, listSmbDirectory, SmbDirectoryEntry } from '../network/SmbBridge';
|
|
|
+import { createSmbDirectory, deleteSmbEntry, listSmbDirectory, SmbDirectoryEntry } from '../network/SmbBridge';
|
|
|
import { NavidromeApi, NavidromeAlbumDetail, NavidromeArtist, NavidromeArtistDetail, NavidromeSong } from '../network/NavidromeApi';
|
|
|
import { WebDavUrlUtil } from './WebDavUrlUtil';
|
|
|
import MediaTable from './MediaTable';
|
|
|
@@ -2916,6 +2916,68 @@ export class RemoteDriveManager {
|
|
|
throw err;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在SMB服务器上创建文件夹
|
|
|
+ * @param account SMB账户
|
|
|
+ * @param folderName 要创建的文件夹名称
|
|
|
+ * @param parentPath 父级路径,默认为当前路径
|
|
|
+ * @returns Promise<string> 创建成功后的完整路径
|
|
|
+ */
|
|
|
+ public async createSMBFolder(account: WebDavAccount, folderName: string, parentPath?: string): Promise<string> {
|
|
|
+ if (!account || account.webType !== RemoteDriveType.Smb) {
|
|
|
+ throw new Error('只支持在SMB账户中创建文件夹');
|
|
|
+ }
|
|
|
+
|
|
|
+ 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('SMB账户缺少服务器地址');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!account.smbShare || account.smbShare.length === 0) {
|
|
|
+ throw new Error('SMB账户缺少共享名称');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确定父级路径
|
|
|
+ const basePath = parentPath || this.currentPath;
|
|
|
+
|
|
|
+ // 构建完整的文件夹路径
|
|
|
+ const fullPath = basePath === '' || basePath === '/'
|
|
|
+ ? `${folderName.trim()}`
|
|
|
+ : `${basePath.replace(/\/$/, '').replace(/^\/+/, '')}/${folderName.trim()}`;
|
|
|
+
|
|
|
+ Logger.info(TAG, `heanup 准备在SMB服务器创建文件夹: ${fullPath}`);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 调用createSmbDirectory函数
|
|
|
+ await createSmbDirectory({
|
|
|
+ host,
|
|
|
+ share: account.smbShare,
|
|
|
+ username: account.account || '',
|
|
|
+ password: account.password || '',
|
|
|
+ domain: account.smbDomain,
|
|
|
+ path: fullPath
|
|
|
+ });
|
|
|
+
|
|
|
+ Logger.info(TAG, `heanup SMB文件夹创建成功: ${fullPath}`);
|
|
|
+ return `/${fullPath}`;
|
|
|
+ } catch (error) {
|
|
|
+ const err = error as Error;
|
|
|
+ Logger.error(TAG, `heanup SMB文件夹创建失败: ${err.message}`);
|
|
|
+ throw err;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|