Skip to content

Commit

Permalink
更新订阅Model
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWanderingCoel committed Jun 21, 2019
1 parent 27dd2e1 commit cd310f6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ShadowCoelModel/Subscribe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,31 @@ extension SubscribeError: CustomStringConvertible {

open class Subscribe: BaseModel {
@objc open dynamic var name: String = ""
@objc open dynamic var update: Bool = true
@objc open dynamic var url: String = ""

public static let subscribePrefix = "subscribe://"
}

// Public
extension Subscribe {
open func Uri() -> String {
if let name = Optional(name),
let url = Optional(url) {
let name_base64 = name.data(using: .utf8)?.base64EncodedString()
let name_base64_1 = name_base64!.replacingOccurrences(of: "=", with: "")
let name_base64_2 = name_base64_1.replacingOccurrences(of: "/", with: "_")
let url_base64 = url.data(using: .ascii)?.base64EncodedString()
let url_base64_1 = url_base64!.replacingOccurrences(of: "=", with: "")
let url_base64_2 = url_base64_1.replacingOccurrences(of: "/", with: "_")
let subscribe_uri = "\(name_base64_2):\(url_base64_2)"
return "subscribe://" + subscribe_uri
}
return ""
}

public class func uriIsSubscribe(_ uri: String) -> Bool {
return uri.lowercased().hasPrefix(Subscribe.subscribePrefix)
}

}

0 comments on commit cd310f6

Please sign in to comment.