@ncukondo/reference-manager 0.23.0 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{action-menu-C0-X1ndf.js → action-menu-t3Dz4j_h.js} +3 -3
- package/dist/chunks/{action-menu-C0-X1ndf.js.map → action-menu-t3Dz4j_h.js.map} +1 -1
- package/dist/chunks/{format-CBbnqK3-.js → format-Bp26FG4I.js} +2 -2
- package/dist/chunks/{format-CBbnqK3-.js.map → format-Bp26FG4I.js.map} +1 -1
- package/dist/chunks/{index-eZatWPDi.js → index-7R-uEYOu.js} +69 -27
- package/dist/chunks/index-7R-uEYOu.js.map +1 -0
- package/dist/chunks/{index-BVDVqLTl.js → index-BxREZKXb.js} +3 -3
- package/dist/chunks/index-BxREZKXb.js.map +1 -0
- package/dist/chunks/{index-BSWbcT3c.js → index-DAoyCWtW.js} +4 -4
- package/dist/chunks/{index-BSWbcT3c.js.map → index-DAoyCWtW.js.map} +1 -1
- package/dist/chunks/{index-BrETQT0g.js → index-DUFYNR2K.js} +25 -25
- package/dist/chunks/{index-BrETQT0g.js.map → index-DUFYNR2K.js.map} +1 -1
- package/dist/chunks/{reference-select-CogjIATu.js → reference-select-QtclFeCr.js} +3 -3
- package/dist/chunks/{reference-select-CogjIATu.js.map → reference-select-QtclFeCr.js.map} +1 -1
- package/dist/chunks/{style-select-CJzZczSq.js → style-select-CorMfmfN.js} +3 -3
- package/dist/chunks/{style-select-CJzZczSq.js.map → style-select-CorMfmfN.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/features/operations/attachments/add.d.ts.map +1 -1
- package/dist/features/operations/fulltext/fetch.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/package.json +2 -2
- package/dist/chunks/index-BVDVqLTl.js.map +0 -1
- package/dist/chunks/index-eZatWPDi.js.map +0 -1
|
@@ -11,7 +11,7 @@ import { z } from "zod";
|
|
|
11
11
|
import * as path from "node:path";
|
|
12
12
|
import path__default, { extname, join, dirname } from "node:path";
|
|
13
13
|
import "@citation-js/plugin-csl";
|
|
14
|
-
import fs__default, { stat, rename, copyFile, rm, readFile, mkdir, writeFile, mkdtemp, access,
|
|
14
|
+
import fs__default, { stat, rename, copyFile, unlink, rm, readFile, mkdir, writeFile, mkdtemp, access, rmdir } from "node:fs/promises";
|
|
15
15
|
import { tmpdir } from "node:os";
|
|
16
16
|
import "node:child_process";
|
|
17
17
|
import "node:crypto";
|
|
@@ -156,7 +156,16 @@ function findExistingFile(files, filename) {
|
|
|
156
156
|
async function copyOrMoveFile(sourcePath, destPath, move) {
|
|
157
157
|
try {
|
|
158
158
|
if (move) {
|
|
159
|
-
|
|
159
|
+
try {
|
|
160
|
+
await rename(sourcePath, destPath);
|
|
161
|
+
} catch (renameError) {
|
|
162
|
+
if (renameError instanceof Error && "code" in renameError && renameError.code === "EXDEV") {
|
|
163
|
+
await copyFile(sourcePath, destPath);
|
|
164
|
+
await unlink(sourcePath);
|
|
165
|
+
} else {
|
|
166
|
+
throw renameError;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
160
169
|
} else {
|
|
161
170
|
await copyFile(sourcePath, destPath);
|
|
162
171
|
}
|
|
@@ -706,7 +715,7 @@ function extractPmcidFromUrl(url) {
|
|
|
706
715
|
const match = PMC_URL_PATTERN.exec(url);
|
|
707
716
|
return match ? match[1] ?? null : null;
|
|
708
717
|
}
|
|
709
|
-
function extractPmcidFromLocations(locations) {
|
|
718
|
+
function extractPmcidFromLocations$1(locations) {
|
|
710
719
|
for (const loc of locations) {
|
|
711
720
|
if (loc.url_for_pdf) {
|
|
712
721
|
const pmcid = extractPmcidFromUrl(loc.url_for_pdf);
|
|
@@ -752,7 +761,7 @@ async function checkUnpaywallDetailed(doi, email) {
|
|
|
752
761
|
}
|
|
753
762
|
if (locations.length === 0)
|
|
754
763
|
return null;
|
|
755
|
-
const pmcid = extractPmcidFromLocations(data.oa_locations);
|
|
764
|
+
const pmcid = extractPmcidFromLocations$1(data.oa_locations);
|
|
756
765
|
const result = { locations };
|
|
757
766
|
if (pmcid)
|
|
758
767
|
result.pmcid = pmcid;
|
|
@@ -9510,6 +9519,29 @@ function parseSection(secChildren, level) {
|
|
|
9510
9519
|
}
|
|
9511
9520
|
return { title, level, content, subsections };
|
|
9512
9521
|
}
|
|
9522
|
+
function flushBlockBuffer(buffer, sections) {
|
|
9523
|
+
const content = parseBlockContent(buffer);
|
|
9524
|
+
if (content.length > 0) {
|
|
9525
|
+
sections.push({ title: "", level: 2, content, subsections: [] });
|
|
9526
|
+
}
|
|
9527
|
+
}
|
|
9528
|
+
function parseMixedBodyChildren(children, sections) {
|
|
9529
|
+
let blockBuffer = [];
|
|
9530
|
+
for (const child of children) {
|
|
9531
|
+
if (getTagName(child) === "sec") {
|
|
9532
|
+
if (blockBuffer.length > 0) {
|
|
9533
|
+
flushBlockBuffer(blockBuffer, sections);
|
|
9534
|
+
blockBuffer = [];
|
|
9535
|
+
}
|
|
9536
|
+
sections.push(parseSection(getChildren(child), 2));
|
|
9537
|
+
} else {
|
|
9538
|
+
blockBuffer.push(child);
|
|
9539
|
+
}
|
|
9540
|
+
}
|
|
9541
|
+
if (blockBuffer.length > 0) {
|
|
9542
|
+
flushBlockBuffer(blockBuffer, sections);
|
|
9543
|
+
}
|
|
9544
|
+
}
|
|
9513
9545
|
function parseJatsBody(xml) {
|
|
9514
9546
|
const parsed = parser.parse(xml);
|
|
9515
9547
|
const article = findArticle(parsed);
|
|
@@ -9521,14 +9553,9 @@ function parseJatsBody(xml) {
|
|
|
9521
9553
|
const sections = [];
|
|
9522
9554
|
const secs = findChildren(body.children, "sec");
|
|
9523
9555
|
if (secs.length > 0) {
|
|
9524
|
-
|
|
9525
|
-
sections.push(parseSection(sec.children, 2));
|
|
9526
|
-
}
|
|
9556
|
+
parseMixedBodyChildren(body.children, sections);
|
|
9527
9557
|
} else {
|
|
9528
|
-
|
|
9529
|
-
if (content.length > 0) {
|
|
9530
|
-
sections.push({ title: "", level: 2, content, subsections: [] });
|
|
9531
|
-
}
|
|
9558
|
+
flushBlockBuffer(body.children, sections);
|
|
9532
9559
|
}
|
|
9533
9560
|
return sections;
|
|
9534
9561
|
}
|
|
@@ -10221,6 +10248,16 @@ async function fulltextDiscover(library, options) {
|
|
|
10221
10248
|
}
|
|
10222
10249
|
return discoverResult;
|
|
10223
10250
|
}
|
|
10251
|
+
function extractPmcidFromLocations(locations) {
|
|
10252
|
+
for (const loc of locations) {
|
|
10253
|
+
if (loc.source !== "pmc") continue;
|
|
10254
|
+
const pdfMatch = loc.url.match(/\/pmc\/articles\/(PMC\d+)\//);
|
|
10255
|
+
if (pdfMatch) return pdfMatch[1];
|
|
10256
|
+
const xmlMatch = loc.url.match(/[?&]id=(\d+)/);
|
|
10257
|
+
if (xmlMatch) return `PMC${xmlMatch[1]}`;
|
|
10258
|
+
}
|
|
10259
|
+
return void 0;
|
|
10260
|
+
}
|
|
10224
10261
|
function buildDiscoveryArticle(item) {
|
|
10225
10262
|
const article = {};
|
|
10226
10263
|
if (item.DOI) article.doi = item.DOI;
|
|
@@ -10239,21 +10276,26 @@ function buildDiscoveryConfig(fulltextConfig) {
|
|
|
10239
10276
|
return config;
|
|
10240
10277
|
}
|
|
10241
10278
|
async function tryDownloadPdf(locations, tempDir, ctx) {
|
|
10242
|
-
const
|
|
10243
|
-
if (
|
|
10279
|
+
const pdfLocations = locations.filter((loc) => loc.urlType === "pdf");
|
|
10280
|
+
if (pdfLocations.length === 0) return { attached: false, source: "" };
|
|
10244
10281
|
const pdfPath = join(tempDir, "fulltext.pdf");
|
|
10245
|
-
const
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10253
|
-
|
|
10254
|
-
|
|
10255
|
-
|
|
10256
|
-
|
|
10282
|
+
for (const pdfLocation of pdfLocations) {
|
|
10283
|
+
const pdfResult = await downloadPdf(pdfLocation.url, pdfPath);
|
|
10284
|
+
if (!pdfResult.success) continue;
|
|
10285
|
+
const attachResult = await fulltextAttach(ctx.library, {
|
|
10286
|
+
identifier: ctx.identifier,
|
|
10287
|
+
idType: ctx.idType,
|
|
10288
|
+
filePath: pdfPath,
|
|
10289
|
+
type: "pdf",
|
|
10290
|
+
force: ctx.force,
|
|
10291
|
+
move: true,
|
|
10292
|
+
fulltextDirectory: ctx.fulltextDirectory
|
|
10293
|
+
});
|
|
10294
|
+
if (attachResult.success) {
|
|
10295
|
+
return { attached: true, source: pdfLocation.source };
|
|
10296
|
+
}
|
|
10297
|
+
}
|
|
10298
|
+
return { attached: false, source: pdfLocations[0]?.source ?? "" };
|
|
10257
10299
|
}
|
|
10258
10300
|
async function tryDownloadPmcXmlAndConvert(pmcid, tempDir, ctx) {
|
|
10259
10301
|
const xmlPath = join(tempDir, "fulltext.xml");
|
|
@@ -10328,7 +10370,7 @@ async function fulltextFetch(library, options) {
|
|
|
10328
10370
|
if (locations.length === 0) {
|
|
10329
10371
|
return { success: false, error: `No OA sources found for ${identifier}` };
|
|
10330
10372
|
}
|
|
10331
|
-
const effectivePmcid = item.PMCID ?? discovery.discoveredIds?.pmcid;
|
|
10373
|
+
const effectivePmcid = item.PMCID ?? discovery.discoveredIds?.pmcid ?? extractPmcidFromLocations(locations);
|
|
10332
10374
|
const tempDir = await mkdtemp(join(tmpdir(), "ref-fulltext-"));
|
|
10333
10375
|
const ctx = {
|
|
10334
10376
|
library,
|
|
@@ -12522,4 +12564,4 @@ export {
|
|
|
12522
12564
|
cite as y,
|
|
12523
12565
|
list as z
|
|
12524
12566
|
};
|
|
12525
|
-
//# sourceMappingURL=index-
|
|
12567
|
+
//# sourceMappingURL=index-7R-uEYOu.js.map
|