diff --git a/content/notero-item.ts b/content/notero-item.ts index 9f2b4bc1..6a686608 100644 --- a/content/notero-item.ts +++ b/content/notero-item.ts @@ -1,4 +1,5 @@ import Notion from './notion'; +import { NoteroPref, getNoteroPref } from './notero-pref'; const APA_STYLE = 'bibliography=http://www.zotero.org/styles/apa'; @@ -134,6 +135,26 @@ export default class NoteroItem { return Zotero.URI.getItemURI(this.zoteroItem); } + public getPDFURL(): string { + const zoteroAPIKey = getNoteroPref(NoteroPref.zoteroAPIKey); + const zoteroUserID = getNoteroPref(NoteroPref.zoteroUserID); + const attachmentIDs = this.zoteroItem + .getAttachments(false) + .slice() + // Sort to get largest ID first + .sort((a, b) => b - a); + + for (const id of attachmentIDs) { + const attachment = Zotero.Items.get(id); + if (attachment.attachmentContentType == 'application/pdf') { + const pdfItemID = Zotero.URI.getItemURI(attachment).split('/').pop(); + return `https://api.zotero.org/users/${zoteroUserID}/items/${pdfItemID}/file/view?key=${zoteroAPIKey}`; + } + } + return 'https://zotero.org'; + } + + public getNotionLinkAttachments(): Zotero.Item[] { const attachmentIDs = this.zoteroItem .getAttachments(false) diff --git a/content/notero-pref.ts b/content/notero-pref.ts index 1bd2ae7c..15a54a74 100644 --- a/content/notero-pref.ts +++ b/content/notero-pref.ts @@ -4,6 +4,8 @@ export enum NoteroPref { notionDatabaseID = 'notionDatabaseID', notionToken = 'notionToken', syncOnModifyItems = 'syncOnModifyItems', + zoteroUserID = 'zoteroUserID', + zoteroAPIKey = 'zoteroAPIKey', } type NoteroPrefValue = Partial<{ @@ -11,6 +13,8 @@ type NoteroPrefValue = Partial<{ [NoteroPref.collectionSyncConfigs]: string; [NoteroPref.notionDatabaseID]: string; [NoteroPref.notionToken]: string; + [NoteroPref.zoteroAPIKey]: string; + [NoteroPref.zoteroUserID]: string; [NoteroPref.syncOnModifyItems]: boolean; }>; @@ -35,6 +39,8 @@ export function getNoteroPref
(
[NoteroPref.collectionSyncConfigs]: stringPref,
[NoteroPref.notionDatabaseID]: stringPref,
[NoteroPref.notionToken]: stringPref,
+ [NoteroPref.zoteroAPIKey]: stringPref,
+ [NoteroPref.zoteroUserID]: stringPref,
[NoteroPref.syncOnModifyItems]: booleanPref,
}[pref];
}
diff --git a/content/notero.ts b/content/notero.ts
index a3d76599..7fab0dc9 100644
--- a/content/notero.ts
+++ b/content/notero.ts
@@ -287,6 +287,8 @@ class Notero {
if ('url' in response) {
await noteroItem.saveNotionLinkAttachment(response.url);
+ const pageID = Notion.getPageIDFromURL(Notion.convertWebURLToLocal(response.url));
+ const response_block = await notion.addEmbedToPage(noteroItem, pageID);
}
}
}
diff --git a/content/notion.ts b/content/notion.ts
index a87b1d34..eab61d1a 100644
--- a/content/notion.ts
+++ b/content/notion.ts
@@ -10,6 +10,9 @@ import {
CreatePageResponse,
GetDatabaseResponse,
UpdatePageResponse,
+ AppendBlockChildrenParameters,
+ AppendBlockChildrenResponse,
+ UpdateBlockResponse
} from '@notionhq/client/build/src/api-endpoints';
import 'core-js/stable/object/from-entries';
import NoteroItem from './notero-item';
@@ -238,6 +241,11 @@ export default class Notion {
type: 'url',
buildRequest: () => item.getZoteroURI(),
},
+ {
+ name: 'File URL',
+ type: 'url',
+ buildRequest: () => item.getPDFURL(),
+ },
];
const validPropertyDefinitions =
@@ -254,4 +262,22 @@ export default class Notion {
return itemProperties;
}
+
+ public async addEmbedToPage(
+ item: NoteroItem,
+ pageID: string
+ ): Promise