mirror of
https://github.com/mas-cli/mas
synced 2024-11-22 03:23:08 +00:00
👀 Scrape the app page only for lookup, not search
This commit is contained in:
parent
cfef4aebc4
commit
a7f8dfea22
1 changed files with 18 additions and 12 deletions
|
@ -97,19 +97,13 @@ class MasStoreSearch: StoreSearch {
|
|||
/// or an Error if there is a problem with the network request.
|
||||
func lookup(app appId: Int) -> Promise<SearchResult?> {
|
||||
let url = MasStoreSearch.lookupURL(forApp: appId)
|
||||
return loadSearchResults(url).map { results in results.first }
|
||||
}
|
||||
|
||||
private func loadSearchResults(_ url: URL) -> Promise<[SearchResult]> {
|
||||
firstly {
|
||||
networkManager.loadData(from: url)
|
||||
}.map { data -> [SearchResult] in
|
||||
do {
|
||||
return try JSONDecoder().decode(SearchResultList.self, from: data).results
|
||||
} catch {
|
||||
throw MASError.jsonParsing(error: error as NSError)
|
||||
return firstly {
|
||||
loadSearchResults(url)
|
||||
}.then { results -> Guarantee<SearchResult?> in
|
||||
guard let result = results.first else {
|
||||
return .value(nil)
|
||||
}
|
||||
}.thenMap { result -> Guarantee<SearchResult> in
|
||||
|
||||
guard let pageUrl = URL(string: result.trackViewUrl)
|
||||
else {
|
||||
return .value(result)
|
||||
|
@ -136,6 +130,18 @@ class MasStoreSearch: StoreSearch {
|
|||
}
|
||||
}
|
||||
|
||||
private func loadSearchResults(_ url: URL) -> Promise<[SearchResult]> {
|
||||
firstly {
|
||||
networkManager.loadData(from: url)
|
||||
}.map { data -> [SearchResult] in
|
||||
do {
|
||||
return try JSONDecoder().decode(SearchResultList.self, from: data).results
|
||||
} catch {
|
||||
throw MASError.jsonParsing(error: error as NSError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// App Store pages indicate:
|
||||
// - compatibility with Macs with Apple Silicon
|
||||
// - (often) a version that is newer than what is listed in search results
|
||||
|
|
Loading…
Reference in a new issue