Skip to content

Commit

Permalink
first time compiling converted
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiki270 committed Apr 19, 2018
1 parent dad9267 commit 20c6634
Show file tree
Hide file tree
Showing 35 changed files with 936 additions and 535 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0
4.1
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016 JustinM1
Copyright (c) 2018 LiveUI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 16 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "ce64e70a48adf54835d040ba4c4dab431e2cd020",
"version": "3.1.1"
"revision": "c61a29ef08e7c8b3e836954269678c5a8fa31f3f",
"version": "3.1.2"
}
},
{
Expand All @@ -42,8 +42,8 @@
"repositoryURL": "https://github.com/vapor/engine.git",
"state": {
"branch": null,
"revision": "2419e37d689b78c9197b2f38cd8f2901cd7dcf9e",
"version": "3.0.0-rc.2.3.1"
"revision": "bcc330e964a0a294afb9c829b6e6b4626cdea427",
"version": "3.0.0-rc.2.4"
}
},
{
Expand Down Expand Up @@ -118,6 +118,15 @@
"version": "1.0.0"
}
},
{
"package": "URLEncodedForm",
"repositoryURL": "https://github.com/vapor/url-encoded-form.git",
"state": {
"branch": null,
"revision": "aca8efc7176f3ea2352dcbcd32526f82af5647c3",
"version": "1.0.1"
}
},
{
"package": "Validation",
"repositoryURL": "https://github.com/vapor/validation.git",
Expand All @@ -132,16 +141,16 @@
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "26b5c4032f236cc78e6fd3a51ac6d8aceb5a3a4f",
"version": "3.0.0-rc.2.4.1"
"revision": "752e6a6c392f18e4986e2251c5db76fd7f79d4e9",
"version": "3.0.0-rc.2.5"
}
},
{
"package": "VaporTestTools",
"repositoryURL": "https://github.com/LiveUI/VaporTestTools.git",
"state": {
"branch": "master",
"revision": "0791548a30e6a805bf9291b0ad6707c4085cc3ee",
"revision": "2b8aa260f6f7faf001d52cae1189d33274886498",
"version": null
}
}
Expand Down
6 changes: 0 additions & 6 deletions Sources/S3/Dates.swift

This file was deleted.

18 changes: 18 additions & 0 deletions Sources/S3/Extensions/Container+S3.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Container+S3.swift
// S3
//
// Created by Ondrej Rafaj on 19/04/2018.
//

import Foundation
import Vapor


extension Container {

public func makeS3Client() throws -> S3Client {
return try make()
}

}
22 changes: 22 additions & 0 deletions Sources/S3/Extensions/Region+Tools.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Region+Tools.swift
// S3Signer
//
// Created by Ondrej Rafaj on 19/04/2018.
//

import Foundation
@_exported import S3Signer


extension Region {

public func urlString(bucket: String) -> String {
return host + bucket
}

public func url(bucket: String) -> URL? {
return URL(string: urlString(bucket: bucket))
}

}
27 changes: 27 additions & 0 deletions Sources/S3/Extensions/S3+Private.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// S3+Private.swift
// S3
//
// Created by Ondrej Rafaj on 19/04/2018.
//

import Foundation
import Vapor
import HTTP


extension S3 {

func make(request url: URL, method: HTTPMethod, headers: HTTPHeaders, data: Data? = nil, on req: Request) throws -> Future<Response> {
let client = try req.make(Client.self)
let request = Request(using: req.privateContainer)
request.http.method = method
request.http.headers = headers
if let data = data {
request.http.body = HTTPBody(data: data)
}
request.http.url = url
return try client.respond(to: request)
}

}
20 changes: 20 additions & 0 deletions Sources/S3/Extensions/Service+S3.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Service+S3.swift
// S3Signer
//
// Created by Ondrej Rafaj on 19/04/2018.
//

import Foundation
import Service
@_exported import S3Signer


extension Services {

/// Convenience method to register both S3Signer and S3Client
public mutating func register(s3 config: S3Signer.Config, defaultBucket: String) throws {
try S3.init(defaultBucket: defaultBucket, config: config, services: &self)
}

}
17 changes: 17 additions & 0 deletions Sources/S3/Protocols/FileInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// FileInfo.swift
// S3
//
// Created by Ondrej Rafaj on 19/04/2018.
//

import Foundation


public protocol FileInfo {
/// Override target bucket
var bucket: String? { get }

/// S3 file path
var path: String { get }
}
19 changes: 19 additions & 0 deletions Sources/S3/Protocols/S3Client.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// S3Signer.swift
// S3
//
// Created by Ondrej Rafaj on 18/04/2018.
//

import Foundation
import Vapor


public protocol S3Client: Service {
func put(file: S3.File.Upload, headers: [String: String], on req: Request) throws -> EventLoopFuture<S3.File.Response>
func put(file url: URL, destination: String, bucket: String?, access: S3.AccessControlList, on req: Request) throws -> Future<S3.File.Response>
func put(file path: String, destination: String, bucket: String?, access: S3.AccessControlList, on req: Request) throws -> Future<S3.File.Response>
func put(string: String, mime: MediaType, destination: String, bucket: String?, access: S3.AccessControlList, on req: Request) throws -> Future<S3.File.Response>
func get(file: S3.File.Location, headers: [String: String], on req: Request) throws -> Future<S3.File.Response>
func delete(file: S3.File.Location, headers: [String: String], on req: Request) throws -> Future<Void>
}
29 changes: 29 additions & 0 deletions Sources/S3/S3+Files.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// S3+Files.swift
// S3
//
// Created by Ondrej Rafaj on 01/12/2016.
// Copyright © 2016 manGoweb UK Ltd. All rights reserved.
//

import Foundation
import Vapor


// Helper S3 extension for uploading files by their URL/path
public extension S3 {

/// Upload file by it's URL to S3, full set
public func put(file url: URL, destination: String, bucket: String? = nil, access: AccessControlList = .privateAccess, on req: Request) throws -> Future<File.Response> {
let data: Data = try Data(contentsOf: url)
let file = File.Upload(data: data, bucket: bucket, destination: destination, access: access, mime: mimeType(forFileAtUrl: url))
return try put(file: file, on: req)
}

/// Upload file by it's path to S3, full set
public func put(file path: String, destination: String, bucket: String? = nil, access: AccessControlList = .privateAccess, on req: Request) throws -> Future<File.Response> {
let url: URL = URL(fileURLWithPath: path)
return try put(file: url, destination: destination, bucket: bucket, access: access, on: req)
}

}
24 changes: 24 additions & 0 deletions Sources/S3/S3+Strings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// S3+Strings.swift
// S3
//
// Created by Ondrej Rafaj on 01/12/2016.
// Copyright © 2016 manGoweb UK Ltd. All rights reserved.
//

import Foundation
import Vapor


public extension S3 {

/// Upload file content to S3, full set
public func put(string: String, mime: MediaType = .plainText, destination: String, bucket: String? = nil, access: AccessControlList = .privateAccess, on req: Request) throws -> Future<File.Response> {
guard let data: Data = string.data(using: String.Encoding.utf8) else {
throw Error.badStringData
}
let file = File.Upload(data: data, bucket: bucket, destination: destination, access: access, mime: mime)
return try put(file: file, on: req)
}

}
Loading

0 comments on commit 20c6634

Please sign in to comment.