Skip to content

Commit

Permalink
Refactor file link handling in Attachment class
Browse files Browse the repository at this point in the history
- Exception handling for html attachments
  • Loading branch information
e-zz committed Dec 29, 2023
1 parent 090c19e commit f1efdf3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/zotero/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ export class Attachment {
file.contentType = raw.contentType;
file.localLink = `zotero://select/library/items/${raw.key}`;

if (file.linkMode === "imported_file") {
switch (file.linkMode) {
case "imported_file":
file.baseName = raw.filename;
file.relPath = raw.filename;
file.button = buttonImportedFile(file.key, file.relPath);
} else { // "linked_file"
file.baseName = raw.path.split(/[:\/]/).pop();
break;
case "linked_file":
file.baseName = raw.path.split(/[:\/]/).pop(); // Warn: The name of a PDF could be different from it's raw.title
file.relPath = raw.path.replace("attachments:", "");
file.button = buttonLinkedFile(file.relPath);
break;
default:
console.log(`Unhandled linkMode ${file.linkMode} for ${file.localLink}`);
}

return file
Expand Down

0 comments on commit f1efdf3

Please sign in to comment.