diff --git a/manifest.json b/manifest.json index 4737d9d..6787cb4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-zotero-desktop-connector", "name": "Zotero Integration", - "version": "3.0.6", + "version": "3.0.7", "minAppVersion": "1.1.1", "description": "Insert and import citations, bibliographies, notes, and PDF annotations from Zotero.", "author": "mgmeyers", diff --git a/src/bbt/export.ts b/src/bbt/export.ts index 1a46679..346bf26 100644 --- a/src/bbt/export.ts +++ b/src/bbt/export.ts @@ -148,11 +148,17 @@ function convertNativeAnnotation( mkdirSync(imageOutputPath, { recursive: true }); } + let input = path.join(parsed.dir, `${annotation.key}${parsed.ext}`); try { - copyFileSync( - path.join(parsed.dir, `${annotation.key}${parsed.ext}`), - imagePath - ); + if (!existsSync(input)) { + const origInput = input; + input = annotation.annotationImagePath; + if (!existsSync(input)) { + throw new Error('Cannot find annotation image: ' + origInput); + } + } + + copyFileSync(input, imagePath); } catch (e) { new Notice( 'Error: unable to copy annotation image from Zotero into your vault', diff --git a/src/bbt/exportNotes.ts b/src/bbt/exportNotes.ts index 328d000..b3c6498 100644 --- a/src/bbt/exportNotes.ts +++ b/src/bbt/exportNotes.ts @@ -1,4 +1,4 @@ -import { copyFileSync } from 'fs'; +import { copyFileSync, existsSync, mkdirSync } from 'fs'; import { Editor, Notice, @@ -44,16 +44,30 @@ export async function processZoteroAnnotationNotes( if (imagePath) { const parsed = path.parse(imagePath); const destPath = await getAvailablePathForAttachments( - parsed.name, + annotationKey, parsed.ext.slice(1), destination ); + const output = path.parse(path.join(getVaultRoot(), destPath)); + const imageOutputPath = output.dir; + + if (!existsSync(imageOutputPath)) { + mkdirSync(imageOutputPath, { recursive: true }); + } + + let input = path.join(parsed.dir, `${annotationKey}${parsed.ext}`); + try { - copyFileSync( - path.join(parsed.dir, `${annotationKey}${parsed.ext}`), - path.join(getVaultRoot(), destPath) - ); + if (!existsSync(input)) { + const origInput = input; + input = imagePath; + if (!existsSync(input)) { + throw new Error('Cannot find annotation image: ' + origInput); + } + } + + copyFileSync(input, path.join(getVaultRoot(), destPath)); } catch (e) { new Notice( 'Error: unable to copy annotation image from Zotero into your vault',