Skip to content

Commit

Permalink
replace base64 image with blob
Browse files Browse the repository at this point in the history
  • Loading branch information
nileshgulia1 committed Aug 6, 2021
1 parent 5e94970 commit 7c01bd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/PrivacyProtection/PrivacyProtection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Placeholder } from 'semantic-ui-react';
import cookie from 'react-cookie';
import { Button, Checkbox } from 'semantic-ui-react';
import config from '@plone/volto/registry';

import '../css/embed-styles.css';
import { createImageUrl } from './helpers';

const key = (domain_key) => `accept-${domain_key}`;

Expand All @@ -31,6 +31,13 @@ function canShow(domain_key) {
export default ({ children, data = {}, block, ...rest }) => {
const { dataprotection = {} } = data;
const { background_image: bgImg } = dataprotection;
const [image, setImage] = React.useState(null);

React.useEffect(() => {
if (bgImg) {
setImage(createImageUrl(bgImg));
}
}, [bgImg]);

const [visible, setVisibility] = useState(false);
const defaultShow = canShow(dataprotection.privacy_cookie_key);
Expand All @@ -56,7 +63,7 @@ export default ({ children, data = {}, block, ...rest }) => {
style={
bgImg
? {
backgroundImage: `url(data:${bgImg['content-type']};${bgImg.encoding},${bgImg.data})`,
backgroundImage: `url(${image})`,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
backgroundSize: 'cover',
Expand Down
11 changes: 11 additions & 0 deletions src/PrivacyProtection/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function createImageUrl(result) {
const decoded = window.atob(result.data);
const byteNumbers = new Array(decoded.length);
for (let i = 0; i < decoded.length; i++) {
byteNumbers[i] = decoded.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);

const image = new Blob([byteArray], { type: result['content-type'] });
return URL.createObjectURL(image);
}

0 comments on commit 7c01bd8

Please sign in to comment.