From aad7e34889110fd0a27e90e655e94a23020c8124 Mon Sep 17 00:00:00 2001 From: Valentin Corral Date: Thu, 27 Apr 2017 09:19:35 +0200 Subject: [PATCH] Updated to Vapor 2 --- Package.swift | 6 +++--- Sources/Storage/Provider.swift | 9 +++++---- Sources/Storage/Storage.swift | 36 +--------------------------------- Sources/Storage/Template.swift | 4 ++-- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/Package.swift b/Package.swift index 5e95e19..48b3a00 100644 --- a/Package.swift +++ b/Package.swift @@ -3,9 +3,9 @@ import PackageDescription let package = Package( name: "Storage", dependencies: [ - .Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1), - .Package(url: "https://github.com/nodes-vapor/data-uri.git", majorVersion: 0), - .Package(url: "https://github.com/nodes-vapor/aws.git", majorVersion: 0), + .Package(url: "https://github.com/vapor/vapor.git", Version(2,0,0, prereleaseIdentifiers: ["beta"])), + .Package(url: "https://github.com/nodes-vapor/data-uri.git", Version(1,0,0, prereleaseIdentifiers: ["beta"])), + .Package(url: "https://github.com/nodes-vapor/aws.git", Version(1,0,0, prereleaseIdentifiers: ["beta"])), .Package(url: "https://github.com/manGoweb/MimeLib.git", majorVersion: 1) ] ) diff --git a/Sources/Storage/Provider.swift b/Sources/Storage/Provider.swift index 0d315bf..fd06cc7 100644 --- a/Sources/Storage/Provider.swift +++ b/Sources/Storage/Provider.swift @@ -5,6 +5,9 @@ import enum AWSSignatureV4.Region ///A provider for configuring the `Storage` package. public final class StorageProvider: Provider { + + public static var repositoryName: String = "Storage" + public enum Error: Swift.Error { case missingConfigurationFile case unsupportedDriver(String) @@ -14,10 +17,6 @@ public final class StorageProvider: Provider { case unknownRegion(String) } - public var provided: Providable { - return Providable() - } - public init(config: Config) throws { guard let config = config["storage"] else { throw Error.missingConfigurationFile @@ -29,6 +28,8 @@ public final class StorageProvider: Provider { } public func boot(_ drop: Droplet) {} + + public func boot(_ config: Config) throws {} public func afterInit(_ drop: Droplet) {} diff --git a/Sources/Storage/Storage.swift b/Sources/Storage/Storage.swift index 7ab16c1..9689dac 100644 --- a/Sources/Storage/Storage.swift +++ b/Sources/Storage/Storage.swift @@ -10,7 +10,6 @@ public class Storage { public enum Error: Swift.Error { case missingNetworkDriver case cdnBaseURLNotSet - case unsupportedMultipart(Multipart) case missingFileName } @@ -36,39 +35,6 @@ public class Storage { return try networkDriver.upload(entity: &entity) } - /** - Uploads the given `Multipart` file. - - - Parameters: - - multipart: The file to be uploaded. - - folder: The folder to save the file in. - - - Returns: The path the file was uploaded to. - */ - @discardableResult - public static func upload( - multipart: Multipart, - folder: String? = nil - ) throws -> String { - switch multipart { - case .file(let file): - guard let name = file.name else { - throw Error.missingFileName - } - - return try upload( - bytes: file.data, - fileName: name, - fileExtension: nil, - mime: file.type, - folder: folder - ) - - default: - throw Error.unsupportedMultipart(multipart) - } - } - @discardableResult public static func upload( formData: Field, @@ -105,7 +71,7 @@ public class Storage { fileExtension: String? = nil, folder: String? = nil ) throws -> String { - let response = try BasicClient.get(url) + let response = try EngineClient.factory.get(url) var entity = FileEntity( fileName: fileName, fileExtension: fileExtension, diff --git a/Sources/Storage/Template.swift b/Sources/Storage/Template.swift index 949ad32..f649ced 100644 --- a/Sources/Storage/Template.swift +++ b/Sources/Storage/Template.swift @@ -145,7 +145,7 @@ extension Template { } } - return try String(bytes: pathBytes) + return String(bytes: pathBytes) } } @@ -215,7 +215,7 @@ extension Template { current = next } - let invalidAlias = try String(bytes: partial) + let invalidAlias = String(bytes: partial) throw Error.invalidAlias(invalidAlias) }