-
Notifications
You must be signed in to change notification settings - Fork 19
Support IHateMoney QR codes #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,7 @@ class ProjectManager: ObservableObject { | |
|
|
||
| func openedByURL(url: URL) { | ||
| let data = url.decodeCospendString() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gehört hier dann noch der Fall für IHM hin? |
||
| guard let _ = data.server, | ||
| let _ = data.project | ||
| else { | ||
| return | ||
| } | ||
| guard data != nil else { return } | ||
| openedByURL = url | ||
| } | ||
|
|
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Die drei |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,43 +176,115 @@ extension StringProtocol { | |
| } | ||
| } | ||
|
|
||
| typealias ProjectData = (server: URL?, project: String?, passwd: String?) | ||
| protocol ProjectData { | ||
| var server: URL { get } | ||
| var project: String { get } | ||
| } | ||
|
|
||
| struct ProjectDataWithToken: ProjectData { | ||
| var server: URL | ||
| var project: String | ||
| var token: String | ||
|
|
||
| init(server: URL, project: String, token: String) { | ||
| self.server = server | ||
| self.project = project | ||
| self.token = token | ||
| } | ||
|
|
||
| } | ||
|
|
||
| struct ProjectDataWithPassword: ProjectData { | ||
| var server: URL | ||
| var project: String | ||
| var password: String? | ||
|
|
||
| init(server: URL, project: String, password: String?) { | ||
| self.server = server | ||
| self.project = project | ||
| self.password = password | ||
| } | ||
| } | ||
|
|
||
| extension URL { | ||
| func decodeMoneyBusterString() -> ProjectData { | ||
| func decodeMoneyBusterString() -> ProjectDataWithPassword? { | ||
| guard absoluteString.hasPrefix("https://net.eneiluj.moneybuster.cospend/"), | ||
| pathComponents.count >= 3, pathComponents.count <= 4 else { return (nil, nil, nil) } | ||
| return (URL(string: "https://" + pathComponents[1]), pathComponents[2], pathComponents[safe: 3]) | ||
| pathComponents.count >= 3, pathComponents.count <= 4 else { | ||
| return nil | ||
| } | ||
|
|
||
| guard let hostUrl = URL(string: "https://" + pathComponents[1]) else { | ||
| return nil | ||
| } | ||
|
|
||
| let password = pathComponents[safe: 3] | ||
|
|
||
| return ProjectDataWithPassword( | ||
| server: hostUrl, | ||
| project: pathComponents[2], | ||
| password: password | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| extension URL { | ||
| func decodeCospendString() -> ProjectData { | ||
| func decodeCospendString() -> ProjectDataWithPassword? { | ||
| guard let host = host, | ||
| let scheme = scheme, | ||
| scheme.localizedCaseInsensitiveContains("cospend") | ||
| else { | ||
| return (nil, nil, nil) | ||
| return nil | ||
| } | ||
| var hostString = "https://\(host)" | ||
|
|
||
| var hostString = host | ||
|
|
||
| if let port = port {hostString += ":\(port)"} | ||
|
|
||
| if pathComponents.count > 3 { | ||
| hostString += "/" + pathComponents[1..<(pathComponents.count - 2)].joined(separator: "/") | ||
| } | ||
|
|
||
| return (URL(string: hostString), | ||
| pathComponents[safe: pathComponents.count - 2], | ||
| pathComponents.last) | ||
|
|
||
| guard | ||
| let hostUrl = URL(string: "https://" + hostString), | ||
| let project = pathComponents[safe: pathComponents.count - 2], | ||
| let password = pathComponents.last | ||
| else { return nil } | ||
|
|
||
| return ProjectDataWithPassword( | ||
| server: hostUrl, | ||
| project: project, | ||
| password: password) | ||
| } | ||
| } | ||
|
|
||
| extension URL { | ||
| func decodeIHateMoenyString() -> ProjectDataWithToken? { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tippfehler bei Money lieber frühzeitig korrigieren
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Und, falls Funktion erhalten bleiben soll, |
||
| guard var host = host, let scheme = scheme, scheme.localizedCaseInsensitiveContains("ihatemoney") else { | ||
| return nil | ||
| } | ||
|
|
||
| let hostUrl = "https://" + host | ||
|
|
||
| guard | ||
| let url = URL(string: hostUrl), | ||
| let project = pathComponents[safe: pathComponents.count - 3], | ||
| let token = pathComponents.last | ||
| else { return nil} | ||
|
|
||
| return ProjectDataWithToken(server: url, project: project, token: token) | ||
| } | ||
| } | ||
|
|
||
| extension URL { | ||
| func decodeQRCode() -> ProjectData { | ||
| guard let scheme = scheme else { return (nil, nil, nil) } | ||
| return scheme.contains("cospend") ? decodeCospendString() : decodeMoneyBusterString() | ||
| func decodeQRCode() -> ProjectData? { | ||
| guard let scheme = scheme else { return nil } | ||
| if scheme.contains("cospend") { | ||
| return decodeCospendString() | ||
| } else if scheme.contains("ihatemoney") { | ||
| return decodeIHateMoenyString() | ||
| } else { | ||
| return decodeMoneyBusterString() | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methode erzeugt nur einen Log, sinnvoll im Produktivcode?