paper-manager 0.11.0 → 0.11.1

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/README.md CHANGED
@@ -64,7 +64,7 @@ paper kb query <id> <query-text> [--json] [--jq <expr>] # Query a knowledge bas
64
64
  ### Literature (`paper lit`)
65
65
 
66
66
  ```bash
67
- paper lit add <kb-id> <file-path> # Add a literature (auto-extracts PDF metadata)
67
+ paper lit add <kb-id> <file-path> [-f] # Add a literature (auto-extracts PDF metadata, rejects duplicate DOI)
68
68
  paper lit remove <kb-id> <id> # Remove a literature
69
69
  paper lit update <kb-id> <id> [opts] # Update literature metadata
70
70
  paper lit list <kb-id> [--json] [--jq <expr>] # List literatures
@@ -36,6 +36,7 @@ export function createLiteratureCommand() {
36
36
  .command("add <knowledge-base-id> <lit-path>")
37
37
  .description("Add a literature from a file (PDF, TXT, MD, TEX, etc.)")
38
38
  .option("-t, --title <title>", "Literature title")
39
+ .option("-f, --force", "Force add even if a literature with the same DOI already exists")
39
40
  .action(async (kbId, litPath, options) => {
40
41
  const resolved = resolveKnowledgeBase(kbId);
41
42
  if (!resolved) {
@@ -77,6 +78,15 @@ export function createLiteratureCommand() {
77
78
  log.step(`Creator: ${pdfMeta.creator}`);
78
79
  }
79
80
  }
81
+ // Check for duplicate DOI in the knowledge base
82
+ if (pdfMeta?.doi && !options.force) {
83
+ const existing = litOps.findLiteratureByDoi(kbId, pdfMeta.doi);
84
+ if (existing) {
85
+ log.error(`A literature with DOI "${pdfMeta.doi}" already exists in this knowledge base: ${existing.id} (${existing.title})`);
86
+ log.info("Use --force to add anyway.");
87
+ process.exit(1);
88
+ }
89
+ }
80
90
  const title = options.title ?? pdfMeta?.title ?? path.basename(litPath, path.extname(litPath));
81
91
  // Create literature record
82
92
  const literature = litOps.createLiterature({
@@ -85,6 +85,14 @@ export function updateLiterature(db, id, input) {
85
85
  const row = db.update(literatures).set(updates).where(eq(literatures.id, id)).returning().get();
86
86
  return row ?? null;
87
87
  }
88
+ export function findLiteratureByDoi(db, knowledgeBaseId, doi) {
89
+ const row = db
90
+ .select()
91
+ .from(literatures)
92
+ .where(and(eq(literatures.knowledgeBaseId, knowledgeBaseId), eq(literatures.doi, doi)))
93
+ .get();
94
+ return row ?? null;
95
+ }
88
96
  export function deleteLiterature(db, id) {
89
97
  const result = db.delete(literatures).where(eq(literatures.id, id)).run();
90
98
  return result.changes > 0;
@@ -21,6 +21,9 @@ export function deleteLiteraturesByKnowledgeBaseId(knowledgeBaseId) {
21
21
  export function searchLiteratures(knowledgeBaseId, filters) {
22
22
  return ops.searchLiteratures(getProjectDb(), knowledgeBaseId, filters);
23
23
  }
24
+ export function findLiteratureByDoi(knowledgeBaseId, doi) {
25
+ return ops.findLiteratureByDoi(getProjectDb(), knowledgeBaseId, doi);
26
+ }
24
27
  export function getLiteraturesByKnowledgeBaseId(knowledgeBaseId) {
25
28
  return ops.getLiteraturesByKnowledgeBaseId(getProjectDb(), knowledgeBaseId);
26
29
  }
@@ -21,6 +21,9 @@ export function deleteLiteraturesByKnowledgeBaseId(knowledgeBaseId) {
21
21
  export function searchLiteratures(knowledgeBaseId, filters) {
22
22
  return ops.searchLiteratures(getUserDb(), knowledgeBaseId, filters);
23
23
  }
24
+ export function findLiteratureByDoi(knowledgeBaseId, doi) {
25
+ return ops.findLiteratureByDoi(getUserDb(), knowledgeBaseId, doi);
26
+ }
24
27
  export function getLiteraturesByKnowledgeBaseId(knowledgeBaseId) {
25
28
  return ops.getLiteraturesByKnowledgeBaseId(getUserDb(), knowledgeBaseId);
26
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paper-manager",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "A paper management system.",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/EurFelux/paper-manager",