Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use the file contents when creating unique file name #1681

Merged
merged 1 commit into from
Dec 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/lib/parser/exporters/embedFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,27 @@ export const embedFile = (input: EmbedFileInput): string | null => {
const suffix = SuffixFrom(filePath);
const file = getFile(exporter, files, filePath, workspace);

/**
* The found file can be a file path in the workspace or a file in the zip or url.
* The contents is used first to avoid name conflicts. URL can have conflicts but so far
* no bug reports.
*/
if (file) {
const newName = getUniqueFileName(filePath) + suffix;
const contents = file.contents as string;
const newName = getUniqueFileName(contents ?? filePath) + suffix;
if (contents) {
exporter.addMedia(newName, contents);
}
return newName;
} else {
console.debug(
JSON.stringify({
hint: 'Missing relative path',
filePath: filePath,
fileNames: files.map((f) => f.name),
})
);
}

console.debug(
JSON.stringify({
hint: 'Missing relative path',
filePath: filePath,
fileNames: files.map((f) => f.name),
})
);

return null;
};
Loading