Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gee1k committed Aug 15, 2019
2 parents a0909b1 + 7404bba commit 5571041
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 75 deletions.
10 changes: 7 additions & 3 deletions uPic/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ extension AppDelegate {

// 注册拖拽文件格式支持。使其支持浏览器拖拽的URL、tiff。以及Safari 有些情况(例如,百度搜图,在默认搜索列表。不进入详情时)下拖拽的时候获取到的是图片URL字符串
if #available(OSX 10.13, *) {
button.window?.registerForDraggedTypes([.URL, .fileURL, .string])
button.window?.registerForDraggedTypes([.URL, .fileURL, .string, .html])
} else {
// Fallback on earlier versions
button.window?.registerForDraggedTypes([.png, .tiff, .pdf, .string])
button.window?.registerForDraggedTypes([.png, .tiff, .pdf, .string, .html])
}

}
Expand Down Expand Up @@ -372,7 +372,11 @@ extension AppDelegate {
outputUrl = "<img src='\(url)'/>"
break
case 2:
outputUrl = "![pic](\(url))"
outputUrl = "![](\(url))"
break
case 3:
// UBB
outputUrl = "[img]\(url)[/img]"
break
default:
outputUrl = url
Expand Down
54 changes: 30 additions & 24 deletions uPic/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,15 @@
<action selector="ouputFormatMenuItemClicked:" target="veO-oa-UPB" id="Xxd-x1-2BP"/>
</connections>
</menuItem>
<menuItem title="UBB" tag="3" id="Hz2-gj-luo">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="ouputFormatMenuItemClicked:" target="veO-oa-UPB" id="BYo-1k-amH"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="ijd-GZ-VTQ"/>
<menuItem title="上传前压缩图片" id="eIU-EA-uQZ">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="上传前压缩图片" id="4yH-6k-LD0"/>
Expand Down Expand Up @@ -199,34 +204,35 @@
<action selector="guideMenuItemClicked:" target="veO-oa-UPB" id="PRm-Bb-SKG"/>
</connections>
</menuItem>
<menuItem title="赞助" id="yCF-Ec-Lgz">
</items>
</menu>
</menuItem>
<menuItem title="赞助" id="yCF-Ec-Lgz">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="赞助" id="iGe-NR-YFa">
<items>
<menuItem title="Paypal" id="70g-zL-O4p">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="赞助" id="iGe-NR-YFa">
<items>
<menuItem title="Paypal" id="70g-zL-O4p">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="paypalMenuItemClicked:" target="veO-oa-UPB" id="G5h-aO-WVm"/>
</connections>
</menuItem>
<menuItem title="支付宝(Alipay)" id="aHw-Zc-eD7">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="alipayMenuItemClicked:" target="veO-oa-UPB" id="SQA-fB-WmZ"/>
</connections>
</menuItem>
<menuItem title="微信(WeChat)" id="Qky-3r-Bgs">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="wechatPayMenuItemClicked:" target="veO-oa-UPB" id="vzQ-HN-NXw"/>
</connections>
</menuItem>
</items>
</menu>
<connections>
<action selector="paypalMenuItemClicked:" target="veO-oa-UPB" id="G5h-aO-WVm"/>
</connections>
</menuItem>
<menuItem title="支付宝(Alipay)" id="aHw-Zc-eD7">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="alipayMenuItemClicked:" target="veO-oa-UPB" id="SQA-fB-WmZ"/>
</connections>
</menuItem>
<menuItem title="微信(WeChat)" id="Qky-3r-Bgs">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="wechatPayMenuItemClicked:" target="veO-oa-UPB" id="vzQ-HN-NXw"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem isSeparatorItem="YES" id="M7L-b9-8Hc"/>
<menuItem title="退出" keyEquivalent="q" id="0JF-m2-1iq">
<connections>
<action selector="quitMenuItemClicked:" target="veO-oa-UPB" id="e0d-Ue-lUF"/>
Expand Down
47 changes: 27 additions & 20 deletions uPic/Models/Aliyun/AliyunRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ import Foundation

class AliyunRegionDict {
static let allRegion = [
"cn_hangzhou": ["name": "华东 1", "endPoint": "oss-cn-hangzhou.aliyuncs.com"],
"cn_shanghai": ["name": "华东 2", "endPoint": "oss-cn-shanghai.aliyuncs.com"],
"cn_qingdao": ["name": "华北 1", "endPoint": "oss-cn-qingdao.aliyuncs.com"],
"cn_beijing": ["name": "华北 2", "endPoint": "oss-cn-beijing.aliyuncs.com"],
"cn_zhangjiakou": ["name": "华北 3", "endPoint": "oss-cn-zhangjiakou.aliyuncs.com"],
"cn_huhehaote": ["name": "华北 5", "endPoint": "oss-cn-huhehaote.aliyuncs.com"],
"cn_shenzhen": ["name": "华南 1", "endPoint": "oss-cn-shenzhen.aliyuncs.com"],
"cn_hongkong": ["name": "香港", "endPoint": "oss-cn-hongkong.aliyuncs.com"],
"us_west_1": ["name": "美国西部 1(硅谷)", "endPoint": "oss-us-west-1.aliyuncs.com"],
"us_east_1": ["name": "美国东部 1(弗吉尼亚)", "endPoint": "oss-us-east-1.aliyuncs.com"],
"ap_southeast_1": ["name": "亚太东南 1(新加坡)", "endPoint": "oss-ap-southeast-1.aliyuncs.com"],
"ap_southeast_2": ["name": "亚太东南 2(悉尼)", "endPoint": "oss-ap-southeast-2.aliyuncs.com"],
"ap_southeast_3": ["name": "亚太东南 3(吉隆坡)", "endPoint": "oss-ap-southeast-3.aliyuncs.com"],
"ap_southeast_5": ["name": "亚太东南 5 (雅加达)", "endPoint": "oss-ap-southeast-5.aliyuncs.com"],
"ap_northeast_1": ["name": "亚太东北 1 (日本)", "endPoint": "oss-ap-northeast-1.aliyuncs.com"],
"ap_south_1": ["name": "亚太南部 1 (孟买)", "endPoint": "oss-ap-south-1.aliyuncs.com"],
"eu_central_1": ["name": "欧洲中部 1 (法兰克福)", "endPoint": "oss-eu-central-1.aliyuncs.com"],
"eu_west_1": ["name": "英国(伦敦)", "endPoint": "oss-eu-west-1.aliyuncs.com"],
"me_east_1": ["name": "中东东部 1 (迪拜)", "endPoint": "oss-me-east-1.aliyuncs.com"]
"cn_hangzhou": ["name": "华东 1", "endPoint": "oss-cn-hangzhou"],
"cn_shanghai": ["name": "华东 2", "endPoint": "oss-cn-shanghai"],
"cn_qingdao": ["name": "华北 1", "endPoint": "oss-cn-qingdao"],
"cn_beijing": ["name": "华北 2", "endPoint": "oss-cn-beijing"],
"cn_zhangjiakou": ["name": "华北 3", "endPoint": "oss-cn-zhangjiakou"],
"cn_huhehaote": ["name": "华北 5", "endPoint": "oss-cn-huhehaote"],
"cn_shenzhen": ["name": "华南 1", "endPoint": "oss-cn-shenzhen"],
"cn_hongkong": ["name": "香港", "endPoint": "oss-cn-hongkong"],
"us_west_1": ["name": "美国西部 1(硅谷)", "endPoint": "oss-us-west-1"],
"us_east_1": ["name": "美国东部 1(弗吉尼亚)", "endPoint": "oss-us-east-1"],
"ap_southeast_1": ["name": "亚太东南 1(新加坡)", "endPoint": "oss-ap-southeast-1"],
"ap_southeast_2": ["name": "亚太东南 2(悉尼)", "endPoint": "oss-ap-southeast-2"],
"ap_southeast_3": ["name": "亚太东南 3(吉隆坡)", "endPoint": "oss-ap-southeast-3"],
"ap_southeast_5": ["name": "亚太东南 5 (雅加达)", "endPoint": "oss-ap-southeast-5"],
"ap_northeast_1": ["name": "亚太东北 1 (日本)", "endPoint": "oss-ap-northeast-1"],
"ap_south_1": ["name": "亚太南部 1 (孟买)", "endPoint": "oss-ap-south-1"],
"eu_central_1": ["name": "欧洲中部 1 (法兰克福)", "endPoint": "oss-eu-central-1"],
"eu_west_1": ["name": "英国(伦敦)", "endPoint": "oss-eu-west-1"],
"me_east_1": ["name": "中东东部 1 (迪拜)", "endPoint": "oss-me-east-1"]
]
}

Expand Down Expand Up @@ -68,7 +68,14 @@ public enum AliyunRegion: String, CaseIterable {
guard let regionDict = AliyunRegionDict.allRegion[self.rawValue], let endPoint = regionDict["endPoint"] else {
return ""
}
return endPoint
return "\(endPoint).aliyuncs.com"
}
}

public static func formatRegion(_ region: String?) -> AliyunRegion {
if let region = region, !region.isEmpty {
return AliyunRegion(rawValue: region)!
}
return AliyunRegion.cn_hangzhou
}
}
8 changes: 6 additions & 2 deletions uPic/Models/Aliyun/AliyunUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AliyunUploader: BaseUploader {
let secretKey = config.secretKey!
let hostSaveKey = HostSaveKey(rawValue: config.saveKey!)!
let domain = config.domain!
let region = (config.region != nil ? AliyunRegion(rawValue: config.region!) : AliyunRegion.cn_hangzhou)!
let region = AliyunRegion.formatRegion(config.region)

let url = AliyunUtil.computeUrl(bucket: bucket, region: region)

Expand Down Expand Up @@ -96,7 +96,11 @@ class AliyunUploader: BaseUploader {
}.response(completionHandler: { response -> Void in
switch response.result {
case .success(_):
super.completed(url: "\(domain)/\(key)\(config.suffix ?? "")")
if domain.isEmpty {
super.completed(url: "\(url)/\(key)\(config.suffix ?? "")")
} else {
super.completed(url: "\(domain)/\(key)\(config.suffix ?? "")")
}
case .failure(let error):
var errorMessage = error.localizedDescription
if let data = response.data {
Expand Down
7 changes: 7 additions & 0 deletions uPic/Models/Amazon_S3/AmazonS3Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ public class AmazonS3Region {
}
return "s3.\(key).amazonaws.com"
}

public static func formatRegion(_ region: String?) -> String {
if let region = region, !region.isEmpty {
return region
}
return AmazonS3Region.allRegion.keys.first!
}
}
2 changes: 1 addition & 1 deletion uPic/Models/Amazon_S3/AmazonS3Uploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AmazonS3Uploader: BaseUploader {
let secretKey = config.secretKey!
let hostSaveKey = HostSaveKey(rawValue: config.saveKey!)!
let domain = config.domain!
let region = config.region!
let region = AmazonS3Region.formatRegion(config.region)

let url = AmazonS3Util.computeUrl(bucket: bucket, region: region)

Expand Down
7 changes: 7 additions & 0 deletions uPic/Models/Qiniu/QiniuRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@ public enum QiniuRegion: String, CaseIterable {
return url
}
}

public static func formatRegion(_ region: String?) -> QiniuRegion {
if let region = region, !region.isEmpty {
return QiniuRegion(rawValue: region)!
}
return QiniuRegion.z0
}
}
2 changes: 1 addition & 1 deletion uPic/Models/Qiniu/QiniuUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QiniuUploader: BaseUploader {
let secretKey = config.secretKey!
let hostSaveKey = HostSaveKey(rawValue: config.saveKey!)!
let domain = config.domain!
let region = (config.region != nil ? QiniuRegion(rawValue: config.region!) : QiniuRegion.z0)!
var region = QiniuRegion.formatRegion(config.region)

var retData = fileData
var fileName = ""
Expand Down
47 changes: 27 additions & 20 deletions uPic/Models/Tencent/TencentRegion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ import Foundation
class TencentRegionDict {
static let allRegion = [
// 内地
"ap_beijing_1": ["name": "北京一区", "endPoint": "cos.ap-beijing-1.myqcloud.com"],
"ap_beijing": ["name": "北京", "endPoint": "cos.ap-beijing.myqcloud.com"],
"ap_shanghai": ["name": "上海(华东)", "endPoint": "cos.ap-shanghai.myqcloud.com"],
"ap_guangzhou": ["name": "广州(华南)", "endPoint": "cos.ap-guangzhou.myqcloud.com"],
"ap_chengdu": ["name": "成都(西南)", "endPoint": "cos.ap-chengdu.myqcloud.com"],
"ap_chongqing": ["name": "重庆", "endPoint": "cos.ap-chongqing.myqcloud.com"],
"ap_shenzhen_fsi": ["name": "深圳金融", "endPoint": "cos.ap-shenzhen-fsi.myqcloud.com"],
"ap_shanghai_fsi": ["name": "上海金融", "endPoint": "cos.ap-shanghai-fsi.myqcloud.com"],
"ap_beijing_1": ["name": "北京一区", "endPoint": "cos.ap-beijing-1"],
"ap_beijing": ["name": "北京", "endPoint": "cos.ap-beijing"],
"ap_shanghai": ["name": "上海(华东)", "endPoint": "cos.ap-shanghai"],
"ap_guangzhou": ["name": "广州(华南)", "endPoint": "cos.ap-guangzhou"],
"ap_chengdu": ["name": "成都(西南)", "endPoint": "cos.ap-chengdu"],
"ap_chongqing": ["name": "重庆", "endPoint": "cos.ap-chongqing"],
"ap_shenzhen_fsi": ["name": "深圳金融", "endPoint": "cos.ap-shenzhen-fsi"],
"ap_shanghai_fsi": ["name": "上海金融", "endPoint": "cos.ap-shanghai-fsi"],
// 中国香港及海外地域
"ap_hongkong": ["name": "香港", "endPoint": "cos.ap-hongkong.myqcloud.com"],
"ap_singapore": ["name": "新加坡", "endPoint": "cos.ap-singapore.myqcloud.com"],
"ap_mumbai": ["name": "孟买", "endPoint": "cos.ap-mumbai.myqcloud.com"],
"ap_seoul": ["name": "首尔", "endPoint": "cos.ap-seoul.myqcloud.com"],
"ap_bangkok": ["name": "曼谷", "endPoint": "cos.ap-bangkok.myqcloud.com"],
"ap_tokyo": ["name": "东京", "endPoint": "cos.ap-tokyo.myqcloud.com"],
"na_siliconvalley": ["name": "硅谷", "endPoint": "cos.na-siliconvalley.myqcloud.com"],
"na_ashburn": ["name": "弗吉尼亚", "endPoint": "cos.na-ashburn.myqcloud.com"],
"na_toronto": ["name": "多伦多", "endPoint": "cos.na-toronto.myqcloud.com"],
"eu_frankfurt": ["name": "法兰克福", "endPoint": "cos.eu-frankfurt.myqcloud.com"],
"eu_moscow": ["name": "莫斯科", "endPoint": "cos.eu-moscow.myqcloud.com"]
"ap_hongkong": ["name": "香港", "endPoint": "cos.ap-hongkong"],
"ap_singapore": ["name": "新加坡", "endPoint": "cos.ap-singapore"],
"ap_mumbai": ["name": "孟买", "endPoint": "cos.ap-mumbai"],
"ap_seoul": ["name": "首尔", "endPoint": "cos.ap-seoul"],
"ap_bangkok": ["name": "曼谷", "endPoint": "cos.ap-bangkok"],
"ap_tokyo": ["name": "东京", "endPoint": "cos.ap-tokyo"],
"na_siliconvalley": ["name": "硅谷", "endPoint": "cos.na-siliconvalley"],
"na_ashburn": ["name": "弗吉尼亚", "endPoint": "cos.na-ashburn"],
"na_toronto": ["name": "多伦多", "endPoint": "cos.na-toronto"],
"eu_frankfurt": ["name": "法兰克福", "endPoint": "cos.eu-frankfurt"],
"eu_moscow": ["name": "莫斯科", "endPoint": "cos.eu-moscow"]
]
}

Expand Down Expand Up @@ -70,7 +70,14 @@ public enum TencentRegion: String, CaseIterable {
guard let regionDict = TencentRegionDict.allRegion[self.rawValue], let endPoint = regionDict["endPoint"] else {
return ""
}
return endPoint
return "\(endPoint).myqcloud.com"
}
}

public static func formatRegion(_ region: String?) -> TencentRegion {
if let region = region, !region.isEmpty {
return TencentRegion(rawValue: region)!
}
return TencentRegion.ap_beijing_1
}
}
8 changes: 6 additions & 2 deletions uPic/Models/Tencent/TencentUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TencentUploader: BaseUploader {
let secretKey = config.secretKey!
let hostSaveKey = HostSaveKey(rawValue: config.saveKey!)!
let domain = config.domain!
let region = (config.region != nil ? TencentRegion(rawValue: config.region!) : TencentRegion.ap_shanghai)!
let region = TencentRegion.formatRegion(config.region)

let url = TencentUtil.computeUrl(bucket: bucket, region: region)
let hostUri = TencentUtil.computeHost(bucket: bucket, region: region)
Expand Down Expand Up @@ -113,7 +113,11 @@ class TencentUploader: BaseUploader {
}.response(completionHandler: { response -> Void in
switch response.result {
case .success(_):
super.completed(url: "\(domain)/\(key)\(config.suffix ?? "")")
if domain.isEmpty {
super.completed(url: "\(url)/\(key)\(config.suffix ?? "")")
} else {
super.completed(url: "\(domain)/\(key)\(config.suffix ?? "")")
}
case .failure(let error):
var errorMessage = error.localizedDescription
if let data = response.data {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ class AliyunConfigView: ConfigView {
selectRegion = menuItem
}
}

selectRegion = selectRegion ?? regionButtonPopUp.menu?.items.first
if selectRegion != nil {
regionButtonPopUp.select(selectRegion)
// 初次设置,手动处罚一下事件,将数据写入data
if (data.region == nil || data.region.isEmpty) {
self.regionChange(regionButtonPopUp)
}
}

self.addSubview(regionLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ class AmazonS3ConfigView: ConfigView {
selectRegion = menuItem
}
}

selectRegion = selectRegion ?? regionButtonPopUp.menu?.items.first
if selectRegion != nil {
regionButtonPopUp.select(selectRegion)
// 初次设置,手动处罚一下事件,将数据写入data
if (data.region == nil || data.region.isEmpty) {
self.regionChange(regionButtonPopUp)
}
}

self.addSubview(regionLabel)
Expand Down
Loading

0 comments on commit 5571041

Please sign in to comment.