mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
parsing share link
This commit is contained in:
1 file changed
+33
-7
@@ -14,12 +14,38 @@ struct EmojiPack: Identifiable, Codable {
|
|||||||
var name: String
|
var name: String
|
||||||
var description: String
|
var description: String
|
||||||
var items: [String]
|
var items: [String]
|
||||||
// var items: [EmojiPack.Item]
|
// var items: [EmojiPack.Item]
|
||||||
|
|
||||||
// struct Item: Identifiable, Codable, Equatable {
|
// struct Item: Identifiable, Codable, Equatable {
|
||||||
// var id: UUID
|
// var id: UUID
|
||||||
// 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 }
|
||||||
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||