From 32e6fbb706ea6015c5adba2d7e9e3ce9f99788e1 Mon Sep 17 00:00:00 2001 From: Jess Date: Sun, 8 Dec 2019 15:58:09 -0800 Subject: [PATCH 1/9] Added financial contributors to the README --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c1905f..68d1169 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@
- + @@ -174,3 +174,33 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d + +## Contributors + +### Code Contributors + +This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. + + +### Financial Contributors + +Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/uPic/contribute)] + +#### Individuals + + + +#### Organizations + +Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/uPic/contribute)] + + + + + + + + + + + From f80160ec5be055041eaf1b470ede0a2f2b6d1446 Mon Sep 17 00:00:00 2001 From: Svend Date: Mon, 9 Dec 2019 17:10:26 +0800 Subject: [PATCH 2/9] :art: Add support for variables for custom host Header and Body property values --- uPic/Models/BaseUploaderUtil.swift | 25 ++++++++++++++++++++++--- uPic/Models/Custom/CustomUploader.swift | 11 +++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/uPic/Models/BaseUploaderUtil.swift b/uPic/Models/BaseUploaderUtil.swift index f498ea6..b50f04c 100644 --- a/uPic/Models/BaseUploaderUtil.swift +++ b/uPic/Models/BaseUploaderUtil.swift @@ -92,7 +92,20 @@ class BaseUploaderUtil { /// - saveKeyPath: 文件保存路径(含变量) /// - filenameComponent: 文件名,含后缀 static func parseSaveKeyPath(_ saveKeyPath: String?, _ filenameComponent: String) -> String { - var keyPath = (saveKeyPath != nil && !saveKeyPath!.isEmpty) ? saveKeyPath! : _defaultSaveKeyPath + let keyPath = (saveKeyPath != nil && !saveKeyPath!.isEmpty) ? saveKeyPath! : _defaultSaveKeyPath + return _parseVariables(keyPath, filenameComponent, otherVariables: nil) + } + + /// 转换字符串中的变量 + /// - Parameters: + /// - str: 字符串(含变量) + /// - filenameComponent: 文件名,含后缀 + /// - otherVariables: 额外变量及值 (变量名:value) + static func _parseVariables(_ str: String, _ filenameComponent: String, otherVariables: [String: String]?) -> String { + if str.isEmpty { + return str + } + let filename = filenameComponent.lastPathComponent.deletingPathExtension let fileExtension = filenameComponent.pathExtension let now = Date() @@ -108,7 +121,7 @@ class BaseUploaderUtil { // The number of millisecond since 1970 let sinceMillisecond = now.milliStamp - keyPath = keyPath.replacingOccurrences(of: "{year}", with: "\(year)") + var result = str.replacingOccurrences(of: "{year}", with: "\(year)") .replacingOccurrences(of: "{month}", with: "\(month)") .replacingOccurrences(of: "{day}", with: "\(day)") .replacingOccurrences(of: "{hour}", with: "\(hour)") @@ -120,7 +133,13 @@ class BaseUploaderUtil { .replacingOccurrences(of: "{random}", with: _getRrandomFileName(nil)) .replacingOccurrences(of: "{.suffix}", with: ".\(fileExtension)") - return keyPath + if let varables = otherVariables, varables.count > 0 { + for (key, value) in varables { + result = result.replacingOccurrences(of: "{\(key)}", with: value) + } + } + + return result } diff --git a/uPic/Models/Custom/CustomUploader.swift b/uPic/Models/Custom/CustomUploader.swift index 3c922b4..35c2657 100644 --- a/uPic/Models/Custom/CustomUploader.swift +++ b/uPic/Models/Custom/CustomUploader.swift @@ -50,15 +50,16 @@ class CustomUploader: BaseUploader { var headers = HTTPHeaders() headers.add(HTTPHeader.contentType("application/x-www-form-urlencoded;charset=utf-8")) + + + let otherVariables = ["saveKey": saveKey] if let headersStr = config.headers { let headersArr = CustomHostUtil.parseHeadersOrBodys(headersStr) for header in headersArr { if let key = header["key"] { var value = header["value"] ?? "" - if value == "{filename}" { - value = fileName - } + value = BaseUploaderUtil._parseVariables(value, fileName, otherVariables: otherVariables) headers.add(HTTPHeader(name: key, value: value)) } @@ -72,9 +73,7 @@ class CustomUploader: BaseUploader { for body in bodysArr { if let key = body["key"] { var value = body["value"] ?? "" - if value == "{filename}" { - value = fileName - } + value = BaseUploaderUtil._parseVariables(value, fileName, otherVariables: otherVariables) multipartFormData.append(String(value).data(using: .utf8)!, withName: key) } From e65d301acf155a9e608e6c2505143791459f24f1 Mon Sep 17 00:00:00 2001 From: Svend Date: Mon, 9 Dec 2019 17:36:17 +0800 Subject: [PATCH 3/9] :pencel: Update the README --- .all-contributorsrc | 19 ----------------- README-cn.md | 32 +++++++++++++++------------- README.md | 52 ++++++++++++--------------------------------- 3 files changed, 30 insertions(+), 73 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index ef2d999..37f6b8e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -46,25 +46,6 @@ "contributions": [ "design" ] - }, - { - "login": "nlnlnull", - "name": "null", - "avatar_url": "https://avatars3.githubusercontent.com/u/17818831?v=4", - "profile": "https://github.com/nlnlnull", - "contributions": [ - "code" - ] - }, - { - "login": "L1cardo", - "name": "Licardo", - "avatar_url": "https://avatars1.githubusercontent.com/u/33802186?v=4", - "profile": "https://licardo.cn", - "contributions": [ - "code", - "design" - ] } ], "contributorsPerLine": 7 diff --git a/README-cn.md b/README-cn.md index ec4dbb4..1255159 100644 --- a/README-cn.md +++ b/README-cn.md @@ -133,18 +133,6 @@ brew cask install upic - -## 💌 联系我 - -- `Email`: svend.jin@gmail.com -- `Telegram`: [gee1k](https://t.me/gee1k) -- `项目地址`: [Github](https://github.com/gee1k/uPic) -- `uPic 产品交流群(Telegram)`: [点击加入 TG 群](https://t.me/upic_host) -- `微信群`: 扫描下方二维码加好友拉你入群 ↓ - - - - ## ❤️ 赞助 如果你喜欢 uPic ,欢迎给我打赏 @@ -153,9 +141,16 @@ brew cask install upic | :-: | :-: | :-: | | [@Geee1k](https://paypal.me/geee1k) | ![](https://raw.githubusercontent.com/gee1k/oss/master/qrcode/alipay-mini.jpeg) | ![](https://raw.githubusercontent.com/gee1k/oss/master/qrcode/wechat-zs.JPG) | - ## ✨ Contributors +### Code Contributors + +This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. + + + +### Other Contributors + Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): @@ -167,8 +162,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Jackxun123
Jackxun123

🌍 eleven
eleven

🌍 zhucebuliaomax
zhucebuliaomax

🎨 - null
null

💻 - Licardo
Licardo

💻 🎨 @@ -176,3 +169,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d + +## 💌 作者 + +**uPic** © [Svend](https://github.com/gee1k), Released under the [MIT](./LICENSE) License.
+Authored and maintained by Svend with help from contributors ([list](https://github.com/gee1k/uPic/contributors)). + +> Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) · 微信群 扫描下方二维码加好友拉你入群 ↓ + + diff --git a/README.md b/README.md index 68d1169..7f94309 100644 --- a/README.md +++ b/README.md @@ -133,17 +133,6 @@ brew cask install upic

sudo xattr -d com.apple.quarantine /Applications/uPic.app

-## 💌 Contact information - -- `Email`: svend.jin@gmail.com -- `Telegram`: [gee1k](https://t.me/gee1k) -- `Github`: [Github](https://github.com/gee1k/uPic) -- `uPic chat group(Telegram)`: [click here to join in](https://t.me/upic_host) -- `Wechat group`: scan the QR code below to join in ↓ - - - - ## ❤️ Support If you like uPic, please hit the star button and thanks for your support. @@ -155,6 +144,14 @@ If you like uPic, please hit the star button and thanks for your support. ## ✨ Contributors +### Code Contributors + +This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. + + + +### Other Contributors + Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): @@ -166,8 +163,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Jackxun123
Jackxun123

🌍 eleven
eleven

🌍 zhucebuliaomax
zhucebuliaomax

🎨 - null
null

💻 - Licardo
Licardo

💻 🎨 @@ -175,32 +170,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d -## Contributors - -### Code Contributors - -This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)]. - - -### Financial Contributors - -Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/uPic/contribute)] - -#### Individuals - - +## 💌 Auther -#### Organizations +**uPic** © [Svend](https://github.com/gee1k), Released under the [MIT](./LICENSE) License.
+Authored and maintained by Svend with help from contributors ([list](https://github.com/gee1k/uPic/contributors)). -Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/uPic/contribute)] +> Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) · Wechat group scan the QR code below to join in ↓ - - - - - - - - - - + \ No newline at end of file From 9b8e3db3cbdf6af4a686541c6260d82af4d5ea8c Mon Sep 17 00:00:00 2001 From: Svend Date: Mon, 9 Dec 2019 21:41:43 +0800 Subject: [PATCH 4/9] :lipstick: Tips for adding custom host configuration headers and bodies --- README-cn.md | 3 +- README.md | 5 +- .../Base.lproj/Preferences.storyboard | 75 +++++++++++-------- .../en.lproj/Preferences.strings | 3 + .../zh-Hans.lproj/Preferences.strings | 3 + 5 files changed, 56 insertions(+), 33 deletions(-) diff --git a/README-cn.md b/README-cn.md index 1255159..0396210 100644 --- a/README-cn.md +++ b/README-cn.md @@ -175,6 +175,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d **uPic** © [Svend](https://github.com/gee1k), Released under the [MIT](./LICENSE) License.
Authored and maintained by Svend with help from contributors ([list](https://github.com/gee1k/uPic/contributors)). -> Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) · 微信群 扫描下方二维码加好友拉你入群 ↓ +> Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) +> 微信群 扫描下方二维码加好友拉你入群 ↓ diff --git a/README.md b/README.md index 7f94309..5c9cd76 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,8 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Jackxun123
Jackxun123

🌍 eleven
eleven

🌍 zhucebuliaomax
zhucebuliaomax

🎨 + null
null

💻 + Licardo
Licardo

💻 🎨 @@ -175,6 +177,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d **uPic** © [Svend](https://github.com/gee1k), Released under the [MIT](./LICENSE) License.
Authored and maintained by Svend with help from contributors ([list](https://github.com/gee1k/uPic/contributors)). -> Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) · Wechat group scan the QR code below to join in ↓ +> Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) +> Wechat group scan the QR code below to join in ↓ \ No newline at end of file diff --git a/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard b/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard index 9b7ad08..2540979 100644 --- a/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard +++ b/uPic/PreferencesWindow/Base.lproj/Preferences.storyboard @@ -532,7 +532,7 @@ + + + + + + Supports {year} {month} {day} {hour} {minute} {second} {since_second} {since_millisecond} {random} {filename} {.suffix} {saveKey} and etc. + + + + + - - + + + - + + + @@ -998,12 +1011,12 @@ Gw - + - + diff --git a/uPic/PreferencesWindow/en.lproj/Preferences.strings b/uPic/PreferencesWindow/en.lproj/Preferences.strings index 89dff65..7b623df 100644 --- a/uPic/PreferencesWindow/en.lproj/Preferences.strings +++ b/uPic/PreferencesWindow/en.lproj/Preferences.strings @@ -172,3 +172,6 @@ /* Class = "NSTextFieldCell"; title = "eg:"; ObjectID = "t25-le-QEa"; */ "t25-le-QEa.title" = "eg:"; + +/* Class = "NSTextFieldCell"; title = "Supports {year} {month} {day} {hour} {minute} {second} {since_second} {since_millisecond} {random} {filename} {.suffix} {saveKey} and etc."; ObjectID = "R0i-0c-6TZ"; */ +"R0i-0c-6TZ.title" = "Supports {year} {month} {day} {hour} {minute} {second} {since_second} {since_millisecond} {random} {filename} {.suffix} {saveKey} and etc."; diff --git a/uPic/PreferencesWindow/zh-Hans.lproj/Preferences.strings b/uPic/PreferencesWindow/zh-Hans.lproj/Preferences.strings index 5c4b59d..f116a28 100644 --- a/uPic/PreferencesWindow/zh-Hans.lproj/Preferences.strings +++ b/uPic/PreferencesWindow/zh-Hans.lproj/Preferences.strings @@ -172,3 +172,6 @@ /* Class = "NSTextFieldCell"; title = "eg:"; ObjectID = "t25-le-QEa"; */ "t25-le-QEa.title" = "示例:"; + +/* Class = "NSTextFieldCell"; title = "Supports {year} {month} {day} {hour} {minute} {second} {since_second} {since_millisecond} {random} {filename} {.suffix} {saveKey} and etc."; ObjectID = "R0i-0c-6TZ"; */ +"R0i-0c-6TZ.title" = "支持 {year} {month} {day} {hour} {minute} {second} {since_second} {since_millisecond} {random} {filename} {.suffix} {saveKey} 等变量。"; From a01cc2a9d4bfc38026becd89829deb530ca5cd9c Mon Sep 17 00:00:00 2001 From: Svend Date: Mon, 9 Dec 2019 21:45:54 +0800 Subject: [PATCH 5/9] :pencel: Update the README --- README-cn.md | 1 + README.md | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README-cn.md b/README-cn.md index 0396210..e1ac719 100644 --- a/README-cn.md +++ b/README-cn.md @@ -176,6 +176,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Authored and maintained by Svend with help from contributors ([list](https://github.com/gee1k/uPic/contributors)). > Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) +> > 微信群 扫描下方二维码加好友拉你入群 ↓ diff --git a/README.md b/README.md index 5c9cd76..d60d37b 100644 --- a/README.md +++ b/README.md @@ -163,8 +163,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Jackxun123
Jackxun123

🌍 eleven
eleven

🌍 zhucebuliaomax
zhucebuliaomax

🎨 - null
null

💻 - Licardo
Licardo

💻 🎨 @@ -178,6 +176,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Authored and maintained by Svend with help from contributors ([list](https://github.com/gee1k/uPic/contributors)). > Blog [@Svend](https://svend.cc) · GitHub [@gee1k](https://github.com/gee1k) · Twitter [@geee1k](https://twitter.com/geee1k) · Telegram Channel [@uPic 产品交流群](https://t.me/upic_host) +> > Wechat group scan the QR code below to join in ↓ \ No newline at end of file From a1302b618a5416404999af132b8f7ae5707437c0 Mon Sep 17 00:00:00 2001 From: Svend Date: Wed, 11 Dec 2019 16:56:14 +0800 Subject: [PATCH 6/9] :construction_worker: Adding CI build system. --- .travis.yml | 17 +++++++++++++++++ .../xcshareddata/xcschemes/uPic.xcscheme | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f63db3e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,17 @@ +language: objective-c +matrix: + include: + - osx_image: xcode11 +branches: + only: + - master +env: + global: + - LC_CTYPE=en_US.UTF-8 +before_install: + - gem install cocoapods + - gem install xcpretty -N + - pod install +script: + - set -o pipefail + - xcodebuild clean build -workspace uPic.xcworkspace -scheme uPic -sdk macosx -configuration Release CODE_SIGN_IDENTITY="" CODE_SIGN_REQUIRED=NO | xcpretty -c diff --git a/uPic.xcodeproj/xcshareddata/xcschemes/uPic.xcscheme b/uPic.xcodeproj/xcshareddata/xcschemes/uPic.xcscheme index 3884d58..d475c26 100644 --- a/uPic.xcodeproj/xcshareddata/xcschemes/uPic.xcscheme +++ b/uPic.xcodeproj/xcshareddata/xcschemes/uPic.xcscheme @@ -1,6 +1,6 @@ Date: Wed, 11 Dec 2019 17:25:30 +0800 Subject: [PATCH 7/9] :green_heart: Fixing CI Build. :pencil: Add a CI Build status badge. --- .travis.yml | 4 ++-- README-cn.md | 5 ++++- README.md | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index f63db3e..1a81a4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ -language: objective-c +language: swift matrix: include: - - osx_image: xcode11 + - osx_image: xcode11.2 branches: only: - master diff --git a/README-cn.md b/README-cn.md index e1ac719..f9dad2a 100644 --- a/README-cn.md +++ b/README-cn.md @@ -13,7 +13,10 @@ - GitHub + GitHub + + +
diff --git a/README.md b/README.md index d60d37b..b50f916 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,16 @@ From 7b304a89b131069d7de41255f78b287b3c602423 Mon Sep 17 00:00:00 2001 From: Svend Date: Thu, 12 Dec 2019 15:48:28 +0800 Subject: [PATCH 8/9] :sparkles: Add test host configuration upload button --- uPic.xcodeproj/project.pbxproj | 4 ++ uPic/Basic/NSImage+Extension.swift | 38 +++++++++++++ uPic/Models/Aliyun/AliyunUploader.swift | 12 ++-- uPic/Models/Amazon_S3/AmazonS3Uploader.swift | 16 +++--- uPic/Models/Baidu/BaiduUploader.swift | 12 ++-- uPic/Models/BaseUploader.swift | 56 +++++++++---------- uPic/Models/Custom/CustomUploader.swift | 16 +++--- uPic/Models/Gitee/GiteeUploader.swift | 12 ++-- uPic/Models/Github/GithubUploader.swift | 12 ++-- uPic/Models/Imgur/ImgurUploader.swift | 16 +++--- uPic/Models/Qiniu/QiniuUploader.swift | 16 +++--- uPic/Models/Smms/SmmsUploader.swift | 12 ++-- uPic/Models/Tencent/TencentUploader.swift | 16 +++--- uPic/Models/UpYun/UpYunUploader.swift | 16 +++--- uPic/Models/Weibo/WeiboUploader.swift | 14 ++--- .../ConfigView/ConfigView.swift | 46 ++++++++++----- .../ConfigView/Views/GithubConfigView.swift | 20 +++++-- uPic/en.lproj/Localizable.strings | 2 + uPic/zh-Hans.lproj/Localizable.strings | 1 + 19 files changed, 206 insertions(+), 131 deletions(-) create mode 100644 uPic/Basic/NSImage+Extension.swift diff --git a/uPic.xcodeproj/project.pbxproj b/uPic.xcodeproj/project.pbxproj index b3b948e..cff2166 100644 --- a/uPic.xcodeproj/project.pbxproj +++ b/uPic.xcodeproj/project.pbxproj @@ -94,6 +94,7 @@ 16A6DC5822AA375700813706 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16A6DC5722AA375700813706 /* AppDelegate.swift */; }; 16BDDDFF22EA96AE0080E467 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16BDDDFE22EA96AE0080E467 /* Assets.xcassets */; }; 16BDDE0322EAA2920080E467 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 16BDDE0222EAA2920080E467 /* Assets.xcassets */; }; + 16C176F523A208A80089B933 /* NSImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16C176F423A208A80089B933 /* NSImage+Extension.swift */; }; 16D20B5523838AB1006D8D01 /* BaiduRegion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D20B54238388D8006D8D01 /* BaiduRegion.swift */; }; 16D20B5623838AB5006D8D01 /* BaiduHostConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D20B532383889F006D8D01 /* BaiduHostConfig.swift */; }; 16D20B58238390F2006D8D01 /* BaiduUploader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D20B57238390F2006D8D01 /* BaiduUploader.swift */; }; @@ -246,6 +247,7 @@ 16A6DC6122AA375800813706 /* uPic.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = uPic.entitlements; sourceTree = ""; }; 16BDDDFE22EA96AE0080E467 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 16BDDE0222EAA2920080E467 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 16C176F423A208A80089B933 /* NSImage+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSImage+Extension.swift"; sourceTree = ""; }; 16D20B532383889F006D8D01 /* BaiduHostConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaiduHostConfig.swift; sourceTree = ""; }; 16D20B54238388D8006D8D01 /* BaiduRegion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaiduRegion.swift; sourceTree = ""; }; 16D20B57238390F2006D8D01 /* BaiduUploader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaiduUploader.swift; sourceTree = ""; }; @@ -335,6 +337,7 @@ 165D908522C333740096FF38 /* PasteboardType+Extension.swift */, 165701A022C8A6E600C57EE9 /* Regex.swift */, 1685AA3422DEC943008FBF1D /* FlippedView.swift */, + 16C176F423A208A80089B933 /* NSImage+Extension.swift */, ); path = Basic; sourceTree = ""; @@ -883,6 +886,7 @@ 1660FCBB22C11C7200372950 /* TencentUploader.swift in Sources */, 167D08AE22ED8A58000F3BC0 /* AliyunUploader.swift in Sources */, 1647474522B66E3400F9575D /* Util.swift in Sources */, + 16C176F523A208A80089B933 /* NSImage+Extension.swift in Sources */, 167620ED230819C0008F8363 /* ImgurHostConfig.swift in Sources */, 1657019F22C897A400C57EE9 /* WeiboConfigView.swift in Sources */, 4BC11BDE238CFD53001641A6 /* HistoryThumbnailTimer.swift in Sources */, diff --git a/uPic/Basic/NSImage+Extension.swift b/uPic/Basic/NSImage+Extension.swift new file mode 100644 index 0000000..eccc713 --- /dev/null +++ b/uPic/Basic/NSImage+Extension.swift @@ -0,0 +1,38 @@ +// +// NSImage+Extension.swift +// uPic +// +// Created by Svend Jin on 2019/12/12. +// Copyright © 2019 Svend Jin. All rights reserved. +// + +import Cocoa + +extension NSImage { + var pngData: Data? { + guard let rep = NSBitmapImageRep( + bitmapDataPlanes: nil, + pixelsWide: Int(size.width), + pixelsHigh: Int(size.height), + bitsPerSample: 8, + samplesPerPixel: 4, + hasAlpha: true, + isPlanar: false, + colorSpaceName: NSColorSpaceName.deviceRGB, + bytesPerRow: 0, + bitsPerPixel: 0 + ) else { + print("Couldn't create bitmap representation") + return nil + } + NSGraphicsContext.saveGraphicsState() + NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: rep) + draw(at: NSZeroPoint, from: NSZeroRect, operation: .sourceOver, fraction: 1.0) + NSGraphicsContext.restoreGraphicsState() + guard let data = rep.representation(using: NSBitmapImageRep.FileType.png, properties: [NSBitmapImageRep.PropertyKey.compressionFactor: 1.0]) else { + print("Couldn't create PNG") + return nil + } + return data + } +} diff --git a/uPic/Models/Aliyun/AliyunUploader.swift b/uPic/Models/Aliyun/AliyunUploader.swift index 69f1bd2..3a43a10 100644 --- a/uPic/Models/Aliyun/AliyunUploader.swift +++ b/uPic/Models/Aliyun/AliyunUploader.swift @@ -15,8 +15,8 @@ class AliyunUploader: BaseUploader { static let shared = AliyunUploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -101,11 +101,11 @@ class AliyunUploader: BaseUploader { } - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Amazon_S3/AmazonS3Uploader.swift b/uPic/Models/Amazon_S3/AmazonS3Uploader.swift index c93920a..2db5652 100644 --- a/uPic/Models/Amazon_S3/AmazonS3Uploader.swift +++ b/uPic/Models/Amazon_S3/AmazonS3Uploader.swift @@ -15,8 +15,8 @@ class AmazonS3Uploader: BaseUploader { static let shared = AmazonS3Uploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -115,12 +115,12 @@ class AmazonS3Uploader: BaseUploader { }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Baidu/BaiduUploader.swift b/uPic/Models/Baidu/BaiduUploader.swift index 22dc905..c66e8cb 100644 --- a/uPic/Models/Baidu/BaiduUploader.swift +++ b/uPic/Models/Baidu/BaiduUploader.swift @@ -15,8 +15,8 @@ class BaiduUploader: BaseUploader { static let shared = BaiduUploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -100,11 +100,11 @@ class BaiduUploader: BaseUploader { } - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/BaseUploader.swift b/uPic/Models/BaseUploader.swift index 5cb7a73..7bb37d2 100644 --- a/uPic/Models/BaseUploader.swift +++ b/uPic/Models/BaseUploader.swift @@ -83,8 +83,8 @@ class BaseUploader { /// 作为上传的统一入口 /// As a unified entry point for uploads /// - static func upload(url: URL) { - guard let host = ConfigManager.shared.getDefaultHost() else { + static func upload(url: URL, _ defaultHost: Host? = nil) { + guard let host = defaultHost ?? ConfigManager.shared.getDefaultHost() else { return } @@ -107,40 +107,40 @@ class BaseUploader { /* 有新的图床在这里进行判断调用 */ switch host.type { case .smms: - SmmsUploader.shared.upload(url) + SmmsUploader.shared.upload(url, host: host) break case .custom: - CustomUploader.shared.upload(url) + CustomUploader.shared.upload(url, host: host) break case .upyun_USS: - UpYunUploader.shared.upload(url) + UpYunUploader.shared.upload(url, host: host) break case .qiniu_KODO: - QiniuUploader.shared.upload(url) + QiniuUploader.shared.upload(url, host: host) break case .aliyun_OSS: - AliyunUploader.shared.upload(url) + AliyunUploader.shared.upload(url, host: host) break case .tencent_COS: - TencentUploader.shared.upload(url) + TencentUploader.shared.upload(url, host: host) break case .github: - GithubUploader.shared.upload(url) + GithubUploader.shared.upload(url, host: host) break case .gitee: - GiteeUploader.shared.upload(url) + GiteeUploader.shared.upload(url, host: host) break case .weibo: - WeiboUploader.shared.upload(url) + WeiboUploader.shared.upload(url, host: host) break case .amazon_S3: - AmazonS3Uploader.shared.upload(url) + AmazonS3Uploader.shared.upload(url, host: host) break case .imgur: - ImgurUploader.shared.upload(url) + ImgurUploader.shared.upload(url, host: host) break case .baidu_BOS: - BaiduUploader.shared.upload(url) + BaiduUploader.shared.upload(url, host: host) break } } @@ -149,8 +149,8 @@ class BaseUploader { /// 作为上传的统一入口 /// As a unified entry point for uploads /// - static func upload(data: Data) { - guard let host = ConfigManager.shared.getDefaultHost() else { + static func upload(data: Data, _ defaultHost: Host? = nil) { + guard let host = defaultHost ?? ConfigManager.shared.getDefaultHost() else { return } @@ -165,40 +165,40 @@ class BaseUploader { /* 有新的图床在这里进行判断调用 */ switch host.type { case .smms: - SmmsUploader.shared.upload(data) + SmmsUploader.shared.upload(data, host: host) break case .custom: - CustomUploader.shared.upload(data) + CustomUploader.shared.upload(data, host: host) break case .upyun_USS: - UpYunUploader.shared.upload(data) + UpYunUploader.shared.upload(data, host: host) break case .qiniu_KODO: - QiniuUploader.shared.upload(data) + QiniuUploader.shared.upload(data, host: host) break case .aliyun_OSS: - AliyunUploader.shared.upload(data) + AliyunUploader.shared.upload(data, host: host) break case .tencent_COS: - TencentUploader.shared.upload(data) + TencentUploader.shared.upload(data, host: host) break case .github: - GithubUploader.shared.upload(data) + GithubUploader.shared.upload(data, host: host) break case .gitee: - GiteeUploader.shared.upload(data) + GiteeUploader.shared.upload(data, host: host) break case .weibo: - WeiboUploader.shared.upload(data) + WeiboUploader.shared.upload(data, host: host) break case .amazon_S3: - AmazonS3Uploader.shared.upload(data) + AmazonS3Uploader.shared.upload(data, host: host) break case .imgur: - ImgurUploader.shared.upload(data) + ImgurUploader.shared.upload(data, host: host) break case .baidu_BOS: - BaiduUploader.shared.upload(data) + BaiduUploader.shared.upload(data, host: host) break } } diff --git a/uPic/Models/Custom/CustomUploader.swift b/uPic/Models/Custom/CustomUploader.swift index 35c2657..e8ca3fa 100644 --- a/uPic/Models/Custom/CustomUploader.swift +++ b/uPic/Models/Custom/CustomUploader.swift @@ -15,8 +15,8 @@ class CustomUploader: BaseUploader { static let shared = CustomUploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -109,12 +109,12 @@ class CustomUploader: BaseUploader { }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Gitee/GiteeUploader.swift b/uPic/Models/Gitee/GiteeUploader.swift index 0b6930e..e9a11b5 100644 --- a/uPic/Models/Gitee/GiteeUploader.swift +++ b/uPic/Models/Gitee/GiteeUploader.swift @@ -14,8 +14,8 @@ class GiteeUploader: BaseUploader { static let shared = GiteeUploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -75,11 +75,11 @@ class GiteeUploader: BaseUploader { } - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Github/GithubUploader.swift b/uPic/Models/Github/GithubUploader.swift index 6e9e76e..4131e65 100644 --- a/uPic/Models/Github/GithubUploader.swift +++ b/uPic/Models/Github/GithubUploader.swift @@ -14,8 +14,8 @@ class GithubUploader: BaseUploader { static let shared = GithubUploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -77,11 +77,11 @@ class GithubUploader: BaseUploader { } - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Imgur/ImgurUploader.swift b/uPic/Models/Imgur/ImgurUploader.swift index cd8f6aa..f761a6a 100644 --- a/uPic/Models/Imgur/ImgurUploader.swift +++ b/uPic/Models/Imgur/ImgurUploader.swift @@ -21,8 +21,8 @@ class ImgurUploader: BaseUploader { let url = "https://api.imgur.com/3/image"; - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -71,12 +71,12 @@ class ImgurUploader: BaseUploader { } }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Qiniu/QiniuUploader.swift b/uPic/Models/Qiniu/QiniuUploader.swift index 2496d0b..3b10388 100644 --- a/uPic/Models/Qiniu/QiniuUploader.swift +++ b/uPic/Models/Qiniu/QiniuUploader.swift @@ -16,8 +16,8 @@ class QiniuUploader: BaseUploader { static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -82,12 +82,12 @@ class QiniuUploader: BaseUploader { }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Smms/SmmsUploader.swift b/uPic/Models/Smms/SmmsUploader.swift index d6bb353..0019fd4 100644 --- a/uPic/Models/Smms/SmmsUploader.swift +++ b/uPic/Models/Smms/SmmsUploader.swift @@ -21,7 +21,7 @@ class SmmsUploader: BaseUploader { let url = "https://sm.ms/api/upload" - func _upload(_ fileUrl: URL?, fileData: Data?) { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { super.start() guard let configuration = BaseUploaderUtil.getSaveConfiguration(fileUrl, fileData, nil) else { @@ -61,12 +61,12 @@ class SmmsUploader: BaseUploader { }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Tencent/TencentUploader.swift b/uPic/Models/Tencent/TencentUploader.swift index e2553cc..24c56ca 100644 --- a/uPic/Models/Tencent/TencentUploader.swift +++ b/uPic/Models/Tencent/TencentUploader.swift @@ -15,8 +15,8 @@ class TencentUploader: BaseUploader { static let shared = TencentUploader() static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -110,12 +110,12 @@ class TencentUploader: BaseUploader { }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/UpYun/UpYunUploader.swift b/uPic/Models/UpYun/UpYunUploader.swift index 7662e0b..3c74671 100644 --- a/uPic/Models/UpYun/UpYunUploader.swift +++ b/uPic/Models/UpYun/UpYunUploader.swift @@ -18,8 +18,8 @@ class UpYunUploader: BaseUploader { static let fileExtensions: [String] = [] - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -94,12 +94,12 @@ class UpYunUploader: BaseUploader { }) } - - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } } diff --git a/uPic/Models/Weibo/WeiboUploader.swift b/uPic/Models/Weibo/WeiboUploader.swift index 77c735a..9c73b4f 100644 --- a/uPic/Models/Weibo/WeiboUploader.swift +++ b/uPic/Models/Weibo/WeiboUploader.swift @@ -18,8 +18,8 @@ class WeiboUploader: BaseUploader { let url = "https://picupload.weibo.com/interface/pic_upload.php?ori=1&mime=image%2Fjpeg&data=base64&url=0&markpos=1&logo=&nick=0&marks=1&app=miniblog" - func _upload(_ fileUrl: URL?, fileData: Data?) { - guard let host = ConfigManager.shared.getDefaultHost(), let data = host.data else { + func _upload(_ fileUrl: URL?, fileData: Data?, host: Host) { + guard let data = host.data else { super.faild(errorMsg: "There is a problem with the map bed configuration, please check!".localized) return } @@ -96,12 +96,12 @@ class WeiboUploader: BaseUploader { } } - func upload(_ fileUrl: URL) { - self._upload(fileUrl, fileData: nil) + func upload(_ fileUrl: URL, host: Host) { + self._upload(fileUrl, fileData: nil, host: host) } - - func upload(_ fileData: Data) { - self._upload(nil, fileData: fileData) + + func upload(_ fileData: Data, host: Host) { + self._upload(nil, fileData: fileData, host: host) } // MARK: 通过用户名密码登录,获取 cookie diff --git a/uPic/PreferencesWindow/ConfigView/ConfigView.swift b/uPic/PreferencesWindow/ConfigView/ConfigView.swift index 801c62d..da072f4 100644 --- a/uPic/PreferencesWindow/ConfigView/ConfigView.swift +++ b/uPic/PreferencesWindow/ConfigView/ConfigView.swift @@ -54,37 +54,37 @@ class ConfigView: NSView { // MARK: 根据当前选择的图床,创建对应的配置界面 switch item.type { case .custom: - parentView.addSubview(CustomConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(CustomConfigView(frame: parentView.frame, host: item)) break case .upyun_USS: - parentView.addSubview(UpYunConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(UpYunConfigView(frame: parentView.frame, host: item)) break case .qiniu_KODO: - parentView.addSubview(QiniuConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(QiniuConfigView(frame: parentView.frame, host: item)) break case .aliyun_OSS: - parentView.addSubview(AliyunConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(AliyunConfigView(frame: parentView.frame, host: item)) break case .tencent_COS: - parentView.addSubview(TencentConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(TencentConfigView(frame: parentView.frame, host: item)) break case .github: - parentView.addSubview(GithubConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(GithubConfigView(frame: parentView.frame, host: item)) break case .gitee: - parentView.addSubview(GiteeConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(GiteeConfigView(frame: parentView.frame, host: item)) break case .weibo: - parentView.addSubview(WeiboConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(WeiboConfigView(frame: parentView.frame, host: item)) break case .amazon_S3: - parentView.addSubview(AmazonS3ConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(AmazonS3ConfigView(frame: parentView.frame, host: item)) break case .imgur: - parentView.addSubview(ImgurConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(ImgurConfigView(frame: parentView.frame, host: item)) break case .baidu_BOS: - parentView.addSubview(BaiduConfigView(frame: parentView.frame, data: item.data)) + parentView.addSubview(BaiduConfigView(frame: parentView.frame, host: item)) break default: let label = NSTextField(labelWithString: "The file will be uploaded anonymously to".localized + " \(item.name)") @@ -93,7 +93,11 @@ class ConfigView: NSView { } } - var data: HostConfig? + var host: Host! + + var data: HostConfig? { + return self.host.data + } var domainField: NSTextField? @@ -109,10 +113,10 @@ class ConfigView: NSView { } - init(frame frameRect: NSRect, data: HostConfig?) { + init(frame frameRect: NSRect, host: Host) { super.init(frame: frameRect) - self.data = data + self.host = host } required init?(coder decoder: NSCoder) { @@ -216,6 +220,7 @@ class ConfigView: NSView { /// - y: y-axis /// - url: Help document address func createHelpBtn(_ url: String) { + // help let helpBtn = NSButton(title: "", target: self, action: #selector(openTutorial(_:))) let helpBtnWidth = Int(helpBtn.frame.width) helpBtn.frame = NSRect(x: Int(self.frame.width) - helpBtnWidth - paddingLeft, y: 0, width: helpBtnWidth, height: Int(helpBtn.frame.height)) @@ -225,6 +230,12 @@ class ConfigView: NSView { helpBtn.setButtonType(.momentaryPushIn) helpBtn.toolTip = url self.addSubview(helpBtn) + + // testing + let testBtn = NSButton(title: "Test the upload".localized, target: self, action: #selector(testUpload(_:))) + let testBtnWidth = Int(testBtn.frame.width) + testBtn.frame = NSRect(x: Int(self.frame.width) - testBtnWidth - helpBtnWidth - paddingLeft, y: 0, width: testBtnWidth, height: Int(testBtn.frame.height)) + self.addSubview(testBtn) } func setNextKeyViews() { @@ -249,4 +260,11 @@ class ConfigView: NSView { NSWorkspace.shared.open(url) } + + @objc func testUpload(_ sender: NSButton) { + if let image = NSImage(named: "AppIcon"), let imgData = image.pngData { + BaseUploader.upload(data: imgData, self.host) + } + + } } diff --git a/uPic/PreferencesWindow/ConfigView/Views/GithubConfigView.swift b/uPic/PreferencesWindow/ConfigView/Views/GithubConfigView.swift index 9282409..414ca92 100644 --- a/uPic/PreferencesWindow/ConfigView/Views/GithubConfigView.swift +++ b/uPic/PreferencesWindow/ConfigView/Views/GithubConfigView.swift @@ -10,6 +10,10 @@ import Cocoa class GithubConfigView: ConfigView { + override var gapTop: Int { + return 5 + } + deinit { PreferencesNotifier.removeObserver(observer: self, notification: .githubCDNAutoComplete) } @@ -139,7 +143,12 @@ class GithubConfigView: ConfigView { self.autoCompleteCDN() } - self.data?.setValue(String(value), forKey: "useCdn") + let strValue = String(value) + + if self.data?.value(forKey: "useCdn") as? String != strValue { + self.data?.setValue(strValue, forKey: "useCdn") + } + } /// auto complete cdn domain @@ -156,9 +165,12 @@ class GithubConfigView: ConfigView { if branch == nil || branch!.isEmpty { branch = "{branch}" } - let domain = "https://cdn.jsdelivr.net/gh/\(owner!)/\(repo!)@\(branch!)/" - self.domainField?.stringValue = domain - self.data?.setValue(domain, forKey: "domain") + let domain = "https://cdn.jsdelivr.net/gh/\(owner!)/\(repo!)@\(branch!)" + + if self.domainField?.stringValue != domain { + self.domainField?.stringValue = domain + self.data?.setValue(domain, forKey: "domain") + } } } diff --git a/uPic/en.lproj/Localizable.strings b/uPic/en.lproj/Localizable.strings index 959334b..1c1175a 100644 --- a/uPic/en.lproj/Localizable.strings +++ b/uPic/en.lproj/Localizable.strings @@ -148,5 +148,7 @@ "weibo.quality.mw690" = "medium size"; "weibo.quality.large" = "original"; +"Test the upload" = "Test the upload"; + /*eroor message*/ "Upload failed, please check the configuration!" = "Upload failed, please check the configuration!"; diff --git a/uPic/zh-Hans.lproj/Localizable.strings b/uPic/zh-Hans.lproj/Localizable.strings index 3ccb18f..70ba76a 100644 --- a/uPic/zh-Hans.lproj/Localizable.strings +++ b/uPic/zh-Hans.lproj/Localizable.strings @@ -148,6 +148,7 @@ "weibo.quality.mw690" = "中等大小"; "weibo.quality.large" = "原图"; +"Test the upload" = "测试上传"; /*eroor message*/ "Upload failed, please check the configuration!" = "上传失败,请检查配置!"; From 6355167e6b218bdc7bbdf86855a18443cf1fe3fd Mon Sep 17 00:00:00 2001 From: Svend Date: Thu, 12 Dec 2019 15:51:29 +0800 Subject: [PATCH 9/9] :bookmark: Releasing v0.15.1 --- uPic.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/uPic.xcodeproj/project.pbxproj b/uPic.xcodeproj/project.pbxproj index cff2166..a97e9a4 100644 --- a/uPic.xcodeproj/project.pbxproj +++ b/uPic.xcodeproj/project.pbxproj @@ -1117,7 +1117,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 20191206; + CURRENT_PROJECT_VERSION = 20191212; DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist"; @@ -1126,7 +1126,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 0.15.0; + MARKETING_VERSION = 0.15.1; PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1147,7 +1147,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 20191206; + CURRENT_PROJECT_VERSION = 20191212; DEVELOPMENT_TEAM = W863J6W8DZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = "$(SRCROOT)/uPic/Supporting Files/Info.plist"; @@ -1156,7 +1156,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 0.15.0; + MARKETING_VERSION = 0.15.1; PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "";