Generates SIP002 QR code

This commit is contained in:
Timothy Qiu
2017-08-01 21:40:09 +08:00
parent 72c52047f4
commit e7cc26f81d
4 changed files with 44 additions and 1 deletions

View File

@ -246,7 +246,7 @@ class ServerProfile: NSObject, NSCopying {
return true
}
func URL() -> Foundation.URL? {
private func makeLegacyURL() -> URL? {
var url = URLComponents()
url.host = serverHost
@ -275,6 +275,38 @@ class ServerProfile: NSObject, NSCopying {
}
return nil
}
func URL(legacy: Bool = false) -> URL? {
// If you want the URL from <= 1.5.1
if (legacy) {
return self.makeLegacyURL()
}
guard let rawUserInfo = "\(method):\(password)".data(using: .utf8) else {
return nil
}
let paddings = CharacterSet(charactersIn: "=")
let userInfo = rawUserInfo.base64EncodedString().trimmingCharacters(in: paddings)
var items = [URLQueryItem(name: "OTA", value: ota.description)]
if enabledKcptun {
items.append(URLQueryItem(name: "Kcptun", value: enabledKcptun.description))
items.append(contentsOf: kcptunProfile.urlQueryItems())
}
var comps = URLComponents()
comps.scheme = "ss"
comps.host = serverHost
comps.port = Int(serverPort)
comps.user = userInfo
comps.fragment = remark
comps.queryItems = items
let url = try? comps.asURL()
return url
}
func title() -> String {
if remark.isEmpty {