From f76470c8607b6372631e7a502520e99a80379886 Mon Sep 17 00:00:00 2001 From: Pierre Balzack Date: Wed, 26 Jul 2023 13:36:16 -0700 Subject: [PATCH] only scale sealed image if not gif --- app/mobile/src/context/useUploadContext.hook.js | 4 ++-- .../session/conversation/addTopic/useAddTopic.hook.js | 11 +++++++---- net/web/src/context/useUploadContext.hook.js | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/mobile/src/context/useUploadContext.hook.js b/app/mobile/src/context/useUploadContext.hook.js index ac4358b8..cab34fda 100644 --- a/app/mobile/src/context/useUploadContext.hook.js +++ b/app/mobile/src/context/useUploadContext.hook.js @@ -4,8 +4,8 @@ import { createThumbnail } from "react-native-create-thumbnail"; import ImageResizer from '@bam.tech/react-native-image-resizer'; import RNFS from 'react-native-fs'; -const ENCRYPTED_BLOCK_SIZE = (1024 * 1024); -const SCALE_SIZE = (128 * 1024 * 1024); +const ENCRYPTED_BLOCK_SIZE = (256 * 1024); +const SCALE_SIZE = (128 * 1024); const GIF_TYPE = 'image/gif'; const WEBP_TYPE = 'image/webp'; diff --git a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js index 491c1935..4d0d3a2f 100644 --- a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js +++ b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js @@ -29,7 +29,10 @@ export function useAddTopic(contentKey) { conflict: false, }); - const SCALE_SIZE = (128 * 1024 * 1024); + const SCALE_SIZE = (128 * 1024); + const GIF_TYPE = 'image/gif'; + const WEBP_TYPE = 'image/webp'; + const assetId = useRef(0); const conversation = useContext(ConversationContext); const account = useContext(AccountContext); @@ -106,12 +109,12 @@ export function useAddTopic(contentKey) { updateState({ enableImage, enableAudio, enableVideo, locked, loaded }); }, [conversation.state]); - const setAsset = async (file, scale) => { + const setAsset = async (file, mime, scale) => { const url = file.startsWith('file:') ? file : `file://${file}`; if (contentKey) { const orig = await RNFS.stat(url); - const scaled = (scale && orig.size > SCALE_SIZE) ? await scale(url) : url; + const scaled = (scale && orig.size > SCALE_SIZE && (mime !== GIF_TYPE && mime !== WEBP_TYPE)) ? await scale(url) : url; const stat = await RNFS.stat(scaled); const getEncryptedBlock = async (pos, len) => { if (pos + len > stat.size) { @@ -133,7 +136,7 @@ export function useAddTopic(contentKey) { }, addImage: async (data, mime) => { assetId.current++; - const asset = await setAsset(data, async (file) => { + const asset = await setAsset(data, mime, async (file) => { const scaled = await ImageResizer.createResizedImage(file, 512, 512, "JPEG", 90, 0, null); return `file://${scaled.path}`; }); diff --git a/net/web/src/context/useUploadContext.hook.js b/net/web/src/context/useUploadContext.hook.js index fd1d9ab0..01a12e30 100644 --- a/net/web/src/context/useUploadContext.hook.js +++ b/net/web/src/context/useUploadContext.hook.js @@ -2,8 +2,8 @@ import { useState, useRef } from 'react'; 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 ENCRYPTED_BLOCK_SIZE = (256 * 1024); +const IMAGE_SCALE_SIZE = (128 * 1024); const GIF_TYPE = 'image/gif'; const WEBP_TYPE = 'image/webp';