Skip to content

Commit

Permalink
fix: Handle relative paths for images
Browse files Browse the repository at this point in the history
  • Loading branch information
andymac4182 committed May 11, 2023
1 parent cfae670 commit dbaba70
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/lib/src/adaptors/filesystem.ts
@@ -1,4 +1,4 @@
import { ConfluenceSettings } from "src/Settings";
import { ConfluenceSettings } from "../Settings";
import { BinaryFile, FilesToUpload, LoaderAdaptor, MarkdownFile } from ".";
import { lookup } from "mime-types";
import { existsSync, lstatSync } from "fs";
Expand Down Expand Up @@ -197,6 +197,14 @@ export class FileSystemAdaptor implements LoaderAdaptor {
fileName: string,
startingDirectory: string
): Promise<string | null> {
const potentialAbsolutePathForFileName = path.join(
startingDirectory,
fileName
);
if (await isFile(potentialAbsolutePathForFileName)) {
return potentialAbsolutePathForFileName;
}

const matchingFiles: string[] = [];
const directoriesToSearch: string[] = [startingDirectory];

Expand Down Expand Up @@ -241,3 +249,12 @@ export class FileSystemAdaptor implements LoaderAdaptor {
return await this.findClosestFile(fileName, parentDirectory);
}
}

async function isFile(filePath: string): Promise<boolean> {
try {
const stats = await fs.stat(filePath);
return stats.isFile();
} catch (error: unknown) {
return false; // Just return false instead of rethrowing any other errors.
}
}

0 comments on commit dbaba70

Please sign in to comment.