Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding move #26

Merged
merged 1 commit into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}

}