Skip to content
This repository was archived by the owner on Sep 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/app/services/backups.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ module.exports = (Model, App) => {
where: {
bucket: { [Op.eq]: backupsBucket },
name: { [Op.eq]: encryptedFolderName },
deleted: { [Op.eq]: false},
removed: { [Op.eq]: false}
deleted: { [Op.eq]: false },
removed: { [Op.eq]: false },
},
});

Expand Down Expand Up @@ -163,13 +163,30 @@ module.exports = (Model, App) => {

const folders = await Model.folder.findAll({ where: { bucket: backupsBucket } });

return Promise.all(
folders.map(async (folder) => ({
...folder.get({ plain: true }),
hasBackups: !(await isDeviceAsFolderEmpty(folder)),
lastBackupAt: folder.updatedAt,
})),
const newFolders = await Promise.all(
folders.map(async (folder) => {
const decryptedWithBucket = App.services.Crypt.decryptName(folder.name, folder.bucket);

const shouldUpdateName = !decryptedWithBucket && folder.bucket;

const backupName = shouldUpdateName
? App.services.Crypt.encryptName(App.services.Crypt.decryptNameWithNullFolderId(folder.name), folder.bucket)
: folder.name;

if (shouldUpdateName) {
await folder.update({ name: backupName }, { silent: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed the frontend uses updated_at to show the last modification on the backups section.

Added silent just to prevent updated_at being updated and mess with user's timestamps (however, updated_at should be updated by the backend in these cases too)

}

return {
...folder.get({ plain: true }),
name: backupName,
hasBackups: !(await isDeviceAsFolderEmpty(folder)),
lastBackupAt: folder.updatedAt,
};
}),
);

return newFolders;
};

const create = async ({ userId, path, deviceId, encryptVersion, interval, enabled }) => {
Expand Down
13 changes: 13 additions & 0 deletions src/app/services/crypt.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ module.exports = (Model, App) => {
}
}

function decryptNameWithNullFolderId(content) {
try {
const decryptedText = AesUtil.decrypt(content, null);

return decryptedText;
} catch (error) {
log.error(`(decryptNameWithNullFolderId): ${error}`);

return null;
}
}
Comment on lines +23 to +33
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had problems with decryptName as it uses probabilistic approach if no salt provided, so I had to get directly the Aes implementation.


function probabilisticDecryption(cipherText) {
try {
const reb64 = CryptoJS.enc.Hex.parse(cipherText);
Expand Down Expand Up @@ -168,5 +180,6 @@ module.exports = (Model, App) => {
hashSha256,
encryptTextWithKey,
RandomPassword,
decryptNameWithNullFolderId,
};
};
Loading