-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding ability to embed PDFs in Notion using Zotero Web API #107
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -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}`; | ||||||||
Comment on lines
+150
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zotero has a
Suggested change
|
||||||||
} | ||||||||
} | ||||||||
return 'https://zotero.org'; | ||||||||
} | ||||||||
|
||||||||
|
||||||||
public getNotionLinkAttachments(): Zotero.Item[] { | ||||||||
const attachmentIDs = this.zoteroItem | ||||||||
.getAttachments(false) | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,6 +287,8 @@ class Notero { | |
|
||
if ('url' in response) { | ||
await noteroItem.saveNotionLinkAttachment(response.url); | ||
const pageID = Notion.getPageIDFromURL(Notion.convertWebURLToLocal(response.url)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can actually get the page ID from |
||
const response_block = await notion.addEmbedToPage(noteroItem, pageID); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,16 @@ | |
value="¬ero.preferences.notionDatabaseID;" | ||
control="notero-notionDatabaseID" /> | ||
<textbox id="notero-notionDatabaseID" preference="pref-notionDatabaseID" /> | ||
<separator /> | ||
<label id="notero-zoteroAPIKey-label" | ||
value="¬ero.preferences.zoteroAPIKey;" | ||
control="notero-zoteroAPIKey" /> | ||
<textbox id="notero-zoteroAPIKey" preference="pref-zoteroAPIKey" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see why the preferences window isn't registering these values. In addition to what you have here, you also need to add a corresponding <preference id="pref-zoteroAPIKey"
name="extensions.notero.zoteroAPIKey"
type="string" /> |
||
<separator /> | ||
<label id="notero-zoteroUserID-label" | ||
value="¬ero.preferences.zoteroUserID;" | ||
control="notero-zoteroUserID" /> | ||
<textbox id="notero-zoteroUserID" preference="pref-zoteroUserID" /> | ||
</groupbox> | ||
|
||
<separator /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
notero.preferences.collectionName = Collection Name | ||
notero.preferences.notionToken = Notion Integration Token | ||
notero.preferences.notionDatabaseID = Notion Database ID | ||
notero.preferences.zoteroAPIKey = Zotero API Key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your issue comment, you mentioned that we could use
getBestAttachment()
for this. Just curious if that ended up not working for you?