123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import Foundation
- import CryptoKit
- func topicUrl(baseUrl: String, topic: String) -> String {
- return "\(baseUrl)/\(topic)"
- }
- func topicShortUrl(baseUrl: String, topic: String) -> String {
- return shortUrl(url: topicUrl(baseUrl: baseUrl, topic: topic))
- }
- func topicAuthUrl(baseUrl: String, topic: String) -> String {
- return "\(baseUrl)/\(topic)/auth"
- }
- func topicHash(baseUrl: String, topic: String) -> String {
- let data = Data(topicUrl(baseUrl: baseUrl, topic: topic).utf8)
- let digest = SHA256.hash(data: data)
- return digest.compactMap { String(format: "%02x", $0)}.joined()
- }
- func shortUrl(url: String) -> String {
- return url
- .replacingOccurrences(of: "http://", with: "")
- .replacingOccurrences(of: "https://", with: "")
- }
- func parseAllTags(_ tags: String?) -> [String] {
- return (tags?.components(separatedBy: ",") ?? [])
- .filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
- }
- func parseEmojiTags(_ tags: String?) -> [String] {
- return parseEmojiTags(parseAllTags(tags))
- }
- func parseEmojiTags(_ tags: [String]?) -> [String] {
- guard let tags = tags else { return [] }
- var emojiTags: [String] = []
- for tag in tags {
- if let emoji = EmojiManager.shared.getEmojiByAlias(alias: tag) {
- emojiTags.append(emoji.getUnicode())
- }
- }
- return emojiTags
- }
- func parseNonEmojiTags(_ tags: String?) -> [String] {
- return parseAllTags(tags)
- .filter { EmojiManager.shared.getEmojiByAlias(alias: $0) == nil }
- }
|