Skip to content

Commit

Permalink
fix: fix the error in CreateFile.swift that occurs when using codable (
Browse files Browse the repository at this point in the history
  • Loading branch information
wzxha authored Feb 4, 2024
1 parent 7157113 commit afb2569
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Demo/Demo/Demo-MacOS/ExamplesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}
}
}
}

Expand Down
28 changes: 27 additions & 1 deletion Demo/Demo/Demo-iOS/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ViewController: UIViewController {
snapshot.appendSections(["File"])
snapshot.appendItems([.fetchFileList])
snapshot.appendItems([.uploadFileToRoot])
snapshot.appendItems([.createFolderOnRoot])
dataSource.apply(snapshot)
}

Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Demo/Demo/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ enum Example: String, CaseIterable {
case getVipFeatureList = "获取付费墙"
case fetchFileList = "获取文件列表"
case uploadFileToRoot = "上传文件到根目录"
case createFolderOnRoot = "在根目录创建文件夹"
}
2 changes: 1 addition & 1 deletion Sources/AliyunpanSDK/AliyunpanScope/File/CreateFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand Down

0 comments on commit afb2569

Please sign in to comment.