-
-
Notifications
You must be signed in to change notification settings - Fork 106
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?
Conversation
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.
@advaitathreya, thanks for sharing this! I hadn't dug into the Zotero API yet, so I appreciate that you found the correct URL for retrieving the PDF files.
I agree this would need a way for users to opt in to the embedding functionality, and it should definitely be possible to add that into the preferences.
My biggest concern with this approach is that it requires embedding a user's Zotero API key into Notion pages (in the embed URL), and I see that as having potential to open the user up to security vulnerabilities. I imagine this is one of the reasons why the Zotero API docs recommend against authenticating with the API in this way. I suppose we could leave this decision up to the user, but I'd want to put a clear disclaimer about the risk implied by using this functionality.
I can think of a couple other things we'd need to figure out before we could release this:
- We need to somehow confirm that the user is signed in to a Zotero account and has syncing enabled since this would be a prerequisite for this feature. If they don't, it'd be nice to display a message describing what this feature could do if they enabled Zotero account syncing.
- We need to find a way to prevent re-appending the embed block whenever the item is modified in Zotero so that we don't end up with multiple embeds of the file.
That said, I think this is a great start to a solution for this!
const attachmentIDs = this.zoteroItem | ||
.getAttachments(false) | ||
.slice() | ||
// Sort to get largest ID first | ||
.sort((a, b) => b - a); | ||
|
||
for (const id of attachmentIDs) { |
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?
const pdfItemID = Zotero.URI.getItemURI(attachment).split('/').pop(); | ||
return `https://api.zotero.org/users/${zoteroUserID}/items/${pdfItemID}/file/view?key=${zoteroAPIKey}`; |
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.
Zotero has a getItemPath()
method that should make this easier. It also includes the user ID, so we don't need to have that as a separate pref. 🙂
const pdfItemID = Zotero.URI.getItemURI(attachment).split('/').pop(); | |
return `https://api.zotero.org/users/${zoteroUserID}/items/${pdfItemID}/file/view?key=${zoteroAPIKey}`; | |
return `https://api.zotero.org/${Zotero.URI.getItemPath(attachment)}/file/view?key=${zoteroAPIKey}`; |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can actually get the page ID from response.id
.
<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 comment
The 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>
element within the <preferences>
element on line 14.
<preference id="pref-zoteroAPIKey"
name="extensions.notero.zoteroAPIKey"
type="string" />
Thanks for your comments! I will come back to this when I have time and work on trying to address them. On a different note, I just realized that PDF annotations made within the Zotero app are not stored with the PDF file but separately, which sort of negates my initial motivation to embed the PDF in Notion, which was to have one central place where all the annotations and notes on a certain article are saved. There's definitely still a way to do this, since the annotations are also supposedly accessible through the API, but this is not gonna be a straightforward task. |
Are there any news on this functionality? |
Just as an update from my end, I no longer use Notion (moved to using Obsidian to have the ability to save my notes locally), so I'm not working on this. Still think this is a wonderful plugin though, just not something I need anymore. |
Is it possible to embed the pdf that is stored in the Zotero library in Notion now? |
There haven't been any changes to the Notion or Zotero APIs, so the approach discussed in this PR is still the only way I know for embedding a Zotero item's PDF into a Notion page. This means it's also still vulnerable to the security issue I described above. @jiwatode-mohit, if you're interested in manually embedding a PDF into Notion and accept the security risk, I believe you can do so by embedding a URL with the following format:
You'll need to fill in the values for those three pieces of the URL: You can find each of them as follows after logging into your Zotero account (https://www.zotero.org/user/login). userIDYou can find your userID on this page: https://www.zotero.org/settings/keys privateKeyYou can create a new private key here: https://www.zotero.org/settings/keys/new attachmentKey
|
I've added the ability to embed PDFs using the Zotero Web API. This is not ready to actually be released, there are a lot of issues that need to be fixed that I was unable to figure out:
I also don't think I followed appropriate conventions, since I have not used TypeScript before. I hope this isn't too much additional work for you to clean up, my motivation in doing this was mostly just to see if it would be possible. Look forward to seeing a cleaned up version of this in some future release if you think it is worth it!
References #4