Skip to content

Commit

Permalink
fix: Fixing large encoding of thumbnail
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Nov 5, 2022
1 parent de9b724 commit c510199
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 50 deletions.
14 changes: 11 additions & 3 deletions cmd/fibr/static/scripts/async-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ async function* readChunk(response) {
}
}

function encode(content) {
const output = [];

for (let i = 0; i < content.length; i++) {
output.push(String.fromCharCode(content[i]));
}

return btoa(output.join(''));
}

/**
* Async image loading
*/
Expand Down Expand Up @@ -107,9 +117,7 @@ async function fetchThumbnail() {
}

const img = new Image();
img.src = `data:image/webp;base64,${btoa(
String.fromCharCode.apply(null, chunk.slice(commaIndex + 1)),
)}`;
img.src = `data:image/webp;base64,${encode(chunk.slice(commaIndex + 1))}`;
img.alt = picture.dataset.alt;
img.dataset.src = picture.dataset.src;
img.classList.add('thumbnail', 'full', 'block');
Expand Down
Loading

0 comments on commit c510199

Please sign in to comment.