👀 Scrape the app page only for lookup, not search

This commit is contained in:
Chris Araman 2021-06-03 20:24:23 -07:00 committed by Ben Chatelain
parent cfef4aebc4
commit a7f8dfea22

View file

@ -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