Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function saveNewVaultTwo() {
const file = window.location.href.split('shared/')[1].split('/')[1].split('#')[0] + '.json';
putFile(file, JSON.stringify(getGlobal().singleFile), {encrypt:true})
.then(() => {
console.log("Saved!");
saveVaultCollection();
// window.location.replace("/vault");
})
.catch(e => {
console.log("e");
console.log(e);
});
}
export function filterContactsNow() {
const global = getGlobal();
let contacts = global.contacts;
if(global.selectedType !== "") {
let typeFilter = contacts.filter(x => typeof x.types !== 'undefined' ? x.types.includes(global.selectedType) : console.log("nada"));
// let typeFilter = contacts.filter(x => x.types.includes(global.selectedType));
setGlobal({ filteredContacts: typeFilter, appliedFilter: true});
window.$('.button-collapse').sideNav('hide');
} else if (global.selectedDate !== "") {
let dateFilter = contacts.filter(x => typeof x.dateAdded !== 'undefined' ? x.dateAdded.includes(global.selectedDate) : console.log("nada"));
// let dateFilter = contacts.filter(x => x.dateAdded.includes(global.selectedDate));
setGlobal({ filteredContacts: dateFilter, appliedFilter: true});
window.$('.button-collapse').sideNav('hide');
}
}
export function saveNewTypes() {
const global = getGlobal();
console.log(global.index);
setGlobal({ loading: true })
const object = {};
object.contact = global.contact;
object.name = global.name;
object.dateAdded = global.dateAdded;
object.types = global.types;
object.img = global.newContactImg;
const index = global.index;
const updatedContact = update(global.contacts, {$splice: [[index, 1, object]]});
setGlobal({contacts: updatedContact, filteredContacts: updatedContact }, () => {
saveNewContactsFile();
});
// setTimeout(saveFullCollectionTypes, 500);
}
export function filterContactsNow() {
const global = getGlobal();
let contacts = global.contacts;
if (global.selectedType !== "") {
let typeFilter = contacts.filter(x =>
typeof x.types !== "undefined"
? x.types.includes(global.selectedType)
: console.log("nada")
);
// let typeFilter = contacts.filter(x => x.types.includes(global.selectedType));
setGlobal({ filteredContacts: typeFilter, appliedFilter: true });
window.$(".button-collapse").sideNav("hide");
} else if (global.selectedDate !== "") {
let dateFilter = contacts.filter(x =>
typeof x.dateAdded !== "undefined"
? x.dateAdded.includes(global.selectedDate)
: console.log("nada")
.then(result => {
var html = result.value; // The generated HTML
setGlobal({ content: html });
console.log(getGlobal().content);
setGlobal({ loading: false });
})
.done();
.then(result => {
var html = result.value; // The generated HTML
setGlobal({ content: html });
console.log(getGlobal().content);
setGlobal({ loading: false });
})
.done();
export function saveVaultDeleteTwo(file) {
const fileID = file.id;
putFile(fileID + '.json', JSON.stringify(getGlobal().singleFile), {encrypt:true})
.then(() => {
console.log("Saved!");
// setGlobal({loading: false});
loadVault();
})
.catch(e => {
console.log("e");
console.log(e);
alert(e.message);
});
}
export async function shareWithTeam(data) {
console.log(data);
if(data.fromSave) {
//Nothing
} else {
setGlobal({ teamShare: true });
}
const { userSession, proOrgInfo } = getGlobal();
//First we need to fetch the teamKey
const teamKeyParams = {
fileName: `user/${userSession.loadUserData().username.split('.').join('_')}/team/${data.teamId}/key.json`,
decrypt: true
}
const fetchedKeys = await fetchData(teamKeyParams);
let singleForm = getGlobal().singleForm;
const form = {
id: singleForm.id,
team: data.teamId,
orgId: proOrgInfo.orgId,
title: singleForm.title,
responses: singleForm.responses || getGlobal().formResponses,
currentHostBucket: userSession.loadUserData().username
}
const encryptedTeamForm = userSession.encryptContent(JSON.stringify(form), {publicKey: JSON.parse(fetchedKeys).public})
export async function saveFile() {
let singleFile = await getGlobal().singleFile;
let singleFileParams = {
fileName: `${window.location.href.split('files/')[1]}.json`,
encrypt: true,
body: JSON.stringify(singleFile)
}
const postedFile = await postData(singleFileParams);
console.log(postedFile);
await saveIndex();
}
currentHostBucket: userSession.loadUserData().username
}
const encryptedTeamForm = userSession.encryptContent(JSON.stringify(form), {publicKey: JSON.parse(fetchedKeys).public})
const teamForm = {
fileName: `teamForms/${data.teamId}/${singleForm.id}.json`,
encrypt: false,
body: JSON.stringify(encryptedTeamForm)
}
const postedTeamForm = await postData(teamForm);
console.log(postedTeamForm);
singleForm["teamForm"] = true;
let theseTeams = singleForm.teams;
singleForm.teams.includes(data.teamId) ? singleForm.teams = theseTeams : singleForm.teams.push(data.teamId);
await setGlobal({ singleForm });
if(data.fromSave) {
//Do nothing
} else {
await saveForm(false);
}
const privateKey = userSession.loadUserData().appPrivateKey;
const syncedForm = {
id: singleForm.id,
title: userSession.encryptContent(singleForm.title, {publicKey: JSON.parse(fetchedKeys).public}),
teamName: data.teamName ? userSession.encryptContent(data.teamName, {publicKey: JSON.parse(fetchedKeys).public}) : "",
orgId: proOrgInfo.orgId,
teamId: data.teamId,
lastUpdated: getMonthDayYear(),
timestamp: Date.now(),