diff --git a/Sources/S3/Extensions/S3+Copy.swift b/Sources/S3/Extensions/S3+Copy.swift index 770b7e6..1fefdf4 100644 --- a/Sources/S3/Extensions/S3+Copy.swift +++ b/Sources/S3/Extensions/S3+Copy.swift @@ -8,10 +8,13 @@ import Foundation import Vapor + extension S3 { + // MARK: Copy + /// Copy file on S3 - public func copy(file: LocationConvertible, to: LocationConvertible, headers: [String: String], on container: Container) throws -> EventLoopFuture { + public func copy(file: LocationConvertible, to: LocationConvertible, headers: [String: String], on container: Container) throws -> Future { let builder = urlBuilder(for: container) let originPath = "\(file.bucket ?? defaultBucket)/\(file.path)" let destinationUrl = try builder.url(file: to) @@ -32,11 +35,10 @@ extension S3 { request.http.url = destinationUrl let client = try container.make(Client.self) - return client.send(request) - .map { - try self.check($0) - return try $0.decode(to: File.CopyResponse.self) - } + return client.send(request).map { + try self.check($0) + return try $0.decode(to: File.CopyResponse.self) + } } } diff --git a/Sources/S3/Extensions/S3+Move.swift b/Sources/S3/Extensions/S3+Move.swift new file mode 100644 index 0000000..de67935 --- /dev/null +++ b/Sources/S3/Extensions/S3+Move.swift @@ -0,0 +1,25 @@ +// +// S3+Copy.swift +// S3 +// +// Created by Ondrej Rafaj on 23/10/2018. +// + +import Foundation +import Vapor + + +extension S3 { + + // MARK: Move + + /// Copy file on S3 + public func move(file: LocationConvertible, to destination: LocationConvertible, headers: [String: String], on container: Container) throws -> EventLoopFuture { + return try copy(file: file, to: destination, headers: headers, on: container).flatMap(to: File.CopyResponse.self) { copyResult in + return try self.delete(file: file, on: container).map(to: File.CopyResponse.self) { _ in + return copyResult + } + } + } + +}