parsing share link

This commit is contained in:
neon443 committed 2026-04-10 01:07:18 +01:00
1 parent 14841dded0
commit 38924dd246
1 file changed
+28 -2
@@ -21,6 +21,32 @@ struct EmojiPack: Identifiable, Codable {
// var name: String // var name: String
// } // }
init(id: UUID, name: String, description: String, items: [String]) {
self.id = id
self.name = name
self.description = description
self.items = items
}
init(fromShareLink url: URL) {
guard var querySplit = url.query()?.split(separator: "&") else { fatalError() }
var queries: [String] = []
for split in querySplit {
if split.contains("%") {
queries.append(split.removingPercentEncoding!)
} else {
queries.append(String(split))
}
}
for query in queries {
print(query)
}
self.id = UUID()
self.name = ""
self.description = ""
self.items = []
}
mutating func add(_ newItem: String) { mutating func add(_ newItem: String) {
guard !items.contains(newItem) else { return } guard !items.contains(newItem) else { return }
withAnimation { withAnimation {
@@ -38,8 +64,7 @@ struct EmojiPack: Identifiable, Codable {
} }
func shareLink() -> URL { func shareLink() -> URL {
let scheme = URL(string: "stickerslack://")! var url = URL(string: "stickerslack://shared.pack/")!
var url: URL = scheme.appendingPathComponent("pack", conformingTo: .directory)
let data = try! JSONEncoder().encode(items) let data = try! JSONEncoder().encode(items)
let queries: [URLQueryItem] = [ let queries: [URLQueryItem] = [
@@ -50,6 +75,7 @@ struct EmojiPack: Identifiable, Codable {
] ]
url = url.appending(queryItems: queries) url = url.appending(queryItems: queries)
print(url.path(percentEncoded: true)) print(url.path(percentEncoded: true))
let _ = Self.init(fromShareLink: url)
return url return url
} }
} }
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.