only scale sealed image if not gif

This commit is contained in:
Pierre Balzack 2023-07-26 13:36:16 -07:00
parent e5a34beceb
commit f76470c860
3 changed files with 11 additions and 8 deletions

View File

@ -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';

View File

@ -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}`;
});

View File

@ -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';