Skip to content

Commit

Permalink
fix: avoid querying some sources if not from arXiv
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanChain committed Nov 14, 2024
1 parent 974932d commit bff7749
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/modules/arxiv-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class PaperFinder {

async semanticScholar(): Promise<PaperIdentifier | undefined> {
// Currently, only searching arXiv paper on semanticScholar is supported
const urlHost = new URL(this.preprintURL).hostname;
if (urlHost !== KNOWN_PREPRINT_SERVERS.arxiv) return undefined;
const idMatch = this.preprintURL.match(/\/(?<arxiv>[^/]+)$/);
if (idMatch?.groups?.arxiv === undefined) {
return undefined;
Expand All @@ -205,6 +207,9 @@ class PaperFinder {
}

async dblp(): Promise<PaperIdentifier | undefined> {
// Well, CS guys won't use preprint servers other than arXiv
const urlHost = new URL(this.preprintURL).hostname;
if (urlHost !== KNOWN_PREPRINT_SERVERS.arxiv) return undefined;
const dblpAPI = "https://dblp.org/search/publ/api";
const dblpURL = `${dblpAPI}?q=${encodeURIComponent(this.title)}&format=json`;
const jsonResp = await fetch(dblpURL);
Expand All @@ -215,7 +220,9 @@ class PaperFinder {
// Require exact title match
if (this.title !== title) {
ztoolkit.log(
`DBLP title mismatch: expected "${this.title}", got "${title}"`,
title
? `DBLP title mismatch: expected "${this.title}", got "${title}"`
: "Paper not found on DBLP",
);
return;
}
Expand Down Expand Up @@ -244,7 +251,9 @@ class PaperFinder {
// Require exact title match
if (this.title !== title) {
ztoolkit.log(
`PubMed title mismatch: expected "${this.title}", got "${title}"`,
title
? `PubMed title mismatch: expected "${this.title}", got "${title}"`
: "Paper not found on PubMed",
);
return;
}
Expand All @@ -257,6 +266,8 @@ class PaperFinder {
}

async arXivPDF(): Promise<PaperIdentifier | undefined> {
const urlHost = new URL(this.preprintURL).hostname;
if (urlHost !== KNOWN_PREPRINT_SERVERS.arxiv) return undefined;
let localVersion = 0;
for (const attachmentID of this.item.getAttachments()) {
const attachment = await Zotero.Items.getAsync(attachmentID);
Expand Down

0 comments on commit bff7749

Please sign in to comment.