From 40e30f42f4f68114ba746006c8eed25eefe5405d Mon Sep 17 00:00:00 2001 From: Dario Baumberger Date: Fri, 2 Feb 2024 18:18:44 +0100 Subject: [PATCH] renamed vars --- README.md | 3 --- src/main.ts | 30 ++++++++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b1f5237..ffba729 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,3 @@ This plugin uses [tesseract.js](https://github.com/naptha/tesseract.js/) to reco - Feel free to [open an issue](https://github.com/dario-baumberger/obsidian-image-to-text-ocr/issues) if you miss something - Feel free to open a Pull request to implement a feature - Please extend tests if you add logic - -todo -command icons diff --git a/src/main.ts b/src/main.ts index 0d5589f..6fedb39 100644 --- a/src/main.ts +++ b/src/main.ts @@ -217,10 +217,10 @@ export default class ImageToTextOcrPlugin extends Plugin { await this.saveData(this.settings); } - async resolveImagePath(imageFilename: string): Promise { + async resolveImagePath(fileName: string): Promise { // todo avoid getFiles const files = this.app.vault.getFiles(); - const imageFile = files.find((file) => file.name === imageFilename); + const imageFile = files.find((file) => file.name === fileName); if (!imageFile) { new Notice("Image file not found in the vault.", 0); @@ -241,7 +241,7 @@ export default class ImageToTextOcrPlugin extends Plugin { } async getSelectedImagePath(selection: string): Promise { - let imageFilename!: string | undefined; + let imagePath!: string | undefined; let fullPath!: string | undefined; if (this.settings.devMode) { @@ -249,30 +249,28 @@ export default class ImageToTextOcrPlugin extends Plugin { } if (isObsidianTag(selection)) { - imageFilename = extractObsidianPath(selection); - fullPath = imageFilename - ? await this.resolveImagePath(imageFilename) + imagePath = extractObsidianPath(selection); + fullPath = imagePath + ? await this.resolveImagePath(imagePath) : undefined; } else if (isValidUrl(selection)) { - imageFilename = selection; + imagePath = selection; fullPath = selection; } else if (isImgTag(selection)) { - imageFilename = extractSrc(selection); - fullPath = imageFilename; + imagePath = extractSrc(selection); + fullPath = imagePath; } else if (isMarkdownTag(selection)) { - imageFilename = extractMdPath(selection); + imagePath = extractMdPath(selection); fullPath = - imageFilename && isValidUrl(imageFilename) - ? imageFilename - : undefined; + imagePath && isValidUrl(imagePath) ? imagePath : undefined; } if (this.settings.devMode) { - console.log(`imageFilename: ${imageFilename}`); + console.log(`imagePath: ${imagePath}`); console.log(`fullPath: ${fullPath}`); } - if (!imageFilename) { + if (!imagePath) { new Notice( "Not supported selection. Allowed: Obsidian Images, Markdown Images and Urls", 0 @@ -282,7 +280,7 @@ export default class ImageToTextOcrPlugin extends Plugin { ); } - if (!checkFileType(imageFilename)) { + if (!checkFileType(imagePath)) { new Notice( "Not supported file type. Allowed file types: .jpg, .jpeg, .png, .gif, .bmp, .pbm, .webp", 0