Skip to content

Commit cd11eb1

Browse files
committed
Save image data to board images array (as per spec)
1 parent 92af3af commit cd11eb1

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/processors/obfProcessor.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ class ObfProcessor extends BaseProcessor {
223223
? String(boardData.id)
224224
: _boardPath?.split(/[/\\]/).pop() || '';
225225

226+
const images = boardData.images;
227+
226228
const buttons: AACButton[] = await Promise.all(
227229
sourceButtons.map(async (btn: ObfButton): Promise<AACButton> => {
228230
const semanticAction: AACSemanticAction = btn.load_board
@@ -248,11 +250,17 @@ class ObfProcessor extends BaseProcessor {
248250
// Resolve image if image_id is present
249251
let resolvedImage: string | undefined;
250252
let imageBuffer: Buffer | undefined;
251-
if (btn.image_id && boardData.images) {
252-
resolvedImage =
253-
(await this.extractImageAsDataUrl(btn.image_id, boardData.images)) || undefined;
254-
imageBuffer =
255-
(await this.extractImageAsBuffer(btn.image_id, boardData.images)) || undefined;
253+
if (btn.image_id && images) {
254+
resolvedImage = (await this.extractImageAsDataUrl(btn.image_id, images)) || undefined;
255+
imageBuffer = (await this.extractImageAsBuffer(btn.image_id, images)) || undefined;
256+
257+
// save image data
258+
if (images) {
259+
const imageIndex = images?.findIndex((img: any) => img.id === btn.image_id);
260+
if (imageIndex !== -1) {
261+
images[imageIndex].data = resolvedImage;
262+
}
263+
}
256264
}
257265

258266
// Build parameters object for Grid3 export compatibility
@@ -294,7 +302,7 @@ class ObfProcessor extends BaseProcessor {
294302
parentId: null,
295303
locale: boardData.locale,
296304
descriptionHtml: boardData.description_html,
297-
images: boardData.images,
305+
images,
298306
sounds: boardData.sounds,
299307
});
300308

0 commit comments

Comments
 (0)