Fix missing PDF attachment MIME type on opening

This commit is contained in:
Martynas Bagdonas 2020-12-14 12:23:26 +02:00 committed by Dan Stillman
parent 15a0415eba
commit 62c6f561a6

View file

@ -4075,9 +4075,21 @@ var ZoteroPane = new function()
}
var launchFile = async (path, contentType, itemID) => {
// Fix blank PDF attachment MIME type
if (!contentType) {
let item = await Zotero.Items.getAsync(itemID);
let path = await item.getFilePathAsync();
let type = 'application/pdf';
if (Zotero.MIME.sniffForMIMEType(await Zotero.File.getSample(path)) == type) {
contentType = type;
item.attachmentContentType = type;
await item.saveTx();
}
}
// Custom PDF handler
if (contentType === 'application/pdf') {
this.viewPDF(itemID, event.shiftKey);
// TODO: Still leave an option to use an external PDF viewer
return;
let pdfHandler = Zotero.Prefs.get("fileHandler.pdf");
if (pdfHandler) {