mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
* cleanup unused convo json fields in db * display a toast if the user is not approved yet on call OFFER received * enable CBR for calls * do not update active_at on configMessage if !!active_at * remove mkdirp dependency * disable call button if focused convo is blocked * quote: do not include the full body in quote, but just the first 100 * click on the edit profile qr code padding * Allow longer input for opengroup join overlay Fixes #2068 * Fix overlay feature for start new session button * make ringing depend on redux CALL status * turn ON read-receipt by default
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const { app } = require('electron').remote;
|
|
|
|
const userDataPath = app.getPath('userData');
|
|
const PATH = path.join(userDataPath, 'profileImages');
|
|
fs.mkdirSync(PATH, { recursive: true });
|
|
|
|
const hasImage = pubKey => fs.existsSync(getImagePath(pubKey));
|
|
|
|
const getImagePath = pubKey => `${PATH}/${pubKey}.png`;
|
|
|
|
const removeImage = pubKey => {
|
|
if (hasImage(pubKey)) {
|
|
fs.unlinkSync(getImagePath(pubKey));
|
|
}
|
|
};
|
|
|
|
const removeImagesNotInArray = pubKeyArray => {
|
|
fs.readdirSync(PATH)
|
|
// Get all files that end with png
|
|
.filter(file => file.includes('.png'))
|
|
// Strip the extension
|
|
.map(i => path.basename(i, '.png'))
|
|
// Get any file that is not in the pubKeyArray
|
|
.filter(i => !pubKeyArray.includes(i))
|
|
// Remove them
|
|
.forEach(i => removeImage(i));
|
|
};
|
|
|
|
const writePNGImage = (base64String, pubKey) => {
|
|
const imagePath = getImagePath(pubKey);
|
|
fs.writeFileSync(imagePath, base64String, 'base64');
|
|
return imagePath;
|
|
};
|
|
|
|
module.exports = {
|
|
writePNGImage,
|
|
getImagePath,
|
|
hasImage,
|
|
removeImage,
|
|
removeImagesNotInArray,
|
|
};
|