Map and save entry metadata

This commit is contained in:
Daniel Nyvik 2024-04-04 13:31:08 +02:00
parent 9e5bc8e12c
commit f3918a5ec4
4 changed files with 42 additions and 7 deletions

View File

@ -150,7 +150,8 @@ class AppModel {
icon: file.icon,
tenantName: file.tenantName,
writeAccess: file.writeAccess,
deleteAccess: file.deleteAccess
deleteAccess: file.deleteAccess,
entries: file.entries
})
)
.reverse()
@ -1076,6 +1077,7 @@ class AppModel {
});
});
};
const saveToStorage = (data) => {
logger.info('Save data to storage');
const storageRev = fileInfo.storage === storage ? fileInfo.rev : undefined;
@ -1107,9 +1109,11 @@ class AppModel {
complete();
}
},
storageRev
storageRev,
this.getEntryMetadata(file)
);
};
const saveToCacheAndStorage = () => {
logger.info('Getting file data for saving');
file.getData((data, err) => {
@ -1226,6 +1230,23 @@ class AppModel {
this.fileInfos.save();
}
getEntryMetadata(file) {
if (!file) {
return null;
}
return {
entries: Object.values(file.entryMap)
.filter((x) => x.group.getEffectiveEnableSearching())
.map((x) => {
return {
id: x.id,
title: x.title,
searchText: x.searchText
};
})
};
}
backupFile(file, data, callback) {
const opts = file.opts;
let backup = file.backup;

View File

@ -23,7 +23,8 @@ const DefaultProperties = {
icon: null,
tenantName: '',
writeAccess: false,
deleteAccess: false
deleteAccess: false,
entries: null
};
class FileInfoModel extends Model {

View File

@ -772,6 +772,7 @@ FileModel.defineModelProperties({
supportsExpiration: true,
defaultGroupHash: '',
tenantName: '',
entries: null,
writeAccess: false,
deleteAccess: false
});

View File

@ -133,7 +133,7 @@ class StorageWebDav extends StorageBase {
}
}
save(path, opts, data, callback, rev) {
save(path, opts, data, callback, rev, metadata) {
const cb = function (err, xhr, stat) {
if (callback) {
callback(err, stat);
@ -244,7 +244,8 @@ class StorageWebDav extends StorageBase {
op: 'Save:put',
method: 'PUT',
data,
nostat: true
nostat: true,
metadata
},
(err) => {
if (err) {
@ -379,8 +380,19 @@ class StorageWebDav extends StorageBase {
xhr.setRequestHeader('Cache-Control', 'no-cache');
}
if (config.data) {
const blob = new Blob([config.data], { type: 'application/octet-stream' });
xhr.send(blob);
if (config.metadata) {
const formData = new FormData();
formData.append('metadata', JSON.stringify(config.metadata));
formData.append(
'kdbx',
new Blob([config.data], { type: 'application/octet-stream' }),
'passwordvault.kdbx'
);
xhr.send(formData);
} else {
const blob = new Blob([config.data], { type: 'application/octet-stream' });
xhr.send(blob);
}
} else {
xhr.send();
}