mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
resizing images for sealed channel
This commit is contained in:
parent
9dda806b23
commit
7ed591abf4
@ -622,7 +622,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.12;
|
MARKETING_VERSION = 1.13;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"-ObjC",
|
"-ObjC",
|
||||||
@ -656,7 +656,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.12;
|
MARKETING_VERSION = 1.13;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"-ObjC",
|
"-ObjC",
|
||||||
|
@ -6,6 +6,7 @@ import Colors from 'constants/Colors';
|
|||||||
import { encryptBlock, decryptBlock, getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil';
|
import { encryptBlock, decryptBlock, getChannelSeals, getContentKey, encryptTopicSubject } from 'context/sealUtil';
|
||||||
import { AccountContext } from 'context/AccountContext';
|
import { AccountContext } from 'context/AccountContext';
|
||||||
import RNFS from 'react-native-fs';
|
import RNFS from 'react-native-fs';
|
||||||
|
import ImageResizer from '@bam.tech/react-native-image-resizer';
|
||||||
|
|
||||||
export function useAddTopic(contentKey) {
|
export function useAddTopic(contentKey) {
|
||||||
|
|
||||||
@ -102,15 +103,16 @@ export function useAddTopic(contentKey) {
|
|||||||
updateState({ enableImage, enableAudio, enableVideo, locked });
|
updateState({ enableImage, enableAudio, enableVideo, locked });
|
||||||
}, [conversation.state]);
|
}, [conversation.state]);
|
||||||
|
|
||||||
const setAsset = async (file) => {
|
const setAsset = async (file, scale) => {
|
||||||
const url = file.startsWith('file:') ? file : `file://${file}`;
|
const url = file.startsWith('file:') ? file : `file://${file}`;
|
||||||
if (contentKey) {
|
if (contentKey) {
|
||||||
const stat = await RNFS.stat(url);
|
const scaled = scale ? await scale(url) : url;
|
||||||
|
const stat = await RNFS.stat(scaled);
|
||||||
const getEncryptedBlock = async (pos, len) => {
|
const getEncryptedBlock = async (pos, len) => {
|
||||||
if (pos + len > stat.size) {
|
if (pos + len > stat.size) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const block = await RNFS.read(file, len, pos, 'base64');
|
const block = await RNFS.read(scaled, len, pos, 'base64');
|
||||||
return encryptBlock(block, contentKey);
|
return encryptBlock(block, contentKey);
|
||||||
}
|
}
|
||||||
return { data: url, encrypted: true, size: stat.size, getEncryptedBlock };
|
return { data: url, encrypted: true, size: stat.size, getEncryptedBlock };
|
||||||
@ -126,7 +128,10 @@ export function useAddTopic(contentKey) {
|
|||||||
},
|
},
|
||||||
addImage: async (data) => {
|
addImage: async (data) => {
|
||||||
assetId.current++;
|
assetId.current++;
|
||||||
const asset = await setAsset(data);
|
const asset = await setAsset(data, async (file) => {
|
||||||
|
const scaled = await ImageResizer.createResizedImage(file, 1024, 1024, "JPEG", 50, 0, null);
|
||||||
|
return `file://${scaled.path}`;
|
||||||
|
});
|
||||||
asset.key = assetId.current;
|
asset.key = assetId.current;
|
||||||
asset.type = 'image';
|
asset.type = 'image';
|
||||||
asset.ratio = 1;
|
asset.ratio = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user