Skip to content

Commit

Permalink
Merge branch 'hotfix/custom-null-ret'
Browse files Browse the repository at this point in the history
  • Loading branch information
gee1k committed Nov 24, 2019
2 parents b78023f + d38a6b5 commit 2089c38
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 43 deletions.
87 changes: 44 additions & 43 deletions uPic/Models/BaseUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,54 +20,55 @@ class BaseUploader {
}

func completed(url: String, _ fileData: String?, _ fileUrl: URL?, _ fileName: String?) {
var thumbnailFileData: Data?
var thumbnailFileDataBase64String: String?
if let fileUrl = fileUrl {
do { thumbnailFileData = try Data(contentsOf: fileUrl) } catch { }
thumbnailFileDataBase64String = thumbnailFileData?.toBase64()
} else {
thumbnailFileDataBase64String = fileData
}
if !url.isEmpty {
var thumbnailFileData: Data?
var thumbnailFileDataBase64String: String?
if let fileUrl = fileUrl {
do { thumbnailFileData = try Data(contentsOf: fileUrl) } catch { }
thumbnailFileDataBase64String = thumbnailFileData?.toBase64()
} else {
thumbnailFileDataBase64String = fileData
}

let thumbnailWidth: CGFloat = 160
var thumbnailHeight: CGFloat = thumbnailWidth * 0.5
var thumbnailData: Data?
var previewWidth: CGFloat = 0
var previewHeight: CGFloat = 0
let bigSize: CGFloat = 450
var isImage: Bool = false
if let thumbnailFileDataBase64String = thumbnailFileDataBase64String, let decodedData = Data(base64Encoded: thumbnailFileDataBase64String), let image = NSImage(data: decodedData) {
previewWidth = image.size.width
previewHeight = image.size.height
let originalScale: CGFloat = previewWidth / previewHeight
if previewWidth > bigSize {
previewWidth = bigSize
previewHeight = previewWidth / originalScale
let thumbnailWidth: CGFloat = 160
var thumbnailHeight: CGFloat = thumbnailWidth * 0.5
var thumbnailData: Data?
var previewWidth: CGFloat = 0
var previewHeight: CGFloat = 0
let bigSize: CGFloat = 450
var isImage: Bool = false
if let thumbnailFileDataBase64String = thumbnailFileDataBase64String, let decodedData = Data(base64Encoded: thumbnailFileDataBase64String), let image = NSImage(data: decodedData) {
previewWidth = image.size.width
previewHeight = image.size.height
let originalScale: CGFloat = previewWidth / previewHeight
if previewWidth > bigSize {
previewWidth = bigSize
previewHeight = previewWidth / originalScale
}

if previewHeight > bigSize {
previewHeight = bigSize
previewWidth = bigSize * originalScale
}

let imageSize = NSSize(width: thumbnailWidth, height: thumbnailWidth / originalScale)
thumbnailData = image.resizeImage(size: imageSize).tiffRepresentation
thumbnailHeight = imageSize.height
isImage = true
}

if previewHeight > bigSize {
previewHeight = bigSize
previewWidth = bigSize * originalScale
}
var previewModel = HistoryThumbnailModel()
previewModel.url = url
previewModel.fileName = fileName
previewModel.thumbnailWidth = thumbnailWidth
previewModel.thumbnailHeight = thumbnailHeight + 20
previewModel.previewWidth = previewWidth
previewModel.previewHeight = previewHeight
previewModel.thumbnailData = thumbnailData
previewModel.isImage = isImage

let imageSize = NSSize(width: thumbnailWidth, height: thumbnailWidth / originalScale)
thumbnailData = image.resizeImage(size: imageSize).tiffRepresentation
thumbnailHeight = imageSize.height
isImage = true
ConfigManager.shared.addHistory_New(url: url, previewModel: previewModel)
}

var previewModel = HistoryThumbnailModel()
previewModel.url = url
previewModel.fileName = fileName
previewModel.thumbnailWidth = thumbnailWidth
previewModel.thumbnailHeight = thumbnailHeight + 20
previewModel.previewWidth = previewWidth
previewModel.previewHeight = previewHeight
previewModel.thumbnailData = thumbnailData
previewModel.isImage = isImage

ConfigManager.shared.addHistory_New(url: url, previewModel: previewModel)
// ConfigManager.shared.addHistory(url: url)
(NSApplication.shared.delegate as? AppDelegate)?.uploadCompleted(url: url)
}

Expand Down
4 changes: 4 additions & 0 deletions uPic/Models/Custom/CustomUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ class CustomUploader: BaseUploader {
case .success(let value):
let json = JSON(value)
var retUrl = CustomHostUtil.parseResultUrl(json, config.resultPath ?? "")
if retUrl.isEmpty {
super.faild(errorMsg: "Did not get the file URL".localized)
return
}
if !domain.isEmpty {
retUrl = "\(domain)/\(retUrl)"
}
Expand Down
2 changes: 2 additions & 0 deletions uPic/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"Upload via uPic" = "Upload via uPic";
"Right click to cancel the current upload task" = "Right click to cancel the current upload task";

"Did not get the file URL" = "Did not get the file URL";

/* 状态栏菜单选择文件 */
"Select File" = "Select File";
/* 状态栏菜单屏幕截图 */
Expand Down
2 changes: 2 additions & 0 deletions uPic/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"Upload via uPic" = "使用 uPic 上传";
"Right click to cancel the current upload task" = "右击取消当前上传任务";

"Did not get the file URL" = "没有获取到文件URL";

/* 状态栏菜单选择文件 */
"Select File" = "选择文件";
/* 状态栏菜单屏幕截图 */
Expand Down

0 comments on commit 2089c38

Please sign in to comment.