Skip to content

Commit

Permalink
renamed vars
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-baumberger committed Feb 2, 2024
1 parent caf9949 commit 40e30f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 14 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ export default class ImageToTextOcrPlugin extends Plugin {
await this.saveData(this.settings);
}

async resolveImagePath(imageFilename: string): Promise<string> {
async resolveImagePath(fileName: string): Promise<string> {
// 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);
Expand All @@ -241,38 +241,36 @@ export default class ImageToTextOcrPlugin extends Plugin {
}

async getSelectedImagePath(selection: string): Promise<string> {
let imageFilename!: string | undefined;
let imagePath!: string | undefined;
let fullPath!: string | undefined;

if (this.settings.devMode) {
console.log(`selection: ${selection}`);
}

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
Expand All @@ -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
Expand Down

0 comments on commit 40e30f4

Please sign in to comment.