Skip to content
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
53 changes: 30 additions & 23 deletions src/processors/obfProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,38 +138,45 @@ class ObfProcessor extends BaseProcessor {
return this.imageCache.get(imageId) ?? null;
}

if (!this.zipFile || !images) {
return null;
}
if (!images) return null;

// Find the image metadata
const imageData = images.find((img: any) => img.id === imageId);
if (!imageData) {
return null;
}

// Try to get the image file from the ZIP
// Images are typically stored in an 'images' folder or root
const possiblePaths = [
imageData.path, // Explicit path if provided
`images/${imageData.filename || imageId}`, // Standard images folder
imageData.id, // Just the ID
].filter(Boolean);
// If image has data property, use that
if ((imageData as { data?: string }).data) {
const dataUrl = (imageData as { data: string }).data;
this.imageCache.set(imageId, dataUrl);
return dataUrl;
}

for (const imagePath of possiblePaths) {
try {
const buffer = await this.zipFile.readFile(imagePath as string);
if (buffer) {
const contentType =
(imageData as { content_type?: string }).content_type ||
this.getMimeTypeFromFilename(imagePath as string);
const dataUrl = `data:${contentType};base64,${encodeBase64(buffer)}`;
this.imageCache.set(imageId, dataUrl);
return dataUrl;
if (this.zipFile) {
// Try to get the image file from the ZIP
// Images are typically stored in an 'images' folder or root
const possiblePaths = [
imageData.path, // Explicit path if provided
`images/${imageData.filename || imageId}`, // Standard images folder
imageData.id, // Just the ID
].filter(Boolean);

for (const imagePath of possiblePaths) {
try {
const buffer = await this.zipFile.readFile(imagePath as string);
if (buffer) {
const contentType =
(imageData as { content_type?: string }).content_type ||
this.getMimeTypeFromFilename(imagePath as string);
const dataUrl = `data:${contentType};base64,${encodeBase64(buffer)}`;
this.imageCache.set(imageId, dataUrl);
return dataUrl;
}
} catch (err) {
// Continue to next path
continue;
}
} catch (err) {
// Continue to next path
continue;
}
}

Expand Down