Skip to content

Commit

Permalink
Merge pull request #26 from LiveUI/development
Browse files Browse the repository at this point in the history
adding move
  • Loading branch information
rafiki270 authored Oct 23, 2018
2 parents b69b387 + 3aaeef5 commit 1f911e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Sources/S3/Extensions/S3+Copy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<File.CopyResponse> {
public func copy(file: LocationConvertible, to: LocationConvertible, headers: [String: String], on container: Container) throws -> Future<File.CopyResponse> {
let builder = urlBuilder(for: container)
let originPath = "\(file.bucket ?? defaultBucket)/\(file.path)"
let destinationUrl = try builder.url(file: to)
Expand All @@ -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)
}
}

}
25 changes: 25 additions & 0 deletions Sources/S3/Extensions/S3+Move.swift
Original file line number Diff line number Diff line change
@@ -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<File.CopyResponse> {
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
}
}
}

}

0 comments on commit 1f911e5

Please sign in to comment.