-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export/Import user generative data - alternative #935
Conversation
Work on story id: 172387 1. export/import backup file support json format 2. encrypt/decrypt json file
export const backupGDriveFileName = 'my.backup'; | ||
export const backupGDriveFileName = 'mybackup.json'; | ||
export const encryptionsKey = 'f06d3a055c7066de31d6d1ae583d7bd18d99840bc74d14aaed63860054004f15'; | ||
export const encryptionsIVKey = 'cd6854fab61ec032563b2e0c38b30c39'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not store keys on public repo, get it from configs.
app/screens/ChildSetup.tsx
Outdated
@@ -183,16 +187,30 @@ const ChildSetup = ({ navigation }: Props): any => { | |||
}; | |||
const importFromFile = async (): Promise<any> => { | |||
if (Platform.OS == "android") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor code, something like:
// Call the appropriate import function based on the platform
if (Platform.OS === 'android') {
importDataAndroid();
} else {
importDataNonAndroid();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay @Akhror sure, I will refactor above code
app/screens/ChildSetup.tsx
Outdated
const importedJsonData = JSON.parse(await decryptedData); | ||
await RNFS.writeFile(tempRealmFile, JSON.stringify(decryptedData), "utf8"); | ||
oldChildrenData = importedJsonData; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we validate file types? How does app behave if user selects inappropriate file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this app we don't have any validation for file type, but we are processing only .backup and .json file. If user select any other inappropriate file, bebbo app will not process further.
app/screens/ChildSetup.tsx
Outdated
@@ -204,7 +222,9 @@ const ChildSetup = ({ navigation }: Props): any => { | |||
navigation.navigate('ChildImportSetup', { | |||
importResponse: JSON.stringify(oldChildrenData) | |||
}); | |||
importedrealm.close(); | |||
if (dataset.name.endsWith('.backup')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (importedrealm)
check is probably better choice.
return AesCrypto.encrypt(text, key, encryptionsIVKey, 'aes-256-cbc').then((cipher: any) => ({ | ||
cipher | ||
})); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if you could write similar method for decrypt as well since we use it in more than one place.
async function decryptData(data: string): Promise<string> {
try {
const decryptedData = await AesCrypto.decrypt(
data,
encryptionsKey,
encryptionsIVKey,
'aes-256-cbc'
);
return decryptedData;
} catch (error) {
console.error('Decryption error', error);
throw error;
}
}
app/screens/ChildSetup.tsx
Outdated
else { | ||
setLoading(false); | ||
setIsImportRunning(false); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please introduce a new method to combine lines 218-238 and 280-301
Something like:
function handleImportedData(importedData: any) {
if (importedData.length > 0) {
userRealmCommon.openRealm()
.then(() => userRealmCommon.deleteAllAtOnce())
.then(() => {
setLoading(false);
setIsImportRunning(false);
navigation.navigate('ChildImportSetup', {
importResponse: JSON.stringify(importedData),
});
})
.catch((error) => console.error('Error handling imported data:', error));
if (tempRealmFile.endsWith('.backup')) {
Realm.deleteFile({ path: tempRealmFile });
}
} else {
setLoading(false);
setIsImportRunning(false);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay sure @Akhror , I will create this new methods
Export/Import user generative data - alternative
Work on story id: 172387