Skip to content

Commit 297a1c7

Browse files
committed
Save the chosen AI painting without fetching a data address
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018v7WmKMbuE6iBswCfdSSeW
1 parent 0dd2b95 commit 297a1c7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

‎innerworlds-web/index.html‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5357,7 +5357,11 @@ <h2 id="work-title">${esc(item.title)}</h2>
53575357
piece.feelings = state.draft.feelings;
53585358
piece.colour = state.draft.colour;
53595359
piece.question = state.content.question;
5360-
const blob = await (await fetch(image)).blob();
5360+
// Decoded here, not fetched: the site's security policy only lets the page
5361+
// fetch from its own address, and a data: address is not that.
5362+
const [head, encoded] = image.split(',');
5363+
const bytes = Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0));
5364+
const blob = new Blob([bytes], { type: (head.match(/^data:(image\/[a-z]+)/) || [])[1] || 'image/jpeg' });
53615365
await store.images.put(piece.id, blob);
53625366
piece.painter = 'model';
53635367
piece.seed = null;
@@ -5465,7 +5469,17 @@ <h1 class="display-sm">Describe the picture.</h1>
54655469
artistMake();
54665470
};
54675471
const keep = document.getElementById('artist-keep');
5468-
if (keep) keep.onclick = () => artistKeep();
5472+
if (keep) {
5473+
keep.onclick = async () => {
5474+
keep.disabled = true;
5475+
try {
5476+
await artistKeep();
5477+
} catch {
5478+
artist.error = 'That painting could not be saved in this browser. It is still here; try again.';
5479+
render();
5480+
}
5481+
};
5482+
}
54695483
}
54705484

54715485
return { html, mount };

0 commit comments

Comments
 (0)