Skip to content

Commit

Permalink
Merge pull request #302 from deepziyu/master
Browse files Browse the repository at this point in the history
fix try to find image files in the attachment folder based on the user's preferences
  • Loading branch information
haouarihk authored Jul 27, 2024
2 parents 98cdcaa + 742be85 commit 463af12
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/scope/context-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,16 @@ export default class ContextManager {
if (elements[i].type == "image_url" && elements[i].image_url?.url && !elements[i].image_url.url.startsWith("http")) {
// @ts-ignore
const path = elements[i].image_url?.url;

const tfile = await this.app.vault.getFileByPath(path);

if (!tfile) continue;
const attachmentFolderPath = this.app.vault.getConfig("attachmentFolderPath"); // it works to getConfig in obsidian v1.6.5
console.log(path,attachmentFolderPath)

let tfile = await this.app.vault.getFileByPath(path);
if (!tfile) {
// try to find in attachment folder, base user's preferences
tfile = await this.app.vault.getFileByPath(attachmentFolderPath + "/" + path);
if (!tfile) continue;
}

const mimtype = mime.lookup(tfile.extension) || ""

const buff = convertArrayBufferToBase64Link(await this.app.vault.readBinary(tfile as any), mimtype)
Expand Down

0 comments on commit 463af12

Please sign in to comment.