Skip to content

Commit

Permalink
优化 S3
Browse files Browse the repository at this point in the history
  • Loading branch information
gee1k committed Aug 14, 2020
1 parent c102fb4 commit dd70340
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
16 changes: 8 additions & 8 deletions uPic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20200728;
CURRENT_PROJECT_VERSION = 20200814;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist";
Expand All @@ -1256,7 +1256,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 0.19.6;
MARKETING_VERSION = 0.20.0;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1277,7 +1277,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20200728;
CURRENT_PROJECT_VERSION = 20200814;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist";
Expand All @@ -1286,7 +1286,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 0.19.6;
MARKETING_VERSION = 0.20.0;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1303,7 +1303,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20200728;
CURRENT_PROJECT_VERSION = 20200814;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = uPicFinderExtension/Info.plist;
Expand All @@ -1313,7 +1313,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 0.19.6;
MARKETING_VERSION = 0.20.0;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.uPicFinderExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1330,7 +1330,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 20200728;
CURRENT_PROJECT_VERSION = 20200814;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = uPicFinderExtension/Info.plist;
Expand All @@ -1340,7 +1340,7 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.12;
MARKETING_VERSION = 0.19.6;
MARKETING_VERSION = 0.20.0;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.uPicFinderExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
9 changes: 8 additions & 1 deletion uPic/Models/S3/S3Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class S3Region {
"ap-southeast-1": ["cname": "亚太区域(新加坡)", "name": "Asia Pacific (Singapore)"],
"ap-southeast-2": ["cname": "亚太区域(悉尼)", "name": "Asia Pacific (Sydney)"],
"ap-northeast-1": ["cname": "亚太区域(东京)", "name": "Asia Pacific (Tokyo)"],
"ap-northeast-3": ["cname": "亚太区域 (大阪当地)", "name": "Asia Pacific (Osaka-Local)"],
"ap-east-1": ["cname": "亚太地区(香港)", "name": "Asia Pacific (Hong Kong)"],
"ca-central-1": ["cname": "加拿大 (中部)", "name": "Canada (Central)"],
"eu-west-1": ["cname": "欧洲(爱尔兰)", "name": "Europe (Ireland)"],
Expand All @@ -34,7 +35,10 @@ public class S3Region {
"eu-south-1": ["cname": "欧洲(米兰)", "name": "Europe (Milan)"],
"sa-east-1": ["cname": "南美洲(圣保罗)", "name": "South America (São Paulo)"],
"me-south-1": ["cname": "中东(巴林)", "name": "Middle East (Bahrain)"],
"af-south-1": ["cname": "非洲(开普敦)", "name": "Africa (Cape Town)"]
"af-south-1": ["cname": "非洲(开普敦)", "name": "Africa (Cape Town)"],
// 中国
"cn-north-1": ["cname": "中国(北京)", "name": "China (Beijing)"],
"cn-northwest-1": ["cname": "中国 (宁夏)", "name": "China (Ningxia)"]
]

public static func name(_ key: String) -> String {
Expand All @@ -54,6 +58,9 @@ public class S3Region {
if key.isEmpty {
return ""
}
if key == "cn-north-1" || key == "cn-northwest-1" {
return "s3.\(key).amazonaws.com.cn"
}
return "s3.\(key).amazonaws.com"
}

Expand Down
11 changes: 8 additions & 3 deletions uPic/Models/S3/S3Uploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ class S3Uploader: BaseUploader {

let customize = config.customize
let bucket = config.bucket
let endpoint = config.endpoint
let accessKey = config.accessKey
let secretKey = config.secretKey
let domain = config.domain
let region = AWSSDKSwiftCore.Region(rawValue: config.region)

var endpoint = config.endpoint

if !customize {
endpoint = S3Region.endPoint(config.region)
}

let saveKeyPath = config.saveKeyPath

let url = S3Util.computeUrl(bucket: bucket, region: config.region, endpoint: customize ? endpoint : nil)
let url = S3Util.computeUrl(bucket: bucket, region: config.region, customize: customize, endpoint: endpoint)

if url.isEmpty {
super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized)
Expand All @@ -62,7 +67,7 @@ class S3Uploader: BaseUploader {

let suffix = BaseUploaderUtil._parseVariables(config.suffix, fileName, otherVariables: nil)

let s3 = S3(accessKeyId: accessKey, secretAccessKey: secretKey, region: region, endpoint: customize ? endpoint : nil)
let s3 = S3(accessKeyId: accessKey, secretAccessKey: secretKey, region: region, endpoint: S3Util.computedS3Endpoint(endpoint))

let putObjectRequest = S3.PutObjectRequest(acl: .publicRead, body: bodyData, bucket: bucket, contentLength: Int64(bodyData.count), contentType: mimeType, key: saveKey)
let put = s3.putObject(putObjectRequest)
Expand Down
12 changes: 10 additions & 2 deletions uPic/Models/S3/S3Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import SwiftyJSON
public class S3Util {
private static let schema = "https://"

static func computeUrl(bucket: String, region: String, endpoint: String?) -> String {
static func computeUrl(bucket: String, region: String, customize: Bool, endpoint: String?) -> String {

if let endpoint = endpoint {
if customize, let endpoint = endpoint {
if (endpoint.last == "/") {
return "\(endpoint)\(bucket)"
}
Expand All @@ -24,4 +24,12 @@ public class S3Util {
return "\(schema)\(bucket).\(cEndpoint)"
}
}

static func computedS3Endpoint(_ endpoint: String?) -> String? {
if var point = endpoint, URL(string: point)?.scheme == nil {
point = schema + point
return point
}
return endpoint
}
}
4 changes: 4 additions & 0 deletions uPic/PreferencesWindow/HostPreferencesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class HostPreferencesViewController: PreferencesViewController {
self.refreshButtonStatus()
self.initHostItems()
self.addObserver()

DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
self.setDefaultSelectedHost()
}
}

override func viewDidDisappear() {
Expand Down

0 comments on commit dd70340

Please sign in to comment.