diff --git a/Demo/Demo/Demo-MacOS/ExamplesViewController.swift b/Demo/Demo/Demo-MacOS/ExamplesViewController.swift index 8274bcc..2a93f9e 100644 --- a/Demo/Demo/Demo-MacOS/ExamplesViewController.swift +++ b/Demo/Demo/Demo-MacOS/ExamplesViewController.swift @@ -44,6 +44,11 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi } // 当选中的行发生变化时被调用 let selectedRow = tableView.selectedRow + + guard selectedRow >= 0, selectedRow < examples.count else { + return + } + let item = examples[selectedRow] switch item { case .getUserInfo: @@ -103,6 +108,27 @@ class ExamplesViewController: NSViewController, NSTableViewDataSource, NSTableVi } case .uploadFileToRoot: break + case .createFolderOnRoot: + Task { + do { + let driveInfo = try await client.send(AliyunpanScope.User.GetDriveInfo()) + + let driveId = driveInfo.default_drive_id + + let response = try await client.send( + AliyunpanScope.File.CreateFile( + .init( + drive_id: driveId, + parent_file_id: "root", + name: "TestFolder", + type: .folder, + check_name_mode: .auto_rename))) + + print(response) + } catch { + print(error) + } + } } } diff --git a/Demo/Demo/Demo-iOS/ViewController.swift b/Demo/Demo/Demo-iOS/ViewController.swift index 4452f8d..71cfa66 100644 --- a/Demo/Demo/Demo-iOS/ViewController.swift +++ b/Demo/Demo/Demo-iOS/ViewController.swift @@ -57,6 +57,7 @@ class ViewController: UIViewController { snapshot.appendSections(["File"]) snapshot.appendItems([.fetchFileList]) snapshot.appendItems([.uploadFileToRoot]) + snapshot.appendItems([.createFolderOnRoot]) dataSource.apply(snapshot) } @@ -84,7 +85,7 @@ class ViewController: UIViewController { name: url.lastPathComponent, check_name_mode: .auto_rename))) - if let uploadURL = response.part_info_list.first?.upload_url { + if let uploadURL = response.part_info_list?.first?.upload_url { var urlRequest = URLRequest(url: uploadURL) urlRequest.httpMethod = "put" urlRequest.allHTTPHeaderFields = [ @@ -195,6 +196,31 @@ extension ViewController: UICollectionViewDelegate { let documentPickerController = UIDocumentPickerViewController(forOpeningContentTypes: [.item]) documentPickerController.delegate = self present(documentPickerController, animated: true) + case .createFolderOnRoot: + Task { + do { + activityIndicatorView.startAnimating() + + let driveInfo = try await self.client.send(AliyunpanScope.User.GetDriveInfo()) + + let driveId = driveInfo.default_drive_id + + let response = try await self.client.send( + AliyunpanScope.File.CreateFile( + .init( + drive_id: driveId, + parent_file_id: "root", + name: "TestFolder", + type: .folder, + check_name_mode: .auto_rename))) + + print(response) + + activityIndicatorView.stopAnimating() + } catch { + print(error) + } + } } } } diff --git a/Demo/Demo/Example.swift b/Demo/Demo/Example.swift index ba3e715..18d007e 100644 --- a/Demo/Demo/Example.swift +++ b/Demo/Demo/Example.swift @@ -15,4 +15,5 @@ enum Example: String, CaseIterable { case getVipFeatureList = "获取付费墙" case fetchFileList = "获取文件列表" case uploadFileToRoot = "上传文件到根目录" + case createFolderOnRoot = "在根目录创建文件夹" } diff --git a/Sources/AliyunpanSDK/AliyunpanScope/File/CreateFile.swift b/Sources/AliyunpanSDK/AliyunpanScope/File/CreateFile.swift index d6bd414..47b1116 100644 --- a/Sources/AliyunpanSDK/AliyunpanScope/File/CreateFile.swift +++ b/Sources/AliyunpanSDK/AliyunpanScope/File/CreateFile.swift @@ -91,7 +91,7 @@ extension AliyunpanFileScope { public let exist: Bool? /// 是否秒传 public let rapid_upload: Bool? - public let part_info_list: [AliyunpanFile.PartInfo] + public let part_info_list: [AliyunpanFile.PartInfo]? /// 创建文件夹返回空 public var upload_id: String? }