Skip to content

Commit

Permalink
avoid scaling gif for sealed topics
Browse files Browse the repository at this point in the history
  • Loading branch information
balzack committed Jul 20, 2023
1 parent 91f0b0d commit af8eccd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
25 changes: 20 additions & 5 deletions net/web/src/context/useUploadContext.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import axios from 'axios';
import Resizer from "react-image-file-resizer";

const ENCRYPTED_BLOCK_SIZE = (1024 * 1024);
const IMAGE_SCALE_SIZE = (128 * 1024 * 1024);
const GIF_TYPE = 'image/gif';
const WEBP_TYPE = 'image/webp';

export function useUploadContext() {

Expand Down Expand Up @@ -151,11 +154,23 @@ export function useUploadContext() {
}

function getImageThumb(data) {
return new Promise(resolve => {
Resizer.imageFileResizer(data, 192, 192, 'JPEG', 50, 0,
uri => {
resolve(uri);
}, 'base64', 128, 128 );
return new Promise((resolve, reject) => {
if ((data.type === GIF_TYPE || data.type === WEBP_TYPE) && data.size < IMAGE_SCALE_SIZE) {
const reader = new FileReader();
reader.readAsDataURL(data);
reader.onload = function () {
resolve(reader.result);
};
reader.onerror = function (error) {
reject();
};
}
else {
Resizer.imageFileResizer(data, 192, 192, 'JPEG', 50, 0,
uri => {
resolve(uri);
}, 'base64', 128, 128 );
}
});
}

Expand Down
15 changes: 11 additions & 4 deletions net/web/src/session/conversation/addTopic/useAddTopic.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,17 @@ export function useAddTopic(contentKey) {

const actions = {
addImage: async (image) => {
const scaled = await getResizedImage(image);
const asset = await setUrl(scaled);
asset.image = image;
addAsset(asset);
if (image.type === 'image/gif' || image.type === 'image/webp') {
const asset = await setUrl(image);
asset.image = image;
addAsset(asset);
}
else {
const scaled = await getResizedImage(image);
const asset = await setUrl(scaled);
asset.image = image;
addAsset(asset);
}
},
addVideo: async (video) => {
const asset = await setUrl(video);
Expand Down

0 comments on commit af8eccd

Please sign in to comment.