mirror of
https://github.com/bitwarden/desktop.git
synced 2024-11-14 10:16:02 +01:00
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
|
function FolderService(cryptoService, userService, apiService) {
|
|||
|
this.cryptoService = cryptoService;
|
|||
|
this.userService = userService;
|
|||
|
this.apiService = apiService;
|
|||
|
|
|||
|
initFolderService();
|
|||
|
};
|
|||
|
|
|||
|
function initFolderService() {
|
|||
|
this.userService.getUserId(function (userId) {
|
|||
|
var foldersKey = 'folders_' + userId;
|
|||
|
|
|||
|
FolderService.prototype.get = function (id, callback) {
|
|||
|
if (!callback || typeof callback !== 'function') {
|
|||
|
throw 'callback function required';
|
|||
|
}
|
|||
|
|
|||
|
chrome.storage.local.get(foldersKey, function (obj) {
|
|||
|
var folders = obj[foldersKey];
|
|||
|
if (id in folders) {
|
|||
|
callback(new Folder(folders[id]));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
callback(null);
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
FolderService.prototype.getAll = function (callback) {
|
|||
|
if (!callback || typeof callback !== 'function') {
|
|||
|
throw 'callback function required';
|
|||
|
}
|
|||
|
|
|||
|
chrome.storage.local.get(foldersKey, function (obj) {
|
|||
|
var folders = obj[foldersKey];
|
|||
|
var response = [];
|
|||
|
for (var id in folders) {
|
|||
|
var folder = folders[id];
|
|||
|
response.push(new Folder(folder));
|
|||
|
}
|
|||
|
|
|||
|
callback(response);
|
|||
|
});
|
|||
|
};
|
|||
|
|
|||
|
function handleError() {
|
|||
|
// TODO: check for unauth or forbidden and logout
|
|||
|
}
|
|||
|
});
|
|||
|
};
|