-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from evandcoleman/release/0.2.0
Add S3 cache engine
- Loading branch information
Showing
9 changed files
with
144 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import Combine | ||
import Foundation | ||
import PathKit | ||
|
||
public struct S3CacheEngine: HTTPCacheEngineProtocol, Decodable, Equatable { | ||
|
||
public let bucket: String | ||
public let path: String? | ||
public let cdnUrl: URL? | ||
|
||
public var uploadBaseUrl: URL { | ||
return bucketS3Url | ||
} | ||
|
||
public var downloadBaseUrl: URL { | ||
return bucketUrl | ||
} | ||
|
||
public let urlSession: URLSession = .createWithExtensionsSupport() | ||
|
||
private var bucketUrl: URL { | ||
if let url = cdnUrl { | ||
if let path = path { | ||
return url | ||
.appendingPathComponent(path) | ||
} else { | ||
return url | ||
} | ||
} else { | ||
return bucketS3Url | ||
} | ||
} | ||
|
||
private var bucketS3Url: URL { | ||
let baseUrl = URL(string: "https://\(bucket).s3.amazonaws.com")! | ||
|
||
if let path = path { | ||
return baseUrl | ||
.appendingPathComponent(path) | ||
} else { | ||
return baseUrl | ||
} | ||
} | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case bucket | ||
case path | ||
case cdnUrl | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters