Skip to content
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

fix wikimedia photos #3278

Merged
merged 4 commits into from
Dec 11, 2023
Merged

fix wikimedia photos #3278

merged 4 commits into from
Dec 11, 2023

Conversation

Skalii
Copy link
Contributor

@Skalii Skalii commented Dec 8, 2023

No description provided.

self.location.latitude,
self.location.longitude,
[OAIAPHelper isPaidVersion] ? @"paid" : @"free",
(preferredLang && preferredLang.length > 0 ? [@"&lang=" stringByAppendingString:preferredLang] : @""),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better not to use two ternary operators in one condition

_wikiCardsReady = YES;
[self sendNearbyOtherImagesRequest:cards];
}];
[self sendNearbyOtherImagesRequest:[NSMutableArray array]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retain cycle ?

@@ -15,6 +15,10 @@
#define CM_LIMIT @"&cmlimit=500"
#define FORMAT_JSON @"&format=json"
#define IMAGE_BASE_URL @"https://commons.wikimedia.org/wiki/Special:FilePath/"
#define USE_OSMAND_WIKI_API YES
#define OSMAND_API_ENDPOINT @"https://osmand.net/api/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use #define. it is not type-safe. static NSString* const OSMAND_API_ENDPOINT = @"https://osmand.net/api/";

- (OAWikiImage *)getOsmandApiWikiImage:(NSString *)imageUrl
{
NSString *url = [imageUrl stringByRemovingPercentEncoding];
NSString *imageHiResUrl = [url stringByReplacingOccurrencesOfString:@" " withString:@"_"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imageHiResUrl - Interesting name:)

{
url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *urlObj = [[NSURL alloc] initWithString:url];
NSURLSession *aSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*session

}
dispatch_async(dispatch_get_main_queue(), ^{
[cards addObjectsFromArray:resultCards];
(byCategory ? _wikimediaCardsReady : _wikidataCardsReady) = YES;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace duplicate checks with 'if byCategory'.

NSURLSession *aSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[aSession dataTaskWithURL:urlObj completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSMutableArray<OAAbstractCard *> *resultCards = [NSMutableArray array];
if (((NSHTTPURLResponse *)response).statusCode == 200)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add error logging to the log output?

{
NSString *safeWikidataTagContent = [wikidataTagContent stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *urlObj = [[NSURL alloc] initWithString: [NSString stringWithFormat:@"%@%@%@%@", WIKIDATA_API_ENDPOINT, WIKIDATA_ACTION, safeWikidataTagContent, FORMAT_JSON]];
NSURLSession *aSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*session

NSString *url = [NSString stringWithFormat:@"%@%@%@%@%@", WIKIMEDIA_API_ENDPOINT, WIKIMEDIA_ACTION, wikiMediaTagContent, CM_LIMIT, FORMAT_JSON];
url = [url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
NSURL *urlObj = [[NSURL alloc] initWithString:url];
NSURLSession *aSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*session

@alex-osm alex-osm merged commit 2a2511d into master Dec 11, 2023
@alex-osm alex-osm deleted the fix_wikimedia_photos branch December 11, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Infer Wikimedia Commons category from Wikidata to show photos (P373)
3 participants