mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-23 03:32:13 -04:00
Merge pull request #811 from kiwix/789-zim-metadata-illustration-is-not-read-properly
Fix favIcons of opened ZIM files (not added via catalog download)
This commit is contained in:
commit
16a1320615
@ -34,6 +34,7 @@
|
||||
// nullable attributes
|
||||
@property (nonatomic, strong, nullable) NSURL *downloadURL;
|
||||
@property (nonatomic, strong, nullable) NSURL *faviconURL;
|
||||
@property (nonatomic, strong, nullable) NSData *faviconData;
|
||||
@property (nonatomic, strong, nullable) NSString *flavor;
|
||||
|
||||
// assigned attributes
|
||||
|
@ -59,6 +59,7 @@
|
||||
|
||||
SAFE_READ(self.downloadURL, [self getURL:_book->getUrl()]);
|
||||
SAFE_READ(self.faviconURL, [self getFaviconURLFromBook:_book]);
|
||||
SAFE_READ(self.faviconData, [self getFaviconDataFromBook:_book]);
|
||||
SAFE_READ(self.flavor, [self getFlavorFromBook:_book]);
|
||||
|
||||
SAFE_READ_BOOL(self.hasDetails, _book->getTagBool("details"));
|
||||
@ -99,7 +100,7 @@
|
||||
return [NSURL URLWithString:[NSString stringWithUTF8String:urlString.c_str()]];
|
||||
}
|
||||
|
||||
- (NSURL *)getFaviconURLFromBook:(kiwix::Book *)book {
|
||||
- (NSURL * _Nullable)getFaviconURLFromBook:(kiwix::Book *)book {
|
||||
try {
|
||||
std::string url = book->getIllustrations().at(0)->url;
|
||||
return [self getURL:url];
|
||||
@ -108,6 +109,19 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSData * _Nullable)getFaviconDataFromBook:(kiwix::Book *)book {
|
||||
try {
|
||||
std::string dataString = book->getIllustrations().at(0)->getData();
|
||||
if(dataString.length() == 0) {
|
||||
return nil;
|
||||
}
|
||||
NSData *favIconData = [NSData dataWithBytes: dataString.data() length: dataString.length()];
|
||||
return favIconData;
|
||||
} catch (std::exception) {
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)getFlavorFromBook:(kiwix::Book *)book {
|
||||
NSString *flavor = [NSString stringWithUTF8String:book->getFlavour().c_str()];
|
||||
return [flavor stringByReplacingOccurrencesOfString:@"_" withString:@""];
|
||||
|
@ -129,12 +129,13 @@ struct LibraryOperations {
|
||||
zimFile.requiresServiceWorkers = metadata.requiresServiceWorkers
|
||||
zimFile.size = metadata.size.int64Value
|
||||
|
||||
// Only overwrite favicon data and url if there is a new value
|
||||
if let url = metadata.downloadURL { zimFile.downloadURL = url }
|
||||
if let url = metadata.faviconURL { zimFile.faviconURL = url }
|
||||
// Overwrite these, only if there are new values
|
||||
if let faviconURL = metadata.faviconURL { zimFile.faviconURL = faviconURL }
|
||||
if let faviconData = metadata.faviconData { zimFile.faviconData = faviconData }
|
||||
if let downloadURL = metadata.downloadURL { zimFile.downloadURL = downloadURL }
|
||||
}
|
||||
|
||||
//MARK: - Deletion
|
||||
// MARK: - Deletion
|
||||
|
||||
/// Unlink a zim file from library, delete associated bookmarks, and delete the file.
|
||||
/// - Parameter zimFile: the zim file to delete
|
||||
|
Loading…
x
Reference in New Issue
Block a user