Merge pull request #706 from omnivore-app/fix/ios-pdf-content-detection

Extract contentType from safari
This commit is contained in:
Jackson Harper 2022-05-25 09:07:46 -07:00 committed by GitHub
commit 5dc205d4e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -19,11 +19,18 @@ public struct PageScrapePayload {
public let url: String
public let contentType: ContentType
init(url: String, title: String?, html: String?) {
init(url: String, title: String?, html: String?, contentType: String?) {
self.url = url
self.title = title
self.html = html
self.contentType = url.hasSuffix(".pdf") ? .pdf : .html
// If the content type was specified and we know its PDF, use that
// otherwise fallback to using file extensions.
if let contentType = contentType, contentType.contains("pdf") {
self.contentType = .pdf
} else {
self.contentType = url.hasSuffix(".pdf") ? .pdf : .html
}
}
}
@ -207,7 +214,7 @@ public enum PageScraper {
private extension PageScrapePayload {
static func make(url: URL?) -> PageScrapePayload? {
guard let url = url else { return nil }
return PageScrapePayload(url: url.absoluteString, title: nil, html: nil)
return PageScrapePayload(url: url.absoluteString, title: nil, html: nil, contentType: nil)
}
static func make(item: NSSecureCoding?) -> PageScrapePayload? {
@ -216,7 +223,8 @@ private extension PageScrapePayload {
guard let url = results?["url"] as? String else { return nil }
let html = results?["documentHTML"] as? String
let title = results?["title"] as? String
let contentType = results?["contentType"] as? String
return PageScrapePayload(url: url, title: title, html: html)
return PageScrapePayload(url: url, title: title, html: html, contentType: contentType)
}
}

View file

@ -5,6 +5,7 @@ ShareExtension.prototype = {
arguments.completionFunction({
'url': window.location.href,
'title': document.title.toString(),
'contentType': document.contentType,
'documentHTML': new XMLSerializer().serializeToString(document),
});
}