mirror of
https://github.com/balzack/databag.git
synced 2025-04-20 08:35:15 +00:00
avoid scaling gif for sealed topics
This commit is contained in:
parent
91f0b0d3ac
commit
af8eccd688
@ -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() {
|
||||
|
||||
@ -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 );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user