Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: if image has been uploaded, return image url insead of error #251

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use_frameworks!

target 'uPic' do
pod "libminipng"
pod 'WCDB.swift'
end

post_install do |installer|
Expand Down
13 changes: 1 addition & 12 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
PODS:
- libminipng (0.5.6)
- WCDB.swift (2.0.2.5):
- WCDB.swift/no-arc (= 2.0.2.5)
- WCDBOptimizedSQLCipher (~> 1.4.1)
- WCDB.swift/no-arc (2.0.2.5):
- WCDBOptimizedSQLCipher (~> 1.4.1)
- WCDBOptimizedSQLCipher (1.4.1)

DEPENDENCIES:
- libminipng
- WCDB.swift

SPEC REPOS:
trunk:
- libminipng
- WCDB.swift
- WCDBOptimizedSQLCipher

SPEC CHECKSUMS:
libminipng: a44c35d06b9d54d6640acdf97f4500c034748abb
WCDB.swift: 41d30d0e113cb2032947e34998f9eedc5c8cbd71
WCDBOptimizedSQLCipher: 880ec8aa6cda6b27e4c72b30bf0cc01771deda6f

PODFILE CHECKSUM: 578e68ce0a8889942b52298dac45365f59c42985
PODFILE CHECKSUM: 2f154ab6bb78169cbea229fc0e9e6d544635745d

COCOAPODS: 1.14.2
31 changes: 27 additions & 4 deletions uPic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
03714B932C19907C00BB4459 /* WCDBSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 03714B922C19907C00BB4459 /* WCDBSwift */; };
03F383CA2C15A6BC00795FD3 /* URL+sha1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F383C92C15A6BC00795FD3 /* URL+sha1.swift */; };
1602ED9722ADEFB200AA8638 /* BaseUploader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1602ED9622ADEFB200AA8638 /* BaseUploader.swift */; };
1602ED9922ADF43800AA8638 /* SmmsUploader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1602ED9822ADF43800AA8638 /* SmmsUploader.swift */; };
16068C7522AEC1D1004D39B7 /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16068C7422AEC1D1004D39B7 /* PreferencesViewController.swift */; };
Expand Down Expand Up @@ -205,6 +207,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
03F383C92C15A6BC00795FD3 /* URL+sha1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+sha1.swift"; sourceTree = "<group>"; };
1602ED9622ADEFB200AA8638 /* BaseUploader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseUploader.swift; sourceTree = "<group>"; };
1602ED9822ADF43800AA8638 /* SmmsUploader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmmsUploader.swift; sourceTree = "<group>"; };
1605DDD8246D993C00262C89 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Main.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -395,6 +398,7 @@
1649393F285E2620007278DA /* CocoaLumberjackSwift in Frameworks */,
964198B62729A6BA0001AB97 /* SwiftyJSON in Frameworks */,
964198C62729A7F00001AB97 /* Kingfisher in Frameworks */,
03714B932C19907C00BB4459 /* WCDBSwift in Frameworks */,
964198C42729A7EC0001AB97 /* SwiftyXMLParser in Frameworks */,
964198C02729A7E30001AB97 /* Alamofire in Frameworks */,
16539DCF278AD8700035B9DF /* SotoS3 in Frameworks */,
Expand Down Expand Up @@ -613,6 +617,7 @@
4B6C62F923613AEF008E3735 /* NSImage+Extension.swift */,
4B2B3355236C3B6400C9F2CA /* NSView+Extension.swift */,
4B2B3353236BC5AB00C9F2CA /* NSButton+Extension.swift */,
03F383C92C15A6BC00795FD3 /* URL+sha1.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -924,6 +929,7 @@
1649393C285E2620007278DA /* CocoaLumberjack */,
1649393E285E2620007278DA /* CocoaLumberjackSwift */,
1649394C285F1C45007278DA /* Zip */,
03714B922C19907C00BB4459 /* WCDBSwift */,
);
productName = uPic;
productReference = 16EC9A0222ABBBB4001B6C89 /* uPic.app */;
Expand Down Expand Up @@ -1025,6 +1031,7 @@
16539DCD278AD8700035B9DF /* XCRemoteSwiftPackageReference "soto" */,
1649393B285E2620007278DA /* XCRemoteSwiftPackageReference "CocoaLumberjack" */,
1649394B285F1C44007278DA /* XCRemoteSwiftPackageReference "Zip" */,
03714B912C19907C00BB4459 /* XCRemoteSwiftPackageReference "wcdb" */,
);
productRefGroup = 16A6DC4B22AA375700813706;
projectDirPath = "";
Expand Down Expand Up @@ -1264,6 +1271,7 @@
16AFDB3824E50F450008E5A7 /* S3Region.swift in Sources */,
96F633F625AEC3C7005514EB /* DatabaseViewController.swift in Sources */,
16CD34FC23BC8966005B52F2 /* MimeType.swift in Sources */,
03F383CA2C15A6BC00795FD3 /* URL+sha1.swift in Sources */,
16F04EE623BCC45F00CCA2FE /* Option.swift in Sources */,
169F074422AF7A3D008E8525 /* StatusMenuController.swift in Sources */,
167DDBEB22C76F5000B03357 /* GithubUploader.swift in Sources */,
Expand Down Expand Up @@ -1552,9 +1560,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "uPic/Supporting Files/uPicDebug.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1565,7 +1574,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -1585,9 +1594,10 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = "uPic/Supporting Files/uPic.entitlements";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 24;
CURRENT_PROJECT_VERSION = 25;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = W863J6W8DZ;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -1598,7 +1608,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.15;
MARKETING_VERSION = 1.4.2;
MARKETING_VERSION = 1.4.3;
PRODUCT_BUNDLE_IDENTIFIER = com.svend.uPic.macos;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down Expand Up @@ -1758,6 +1768,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
03714B912C19907C00BB4459 /* XCRemoteSwiftPackageReference "wcdb" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Tencent/wcdb";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 2.1.0;
};
};
1649393B285E2620007278DA /* XCRemoteSwiftPackageReference "CocoaLumberjack" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/CocoaLumberjack/CocoaLumberjack.git";
Expand Down Expand Up @@ -1849,6 +1867,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
03714B922C19907C00BB4459 /* WCDBSwift */ = {
isa = XCSwiftPackageProductDependency;
package = 03714B912C19907C00BB4459 /* XCRemoteSwiftPackageReference "wcdb" */;
productName = WCDBSwift;
};
1649393C285E2620007278DA /* CocoaLumberjack */ = {
isa = XCSwiftPackageProductDependency;
package = 1649393B285E2620007278DA /* XCRemoteSwiftPackageReference "CocoaLumberjack" */;
Expand Down
19 changes: 19 additions & 0 deletions uPic.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "4ef337139bd210e7da4124ce672b7e886fd0a73988e4c7957d7fa3f522103a10",
"pins" : [
{
"identity" : "alamofire",
Expand Down Expand Up @@ -99,6 +100,15 @@
"version" : "6.5.0"
}
},
{
"identity" : "sqlcipher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Tencent/sqlcipher",
"state" : {
"revision" : "f7e94ce2fad6fc55cfc1180592addd654f140058",
"version" : "1.4.4"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -198,6 +208,15 @@
"version" : "5.6.0"
}
},
{
"identity" : "wcdb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Tencent/wcdb",
"state" : {
"revision" : "b30137b3002ae7fcf8a31dae61168e406d41d1a3",
"version" : "2.1.5"
}
},
{
"identity" : "zip",
"kind" : "remoteSourceControl",
Expand Down
40 changes: 30 additions & 10 deletions uPic/Extensions/Data+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,67 @@ import Cocoa
import CryptoSwift

extension Data {

func toBytes() -> Array<UInt8> {
return self.bytes
}

func toMd5() -> String {
return self.md5().toHexString()
}

func toBase64() -> String {
return self.bytes.toBase64()
}

func toSha1() -> String {
return self.sha1().toHexString()
}

func toSha224() -> String {
return self.sha224().toHexString()
}

func toSha256() -> String {
return self.sha256().toHexString()
}

func toSha384() -> String {
return self.sha384().toHexString()
}

func toSha512() -> String {
return self.sha512().toHexString()
}

func toString() -> String {
return String(data: self, encoding: .utf8)!
}

// 转换图片格式
func convertImageData(_ fileType: NSBitmapImageRep.FileType = .png) -> Data? {
let bitmap = NSBitmapImageRep(data: self)
let data = bitmap?.representation(using: fileType, properties: [:])
return data
}

/// Get github file sha.
func githubSHA() -> String {
let header = "blob \(self.count)\0".data(using: .utf8)!
var store = Data()
store.append(header)
store.append(self)
let sha1 = store.sha1().toHexString()
return sha1
}

/// Get github file sha.
func githubSHAAsync() async -> String {
return await withCheckedContinuation { continuation in
DispatchQueue.global().async {
let sha1 = self.githubSHA()
continuation.resume(returning: sha1)
}
}
}
}
28 changes: 28 additions & 0 deletions uPic/Extensions/URL+sha1.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// URL+sha1.swift
// uPic
//
// Created by tisfeng on 2024/6/9.
// Copyright © 2024 Svend Jin. All rights reserved.
//

import Foundation
import CryptoSwift

extension URL {
/// Get github file sha.
func githubSHA() -> String? {
do {
let fileData = try Data(contentsOf: self)
let header = "blob \(fileData.count)\0".data(using: .utf8)!
var store = Data()
store.append(header)
store.append(fileData)
let sha1 = store.sha1().toHexString()
return sha1
} catch {
print("Error reading file: \(error)")
return nil
}
}
}
4 changes: 2 additions & 2 deletions uPic/Managers/DBManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class DBManager {
private var database: Database!

init() {
Database.globalTrace(ofError: { (error) in
Database.globalTraceError { error in
assert(error.level != .Fatal)
print(error)
})
}
debugPrintOnly("数据库地址:\(Constants.CachePath.databasePath)")
database = Database(at: Constants.CachePath.databasePath)
createHistoryTable()
Expand Down
Loading