From 3f281e308459f96a8425e1f91c1b61d32f19e84c Mon Sep 17 00:00:00 2001 From: Julian Locke Date: Tue, 16 Jan 2024 15:58:02 -0500 Subject: [PATCH] Generate missing app auth routes, clean up task reconnection helpers (#396) --- .../SwiftyDropbox_iOS/OAuthMobile.swift | 4 +- .../AppAuthReconnectionHelpers.swift | 25 ++ .../Shared/Generated/BaseApp.swift | 6 + .../Generated/DropboxAppBaseRequestBox.swift | 12 + .../Shared/Generated/FilesAppAuthRoutes.swift | 156 ++++++++++++ .../Generated/SharingAppAuthRoutes.swift | 37 +++ .../Shared/Handwritten/DropboxAppClient.swift | 1 - .../ReconnectionHelpers+Handwritten.swift | 139 ++++++----- .../SwiftyDropbox_iOS/DBXOAuthMobile.swift | 4 +- .../Shared/Generated/DBXBaseApp.swift | 8 + .../DBXDropboxAppBaseRequestBox.swift | 17 ++ .../Generated/DBXDropboxBaseRequestBox.swift | 2 - .../Generated/DBXFilesAppAuthRoutes.swift | 225 ++++++++++++++++++ .../Generated/DBXSharingAppAuthRoutes.swift | 50 ++++ stone | 2 +- 15 files changed, 623 insertions(+), 65 deletions(-) create mode 100644 Source/SwiftyDropbox/Shared/Generated/AppAuthReconnectionHelpers.swift create mode 100644 Source/SwiftyDropbox/Shared/Generated/DropboxAppBaseRequestBox.swift create mode 100644 Source/SwiftyDropbox/Shared/Generated/FilesAppAuthRoutes.swift create mode 100644 Source/SwiftyDropbox/Shared/Generated/SharingAppAuthRoutes.swift create mode 100644 Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxAppBaseRequestBox.swift create mode 100644 Source/SwiftyDropboxObjC/Shared/Generated/DBXFilesAppAuthRoutes.swift create mode 100644 Source/SwiftyDropboxObjC/Shared/Generated/DBXSharingAppAuthRoutes.swift diff --git a/Source/SwiftyDropbox/Platform/SwiftyDropbox_iOS/OAuthMobile.swift b/Source/SwiftyDropbox/Platform/SwiftyDropbox_iOS/OAuthMobile.swift index 459e51fc..7e3f0e4d 100644 --- a/Source/SwiftyDropbox/Platform/SwiftyDropbox_iOS/OAuthMobile.swift +++ b/Source/SwiftyDropbox/Platform/SwiftyDropbox_iOS/OAuthMobile.swift @@ -19,7 +19,7 @@ extension DropboxClientsManager { /// /// - Parameters: /// - sharedApplication: The shared UIApplication instance in your app. - /// - controller: A UIViewController to present the auth flow from. Reference is weakly held. + /// - controller: A UIViewController to present the auth flow from. This should be the top-most view controller. Reference is weakly held. /// - openURL: Handler to open a URL. @available( *, @@ -50,7 +50,7 @@ extension DropboxClientsManager { /// /// - Parameters: /// - sharedApplication: The shared UIApplication instance in your app. - /// - controller: A UIViewController to present the auth flow from. Reference is weakly held. + /// - controller: A UIViewController to present the auth flow from. This should be the top-most view controller. Reference is weakly held. /// - loadingStatusDelegate: An optional delegate to handle loading experience during auth flow. /// e.g. Show a loading spinner and block user interaction while loading/waiting. /// If a delegate is not provided, the SDK will show a default loading spinner when necessary. diff --git a/Source/SwiftyDropbox/Shared/Generated/AppAuthReconnectionHelpers.swift b/Source/SwiftyDropbox/Shared/Generated/AppAuthReconnectionHelpers.swift new file mode 100644 index 00000000..11e74813 --- /dev/null +++ b/Source/SwiftyDropbox/Shared/Generated/AppAuthReconnectionHelpers.swift @@ -0,0 +1,25 @@ +/// +/// Copyright (c) 2022 Dropbox, Inc. All rights reserved. +/// + +import Foundation + +enum AppAuthReconnectionHelpers { + static func rebuildRequest(apiRequest: ApiRequest, client: DropboxTransportClientInternal) throws -> DropboxAppBaseRequestBox { + let info = try persistedRequestInfo(from: apiRequest) + + switch info.routeName { + case "getThumbnailV2": + return .getThumbnailV2( + rebuildRequest( + apiRequest: apiRequest, + info: info, + route: Files.getThumbnailV2, + client: client + ) + ) + default: + throw ReconnectionErrorKind.missingReconnectionCase + } + } +} diff --git a/Source/SwiftyDropbox/Shared/Generated/BaseApp.swift b/Source/SwiftyDropbox/Shared/Generated/BaseApp.swift index 4cdd60b7..3172d341 100644 --- a/Source/SwiftyDropbox/Shared/Generated/BaseApp.swift +++ b/Source/SwiftyDropbox/Shared/Generated/BaseApp.swift @@ -13,11 +13,17 @@ public class DropboxAppBase: DropboxTransportClientOwning { public var auth: AuthAppAuthRoutes! /// Routes within the check namespace. See CheckAppAuthRoutes for details. public var check: CheckAppAuthRoutes! + /// Routes within the files namespace. See FilesAppAuthRoutes for details. + public var files: FilesAppAuthRoutes! + /// Routes within the sharing namespace. See SharingAppAuthRoutes for details. + public var sharing: SharingAppAuthRoutes! public required init(client: DropboxTransportClient) { self.client = client self.auth = AuthAppAuthRoutes(client: client) self.check = CheckAppAuthRoutes(client: client) + self.files = FilesAppAuthRoutes(client: client) + self.sharing = SharingAppAuthRoutes(client: client) } } diff --git a/Source/SwiftyDropbox/Shared/Generated/DropboxAppBaseRequestBox.swift b/Source/SwiftyDropbox/Shared/Generated/DropboxAppBaseRequestBox.swift new file mode 100644 index 00000000..8fcb57da --- /dev/null +++ b/Source/SwiftyDropbox/Shared/Generated/DropboxAppBaseRequestBox.swift @@ -0,0 +1,12 @@ +/// +/// Copyright (c) 2022 Dropbox, Inc. All rights reserved. +/// +/// Auto-generated by Stone, do not modify. +/// + +import Foundation + +/// Allows for heterogenous collections of typed requests +public enum DropboxAppBaseRequestBox { + case getThumbnailV2(DownloadRequestFile) +} diff --git a/Source/SwiftyDropbox/Shared/Generated/FilesAppAuthRoutes.swift b/Source/SwiftyDropbox/Shared/Generated/FilesAppAuthRoutes.swift new file mode 100644 index 00000000..aa6c9350 --- /dev/null +++ b/Source/SwiftyDropbox/Shared/Generated/FilesAppAuthRoutes.swift @@ -0,0 +1,156 @@ +/// +/// Copyright (c) 2016 Dropbox, Inc. All rights reserved. +/// +/// Auto-generated by Stone, do not modify. +/// + +import Foundation + +/// Routes for the filesAppAuth namespace +/// For Objective-C compatible routes see DBFilesRoutes +public class FilesAppAuthRoutes: DropboxTransportClientOwning { + public let client: DropboxTransportClient + required init(client: DropboxTransportClient) { + self.client = client + } + + /// Get a thumbnail for an image. This method currently supports files with the following file extensions: jpg, + /// jpeg, png, tiff, tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size won't be converted to + /// a thumbnail. + /// + /// - scope: files.content.read + /// + /// - parameter resource: Information specifying which file to preview. This could be a path to a file, a shared + /// link pointing to a file, or a shared link pointing to a folder, with a relative path. + /// - parameter format: The format for the thumbnail image, jpeg (default) or png. For images that are photos, jpeg + /// should be preferred, while png is better for screenshots and digital arts. + /// - parameter size: The size for the thumbnail image. + /// - parameter mode: How to resize and crop the image to achieve the desired size. + /// - parameter overwrite: A boolean to set behavior in the event of a naming conflict. `True` will overwrite + /// conflicting file at destination. `False` will take no action (but if left unhandled in destination closure, + /// an NSError will be thrown). + /// - parameter destination: The location to write the download to. + /// + /// - returns: Through the response callback, the caller will receive a `Files.PreviewResult` object on success or a + /// `Files.ThumbnailV2Error` object on failure. + @discardableResult public func getThumbnailV2( + resource: Files.PathOrLink, + format: Files.ThumbnailFormat = .jpeg, + size: Files.ThumbnailSize = .w64h64, + mode: Files.ThumbnailMode = .strict, + overwrite: Bool = false, + destination: URL + ) -> DownloadRequestFile { + let route = Files.getThumbnailV2 + let serverArgs = Files.ThumbnailV2Arg(resource: resource, format: format, size: size, mode: mode) + return client.request(route, serverArgs: serverArgs, overwrite: overwrite, destination: destination) + } + + /// Get a thumbnail for an image. This method currently supports files with the following file extensions: jpg, + /// jpeg, png, tiff, tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size won't be converted to + /// a thumbnail. + /// + /// - scope: files.content.read + /// + /// - parameter resource: Information specifying which file to preview. This could be a path to a file, a shared + /// link pointing to a file, or a shared link pointing to a folder, with a relative path. + /// - parameter format: The format for the thumbnail image, jpeg (default) or png. For images that are photos, jpeg + /// should be preferred, while png is better for screenshots and digital arts. + /// - parameter size: The size for the thumbnail image. + /// - parameter mode: How to resize and crop the image to achieve the desired size. + /// + /// - returns: Through the response callback, the caller will receive a `Files.PreviewResult` object on success or a + /// `Files.ThumbnailV2Error` object on failure. + @discardableResult public func getThumbnailV2( + resource: Files.PathOrLink, + format: Files.ThumbnailFormat = .jpeg, + size: Files.ThumbnailSize = .w64h64, + mode: Files.ThumbnailMode = .strict + ) -> DownloadRequestMemory { + let route = Files.getThumbnailV2 + let serverArgs = Files.ThumbnailV2Arg(resource: resource, format: format, size: size, mode: mode) + return client.request(route, serverArgs: serverArgs) + } + + /// Starts returning the contents of a folder. If the result's hasMore in ListFolderResult field is true, call + /// listFolderContinue with the returned cursor in ListFolderResult to retrieve more entries. If you're using + /// recursive in ListFolderArg set to true to keep a local cache of the contents of a Dropbox account, iterate + /// through each entry in order and process them as follows to keep your local state in sync: For each + /// FileMetadata, store the new entry at the given path in your local state. If the required parent folders + /// don't exist yet, create them. If there's already something else at the given path, replace it and remove all + /// its children. For each FolderMetadata, store the new entry at the given path in your local state. If the + /// required parent folders don't exist yet, create them. If there's already something else at the given path, + /// replace it but leave the children as they are. Check the new entry's readOnly in FolderSharingInfo and set + /// all its children's read-only statuses to match. For each DeletedMetadata, if your local state has something + /// at the given path, remove it and all its children. If there's nothing at the given path, ignore this entry. + /// Note: auth.RateLimitError may be returned if multiple listFolder or listFolderContinue calls with same + /// parameters are made simultaneously by same API app for same user. If your app implements retry logic, please + /// hold off the retry until the previous request finishes. + /// + /// - scope: files.metadata.read + /// + /// - parameter path: A unique identifier for the file. + /// - parameter recursive: If true, the list folder operation will be applied recursively to all subfolders and the + /// response will contain contents of all subfolders. + /// - parameter includeMediaInfo: If true, mediaInfo in FileMetadata is set for photo and video. This parameter will + /// no longer have an effect starting December 2, 2019. + /// - parameter includeDeleted: If true, the results will include entries for files and folders that used to exist + /// but were deleted. + /// - parameter includeHasExplicitSharedMembers: If true, the results will include a flag for each file indicating + /// whether or not that file has any explicit members. + /// - parameter includeMountedFolders: If true, the results will include entries under mounted folders which + /// includes app folder, shared folder and team folder. + /// - parameter limit: The maximum number of results to return per request. Note: This is an approximate number and + /// there can be slightly more entries returned in some cases. + /// - parameter sharedLink: A shared link to list the contents of. If the link is password-protected, the password + /// must be provided. If this field is present, path in ListFolderArg will be relative to root of the shared + /// link. Only non-recursive mode is supported for shared link. + /// - parameter includePropertyGroups: If set to a valid list of template IDs, propertyGroups in FileMetadata is set + /// if there exists property data associated with the file and each of the listed templates. + /// - parameter includeNonDownloadableFiles: If true, include files that are not downloadable, i.e. Google Docs. + /// + /// - returns: Through the response callback, the caller will receive a `Files.ListFolderResult` object on success + /// or a `Files.ListFolderError` object on failure. + @discardableResult public func listFolder( + path: String, + recursive: Bool = false, + includeMediaInfo: Bool = false, + includeDeleted: Bool = false, + includeHasExplicitSharedMembers: Bool = false, + includeMountedFolders: Bool = true, + limit: UInt32? = nil, + sharedLink: Files.SharedLink? = nil, + includePropertyGroups: FileProperties.TemplateFilterBase? = nil, + includeNonDownloadableFiles: Bool = true + ) -> RpcRequest { + let route = Files.listFolder + let serverArgs = Files.ListFolderArg( + path: path, + recursive: recursive, + includeMediaInfo: includeMediaInfo, + includeDeleted: includeDeleted, + includeHasExplicitSharedMembers: includeHasExplicitSharedMembers, + includeMountedFolders: includeMountedFolders, + limit: limit, + sharedLink: sharedLink, + includePropertyGroups: includePropertyGroups, + includeNonDownloadableFiles: includeNonDownloadableFiles + ) + return client.request(route, serverArgs: serverArgs) + } + + /// Once a cursor has been retrieved from listFolder, use this to paginate through all files and retrieve updates to + /// the folder, following the same rules as documented for listFolder. + /// + /// - scope: files.metadata.read + /// + /// - parameter cursor: The cursor returned by your last call to listFolder or listFolderContinue. + /// + /// - returns: Through the response callback, the caller will receive a `Files.ListFolderResult` object on success + /// or a `Files.ListFolderContinueError` object on failure. + @discardableResult public func listFolderContinue(cursor: String) -> RpcRequest { + let route = Files.listFolderContinue + let serverArgs = Files.ListFolderContinueArg(cursor: cursor) + return client.request(route, serverArgs: serverArgs) + } +} diff --git a/Source/SwiftyDropbox/Shared/Generated/SharingAppAuthRoutes.swift b/Source/SwiftyDropbox/Shared/Generated/SharingAppAuthRoutes.swift new file mode 100644 index 00000000..6464ca85 --- /dev/null +++ b/Source/SwiftyDropbox/Shared/Generated/SharingAppAuthRoutes.swift @@ -0,0 +1,37 @@ +/// +/// Copyright (c) 2016 Dropbox, Inc. All rights reserved. +/// +/// Auto-generated by Stone, do not modify. +/// + +import Foundation + +/// Routes for the sharingAppAuth namespace +/// For Objective-C compatible routes see DBSharingRoutes +public class SharingAppAuthRoutes: DropboxTransportClientOwning { + public let client: DropboxTransportClient + required init(client: DropboxTransportClient) { + self.client = client + } + + /// Get the shared link's metadata. + /// + /// - scope: sharing.read + /// + /// - parameter url: URL of the shared link. + /// - parameter path: If the shared link is to a folder, this parameter can be used to retrieve the metadata for a + /// specific file or sub-folder in this folder. A relative path should be used. + /// - parameter linkPassword: If the shared link has a password, this parameter can be used. + /// + /// - returns: Through the response callback, the caller will receive a `Sharing.SharedLinkMetadata` object on + /// success or a `Sharing.SharedLinkError` object on failure. + @discardableResult public func getSharedLinkMetadata( + url: String, + path: String? = nil, + linkPassword: String? = nil + ) -> RpcRequest { + let route = Sharing.getSharedLinkMetadata + let serverArgs = Sharing.GetSharedLinkMetadataArg(url: url, path: path, linkPassword: linkPassword) + return client.request(route, serverArgs: serverArgs) + } +} diff --git a/Source/SwiftyDropbox/Shared/Handwritten/DropboxAppClient.swift b/Source/SwiftyDropbox/Shared/Handwritten/DropboxAppClient.swift index 7d5bc7d6..aafe6adb 100644 --- a/Source/SwiftyDropbox/Shared/Handwritten/DropboxAppClient.swift +++ b/Source/SwiftyDropbox/Shared/Handwritten/DropboxAppClient.swift @@ -23,5 +23,4 @@ public class DropboxAppClient: DropboxAppBase { required convenience init(client: DropboxTransportClient) { self.init(transportClient: client) } - } diff --git a/Source/SwiftyDropbox/Shared/Handwritten/ReconnectionHelpers+Handwritten.swift b/Source/SwiftyDropbox/Shared/Handwritten/ReconnectionHelpers+Handwritten.swift index 7bba2b08..4dc60b4f 100644 --- a/Source/SwiftyDropbox/Shared/Handwritten/ReconnectionHelpers+Handwritten.swift +++ b/Source/SwiftyDropbox/Shared/Handwritten/ReconnectionHelpers+Handwritten.swift @@ -24,9 +24,87 @@ protocol PersistedRequestInfoBaseInfo { var clientProvidedInfo: String? { get set } } -extension ReconnectionHelpers { - private static let Separator = "#?///?#" +fileprivate struct ReconnectionConstants { + static let separator = "#?///?#" +} + +protocol ReconnectionHelpersShared { + static func persistedRequestInfo(from apiRequest: ApiRequest) throws -> ReconnectionHelpers.PersistedRequestInfo + static func originalSdkVersion(fromJsonString jsonString: String) throws -> String + static func rebuildRequest( + apiRequest: ApiRequest, + info: ReconnectionHelpers.PersistedRequestInfo, + route: Route, + client: DropboxTransportClientInternal + ) -> UploadRequest + + static func rebuildRequest( + apiRequest: ApiRequest, + info: ReconnectionHelpers.PersistedRequestInfo, + route: Route, + client: DropboxTransportClientInternal + ) -> DownloadRequestFile +} + +extension ReconnectionHelpersShared { + static func persistedRequestInfo(from apiRequest: ApiRequest) throws -> ReconnectionHelpers.PersistedRequestInfo { + guard let taskDescription = apiRequest.taskDescription else { + throw ReconnectionErrorKind.noPersistedInfo + } + guard try originalSdkVersion(fromJsonString: taskDescription) == DropboxClientsManager.sdkVersion else { + throw ReconnectionErrorKind.versionMismatch + } + + return try ReconnectionHelpers.PersistedRequestInfo.from(jsonString: taskDescription) + } + + static func originalSdkVersion(fromJsonString jsonString: String) throws -> String { + let components = jsonString.components(separatedBy: ReconnectionConstants.separator) + guard components.count == 2 else { + throw ReconnectionErrorKind.badPersistedStringFormat + } + return components[0] + } + + static func rebuildRequest( + apiRequest: ApiRequest, + info: ReconnectionHelpers.PersistedRequestInfo, + route: Route, + client: DropboxTransportClientInternal + ) -> UploadRequest { + if case .upload = info { + return client.reconnectRequest( + route, + apiRequest: apiRequest + ) + } else { + fatalError("codegen error, background request not an upload or download file request") + } + } + + static func rebuildRequest( + apiRequest: ApiRequest, + info: ReconnectionHelpers.PersistedRequestInfo, + route: Route, + client: DropboxTransportClientInternal + ) -> DownloadRequestFile { + if case .downloadFile(let info) = info { + return client.reconnectRequest( + route, + apiRequest: apiRequest, + overwrite: info.overwrite, + destination: info.destination + ) + } else { + fatalError("codegen error, background request not an upload or download file request") + } + } +} + +extension ReconnectionHelpers: ReconnectionHelpersShared {} +extension AppAuthReconnectionHelpers: ReconnectionHelpersShared {} +extension ReconnectionHelpers { enum PersistedRequestInfo: Codable, Equatable { case upload(StandardInfo) case downloadFile(DownloadFileInfo) @@ -52,11 +130,11 @@ extension ReconnectionHelpers { let jsonString = String(data: jsonData, encoding: .utf8) // We encode the SDK Version outside of the JSON so we can condition JSON decoding on a version match - return DropboxClientsManager.sdkVersion + Separator + (try jsonString.orThrow()) + return DropboxClientsManager.sdkVersion + ReconnectionConstants.separator + (try jsonString.orThrow()) } static func from(jsonString: String) throws -> Self { - let components = jsonString.components(separatedBy: Separator) + let components = jsonString.components(separatedBy: ReconnectionConstants.separator) guard components.count == 2 else { throw ReconnectionErrorKind.badPersistedStringFormat } @@ -96,57 +174,4 @@ extension ReconnectionHelpers { return self } } - - static func persistedRequestInfo(from apiRequest: ApiRequest) throws -> PersistedRequestInfo { - guard let taskDescription = apiRequest.taskDescription else { - throw ReconnectionErrorKind.noPersistedInfo - } - guard try originalSdkVersion(fromJsonString: taskDescription) == DropboxClientsManager.sdkVersion else { - throw ReconnectionErrorKind.versionMismatch - } - - return try PersistedRequestInfo.from(jsonString: taskDescription) - } - - static func originalSdkVersion(fromJsonString jsonString: String) throws -> String { - let components = jsonString.components(separatedBy: Separator) - guard components.count == 2 else { - throw ReconnectionErrorKind.badPersistedStringFormat - } - return components[0] - } - - static func rebuildRequest( - apiRequest: ApiRequest, - info: PersistedRequestInfo, - route: Route, - client: DropboxTransportClientInternal - ) -> UploadRequest { - if case .upload = info { - return client.reconnectRequest( - route, - apiRequest: apiRequest - ) - } else { - fatalError("codegen error, background request not an upload or download file request") - } - } - - static func rebuildRequest( - apiRequest: ApiRequest, - info: PersistedRequestInfo, - route: Route, - client: DropboxTransportClientInternal - ) -> DownloadRequestFile { - if case .downloadFile(let info) = info { - return client.reconnectRequest( - route, - apiRequest: apiRequest, - overwrite: info.overwrite, - destination: info.destination - ) - } else { - fatalError("codegen error, background request not an upload or download file request") - } - } } diff --git a/Source/SwiftyDropboxObjC/Platform/SwiftyDropbox_iOS/DBXOAuthMobile.swift b/Source/SwiftyDropboxObjC/Platform/SwiftyDropbox_iOS/DBXOAuthMobile.swift index ee11bded..7926e74d 100644 --- a/Source/SwiftyDropboxObjC/Platform/SwiftyDropbox_iOS/DBXOAuthMobile.swift +++ b/Source/SwiftyDropboxObjC/Platform/SwiftyDropbox_iOS/DBXOAuthMobile.swift @@ -17,7 +17,7 @@ extension DBXDropboxClientsManager { /// /// - Parameters: /// - sharedApplication: The shared UIApplication instance in your app. - /// - controller: A UIViewController to present the auth flow from. Reference is weakly held. + /// - controller: A UIViewController to present the auth flow from. This should be the top-most view controller. Reference is weakly held. /// - openURL: Handler to open a URL. @objc @available( @@ -43,7 +43,7 @@ extension DBXDropboxClientsManager { /// /// - Parameters: /// - sharedApplication: The shared UIApplication instance in your app. - /// - controller: A UIViewController to present the auth flow from. Reference is weakly held. + /// - controller: A UIViewController to present the auth flow from. This should be the top-most view controller. Reference is weakly held. /// - loadingStatusDelegate: An optional delegate to handle loading experience during auth flow. /// e.g. Show a loading spinner and block user interaction while loading/waiting. /// If a delegate is not provided, the SDK will show a default loading spinner when necessary. diff --git a/Source/SwiftyDropboxObjC/Shared/Generated/DBXBaseApp.swift b/Source/SwiftyDropboxObjC/Shared/Generated/DBXBaseApp.swift index b4d214fe..773248df 100644 --- a/Source/SwiftyDropboxObjC/Shared/Generated/DBXBaseApp.swift +++ b/Source/SwiftyDropboxObjC/Shared/Generated/DBXBaseApp.swift @@ -19,6 +19,12 @@ public class DBXDropboxAppBase: NSObject { /// Routes within the check namespace. See DBCheckAppAuthRoutes for details. @objc public var check: DBXCheckAppAuthRoutes! + /// Routes within the files namespace. See DBFilesAppAuthRoutes for details. + @objc + public var files: DBXFilesAppAuthRoutes! + /// Routes within the sharing namespace. See DBSharingAppAuthRoutes for details. + @objc + public var sharing: DBXSharingAppAuthRoutes! @objc public convenience init(client: DBXDropboxTransportClient) { @@ -30,5 +36,7 @@ public class DBXDropboxAppBase: NSObject { self.auth = DBXAuthAppAuthRoutes(swift: swift.auth) self.check = DBXCheckAppAuthRoutes(swift: swift.check) + self.files = DBXFilesAppAuthRoutes(swift: swift.files) + self.sharing = DBXSharingAppAuthRoutes(swift: swift.sharing) } } diff --git a/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxAppBaseRequestBox.swift b/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxAppBaseRequestBox.swift new file mode 100644 index 00000000..55e44a45 --- /dev/null +++ b/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxAppBaseRequestBox.swift @@ -0,0 +1,17 @@ +/// +/// Copyright (c) 2022 Dropbox, Inc. All rights reserved. +/// +/// Auto-generated by Stone, do not modify. +/// + +import Foundation +import SwiftyDropbox + +extension DropboxAppBaseRequestBox { + var objc: DBXRequest { + switch self { + case .getThumbnailV2(let swift): + return DBXFilesGetThumbnailDownloadRequestFileV2(swift: swift) + } + } +} diff --git a/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxBaseRequestBox.swift b/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxBaseRequestBox.swift index 2cfe4f10..47baefa2 100644 --- a/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxBaseRequestBox.swift +++ b/Source/SwiftyDropboxObjC/Shared/Generated/DBXDropboxBaseRequestBox.swift @@ -46,8 +46,6 @@ extension DropboxBaseRequestBox { return DBXPaperDocsUpdateUploadRequest(swift: swift) case .getSharedLinkFile(let swift): return DBXSharingGetSharedLinkFileDownloadRequestFile(swift: swift) - default: - fatalError("For Obj-C compatibility, add this route to the Objective-C compatibility module allow-list") } } } diff --git a/Source/SwiftyDropboxObjC/Shared/Generated/DBXFilesAppAuthRoutes.swift b/Source/SwiftyDropboxObjC/Shared/Generated/DBXFilesAppAuthRoutes.swift new file mode 100644 index 00000000..2dbc9877 --- /dev/null +++ b/Source/SwiftyDropboxObjC/Shared/Generated/DBXFilesAppAuthRoutes.swift @@ -0,0 +1,225 @@ +/// +/// Copyright (c) 2022 Dropbox, Inc. All rights reserved. +/// +/// Auto-generated by Stone, do not modify. +/// + +import Foundation +import SwiftyDropbox + +/// Objective-C compatible routes for the files namespace +/// For Swift routes see FilesAppAuthRoutes +@objc +public class DBXFilesAppAuthRoutes: NSObject { + private let swift: FilesAppAuthRoutes + init(swift: FilesAppAuthRoutes) { + self.swift = swift + self.client = swift.client.objc + } + + public let client: DBXDropboxTransportClient + + /// Get a thumbnail for an image. This method currently supports files with the following file extensions: jpg, + /// jpeg, png, tiff, tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size won't be converted to + /// a thumbnail. + /// + /// - scope: files.content.read + /// + /// - parameter resource: Information specifying which file to preview. This could be a path to a file, a shared + /// link pointing to a file, or a shared link pointing to a folder, with a relative path. + /// - parameter format: The format for the thumbnail image, jpeg (default) or png. For images that are photos, jpeg + /// should be preferred, while png is better for screenshots and digital arts. + /// - parameter size: The size for the thumbnail image. + /// - parameter mode: How to resize and crop the image to achieve the desired size. + /// - parameter overwrite: A boolean to set behavior in the event of a naming conflict. `True` will overwrite + /// conflicting file at destination. `False` will take no action (but if left unhandled in destination closure, + /// an NSError will be thrown). + /// - parameter destination: The location to write the download to. + /// + /// - returns: Through the response callback, the caller will receive a `Files.PreviewResult` object on success or a + /// `Files.ThumbnailV2Error` object on failure. + @objc + @discardableResult public func getThumbnailV2URL( + resource: DBXFilesPathOrLink, + format: DBXFilesThumbnailFormat, + size: DBXFilesThumbnailSize, + mode: DBXFilesThumbnailMode, + overwrite: Bool, + destination: URL + ) -> DBXFilesGetThumbnailDownloadRequestFileV2 { + let swift = swift.getThumbnailV2( + resource: resource.swift, + format: format.swift, + size: size.swift, + mode: mode.swift, + overwrite: overwrite, + destination: destination + ) + return DBXFilesGetThumbnailDownloadRequestFileV2(swift: swift) + } + + /// Get a thumbnail for an image. This method currently supports files with the following file extensions: jpg, + /// jpeg, png, tiff, tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size won't be converted to + /// a thumbnail. + /// + /// - scope: files.content.read + /// + /// - returns: Through the response callback, the caller will receive a `Files.PreviewResult` object on success or a + /// `Files.ThumbnailV2Error` object on failure. + @objc + @discardableResult public func getThumbnailV2URL( + resource: DBXFilesPathOrLink, + overwrite: Bool, + destination: URL + ) -> DBXFilesGetThumbnailDownloadRequestFileV2 { + let swift = swift.getThumbnailV2(resource: resource.swift, overwrite: overwrite, destination: destination) + return DBXFilesGetThumbnailDownloadRequestFileV2(swift: swift) + } + + /// Get a thumbnail for an image. This method currently supports files with the following file extensions: jpg, + /// jpeg, png, tiff, tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size won't be converted to + /// a thumbnail. + /// + /// - scope: files.content.read + /// + /// - parameter resource: Information specifying which file to preview. This could be a path to a file, a shared + /// link pointing to a file, or a shared link pointing to a folder, with a relative path. + /// - parameter format: The format for the thumbnail image, jpeg (default) or png. For images that are photos, jpeg + /// should be preferred, while png is better for screenshots and digital arts. + /// - parameter size: The size for the thumbnail image. + /// - parameter mode: How to resize and crop the image to achieve the desired size. + /// + /// - returns: Through the response callback, the caller will receive a `Files.PreviewResult` object on success or a + /// `Files.ThumbnailV2Error` object on failure. + @objc + @discardableResult public func getThumbnailV2( + resource: DBXFilesPathOrLink, + format: DBXFilesThumbnailFormat, + size: DBXFilesThumbnailSize, + mode: DBXFilesThumbnailMode + ) -> DBXFilesGetThumbnailDownloadRequestMemoryV2 { + let swift = swift.getThumbnailV2(resource: resource.swift, format: format.swift, size: size.swift, mode: mode.swift) + return DBXFilesGetThumbnailDownloadRequestMemoryV2(swift: swift) + } + + /// Get a thumbnail for an image. This method currently supports files with the following file extensions: jpg, + /// jpeg, png, tiff, tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size won't be converted to + /// a thumbnail. + /// + /// - scope: files.content.read + /// + /// - returns: Through the response callback, the caller will receive a `Files.PreviewResult` object on success or a + /// `Files.ThumbnailV2Error` object on failure. + @objc + @discardableResult public func getThumbnailV2(resource: DBXFilesPathOrLink) -> DBXFilesGetThumbnailDownloadRequestMemoryV2 { + let swift = swift.getThumbnailV2(resource: resource.swift) + return DBXFilesGetThumbnailDownloadRequestMemoryV2(swift: swift) + } + + /// Starts returning the contents of a folder. If the result's hasMore in ListFolderResult field is true, call + /// listFolderContinue with the returned cursor in ListFolderResult to retrieve more entries. If you're using + /// recursive in ListFolderArg set to true to keep a local cache of the contents of a Dropbox account, iterate + /// through each entry in order and process them as follows to keep your local state in sync: For each + /// FileMetadata, store the new entry at the given path in your local state. If the required parent folders + /// don't exist yet, create them. If there's already something else at the given path, replace it and remove all + /// its children. For each FolderMetadata, store the new entry at the given path in your local state. If the + /// required parent folders don't exist yet, create them. If there's already something else at the given path, + /// replace it but leave the children as they are. Check the new entry's readOnly in FolderSharingInfo and set + /// all its children's read-only statuses to match. For each DeletedMetadata, if your local state has something + /// at the given path, remove it and all its children. If there's nothing at the given path, ignore this entry. + /// Note: auth.RateLimitError may be returned if multiple listFolder or listFolderContinue calls with same + /// parameters are made simultaneously by same API app for same user. If your app implements retry logic, please + /// hold off the retry until the previous request finishes. + /// + /// - scope: files.metadata.read + /// + /// - parameter path: A unique identifier for the file. + /// - parameter recursive: If true, the list folder operation will be applied recursively to all subfolders and the + /// response will contain contents of all subfolders. + /// - parameter includeMediaInfo: If true, mediaInfo in FileMetadata is set for photo and video. This parameter will + /// no longer have an effect starting December 2, 2019. + /// - parameter includeDeleted: If true, the results will include entries for files and folders that used to exist + /// but were deleted. + /// - parameter includeHasExplicitSharedMembers: If true, the results will include a flag for each file indicating + /// whether or not that file has any explicit members. + /// - parameter includeMountedFolders: If true, the results will include entries under mounted folders which + /// includes app folder, shared folder and team folder. + /// - parameter limit: The maximum number of results to return per request. Note: This is an approximate number and + /// there can be slightly more entries returned in some cases. + /// - parameter sharedLink: A shared link to list the contents of. If the link is password-protected, the password + /// must be provided. If this field is present, path in ListFolderArg will be relative to root of the shared + /// link. Only non-recursive mode is supported for shared link. + /// - parameter includePropertyGroups: If set to a valid list of template IDs, propertyGroups in FileMetadata is set + /// if there exists property data associated with the file and each of the listed templates. + /// - parameter includeNonDownloadableFiles: If true, include files that are not downloadable, i.e. Google Docs. + /// + /// - returns: Through the response callback, the caller will receive a `Files.ListFolderResult` object on success + /// or a `Files.ListFolderError` object on failure. + @objc + @discardableResult public func listFolder( + path: String, + recursive: NSNumber, + includeMediaInfo: NSNumber, + includeDeleted: NSNumber, + includeHasExplicitSharedMembers: NSNumber, + includeMountedFolders: NSNumber, + limit: NSNumber?, + sharedLink: DBXFilesSharedLink?, + includePropertyGroups: DBXFilePropertiesTemplateFilterBase?, + includeNonDownloadableFiles: NSNumber + ) -> DBXFilesListFolderRpcRequest { + let swift = swift.listFolder( + path: path, + recursive: recursive.boolValue, + includeMediaInfo: includeMediaInfo.boolValue, + includeDeleted: includeDeleted.boolValue, + includeHasExplicitSharedMembers: includeHasExplicitSharedMembers.boolValue, + includeMountedFolders: includeMountedFolders.boolValue, + limit: limit?.uint32Value, + sharedLink: sharedLink?.swift, + includePropertyGroups: includePropertyGroups?.swift, + includeNonDownloadableFiles: includeNonDownloadableFiles.boolValue + ) + return DBXFilesListFolderRpcRequest(swift: swift) + } + + /// Starts returning the contents of a folder. If the result's hasMore in ListFolderResult field is true, call + /// listFolderContinue with the returned cursor in ListFolderResult to retrieve more entries. If you're using + /// recursive in ListFolderArg set to true to keep a local cache of the contents of a Dropbox account, iterate + /// through each entry in order and process them as follows to keep your local state in sync: For each + /// FileMetadata, store the new entry at the given path in your local state. If the required parent folders + /// don't exist yet, create them. If there's already something else at the given path, replace it and remove all + /// its children. For each FolderMetadata, store the new entry at the given path in your local state. If the + /// required parent folders don't exist yet, create them. If there's already something else at the given path, + /// replace it but leave the children as they are. Check the new entry's readOnly in FolderSharingInfo and set + /// all its children's read-only statuses to match. For each DeletedMetadata, if your local state has something + /// at the given path, remove it and all its children. If there's nothing at the given path, ignore this entry. + /// Note: auth.RateLimitError may be returned if multiple listFolder or listFolderContinue calls with same + /// parameters are made simultaneously by same API app for same user. If your app implements retry logic, please + /// hold off the retry until the previous request finishes. + /// + /// - scope: files.metadata.read + /// + /// - returns: Through the response callback, the caller will receive a `Files.ListFolderResult` object on success + /// or a `Files.ListFolderError` object on failure. + @objc + @discardableResult public func listFolder(path: String) -> DBXFilesListFolderRpcRequest { + let swift = swift.listFolder(path: path) + return DBXFilesListFolderRpcRequest(swift: swift) + } + + /// Once a cursor has been retrieved from listFolder, use this to paginate through all files and retrieve updates to + /// the folder, following the same rules as documented for listFolder. + /// + /// - scope: files.metadata.read + /// + /// - parameter cursor: The cursor returned by your last call to listFolder or listFolderContinue. + /// + /// - returns: Through the response callback, the caller will receive a `Files.ListFolderResult` object on success + /// or a `Files.ListFolderContinueError` object on failure. + @objc + @discardableResult public func listFolderContinue(cursor: String) -> DBXFilesListFolderContinueRpcRequest { + let swift = swift.listFolderContinue(cursor: cursor) + return DBXFilesListFolderContinueRpcRequest(swift: swift) + } +} diff --git a/Source/SwiftyDropboxObjC/Shared/Generated/DBXSharingAppAuthRoutes.swift b/Source/SwiftyDropboxObjC/Shared/Generated/DBXSharingAppAuthRoutes.swift new file mode 100644 index 00000000..5fcd60eb --- /dev/null +++ b/Source/SwiftyDropboxObjC/Shared/Generated/DBXSharingAppAuthRoutes.swift @@ -0,0 +1,50 @@ +/// +/// Copyright (c) 2022 Dropbox, Inc. All rights reserved. +/// +/// Auto-generated by Stone, do not modify. +/// + +import Foundation +import SwiftyDropbox + +/// Objective-C compatible routes for the sharing namespace +/// For Swift routes see SharingAppAuthRoutes +@objc +public class DBXSharingAppAuthRoutes: NSObject { + private let swift: SharingAppAuthRoutes + init(swift: SharingAppAuthRoutes) { + self.swift = swift + self.client = swift.client.objc + } + + public let client: DBXDropboxTransportClient + + /// Get the shared link's metadata. + /// + /// - scope: sharing.read + /// + /// - parameter url: URL of the shared link. + /// - parameter path: If the shared link is to a folder, this parameter can be used to retrieve the metadata for a + /// specific file or sub-folder in this folder. A relative path should be used. + /// - parameter linkPassword: If the shared link has a password, this parameter can be used. + /// + /// - returns: Through the response callback, the caller will receive a `Sharing.SharedLinkMetadata` object on + /// success or a `Sharing.SharedLinkError` object on failure. + @objc + @discardableResult public func getSharedLinkMetadata(url: String, path: String?, linkPassword: String?) -> DBXSharingGetSharedLinkMetadataRpcRequest { + let swift = swift.getSharedLinkMetadata(url: url, path: path, linkPassword: linkPassword) + return DBXSharingGetSharedLinkMetadataRpcRequest(swift: swift) + } + + /// Get the shared link's metadata. + /// + /// - scope: sharing.read + /// + /// - returns: Through the response callback, the caller will receive a `Sharing.SharedLinkMetadata` object on + /// success or a `Sharing.SharedLinkError` object on failure. + @objc + @discardableResult public func getSharedLinkMetadata(url: String) -> DBXSharingGetSharedLinkMetadataRpcRequest { + let swift = swift.getSharedLinkMetadata(url: url) + return DBXSharingGetSharedLinkMetadataRpcRequest(swift: swift) + } +} diff --git a/stone b/stone index 47534811..e5d99072 160000 --- a/stone +++ b/stone @@ -1 +1 @@ -Subproject commit 475348110f0bc3820032c7b966f5affb56f28ae3 +Subproject commit e5d990723484b5c41c0dd8cec93d7a9068035f6e