Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
edge: 'left', // Choose the horizontal origin
closeOnClick: false, // Closes side-nav on <a> clicks, useful for Angular/Meteor
draggable: true, // Choose whether you can drag to open on touch screens
}
);
const publicKey = getPublicKeyFromPrivate(loadUserData().appPrivateKey)
putFile('key.json', JSON.stringify(publicKey), {encrypt: false})
.then(() => {
console.log("Saved!");
console.log(JSON.stringify(publicKey));
})
.catch(e => {
console.log(e);
});
getFile("contact.json", {decrypt: true})
.then((fileContents) => {
let file = JSON.parse(fileContents || '{}');
let contacts = file.contacts;
if(contacts.length > 0) {
this.setState({ contacts: JSON.parse(fileContents || '{}').contacts });
} else {
this.setState({ contacts: [] });
}
})
.catch(error => {
console.log(error);
});
this.loadCollection();
}
</a>
export function postToSharedBucket() {
//First we need to check root level access.
//We will always look up from the root username (eg: acmecompany.graphite)
//For testing, we can hard-code this as necessary.
const pubKey = blockstack.getPublicKeyFromPrivate(
blockstack.loadUserData().appPrivateKey
);
const file = pubKey + "/AccessConfig";
let gaiaConfig;
blockstack
.getFile(file, { username: "admin.graphite", decrypt: false })
.then(file => {
let privateKey = blockstack.loadUserData().appPrivateKey;
let content = blockstack.decryptContent(file, {
privateKey: privateKey
});
gaiaConfig = JSON.parse(content);
})
.then(() => {
try {
blockstack.uploadToGaiaHub("shouldnt-work", "asdf", gaiaConfig);
} catch (error) {
console.log("Correctly failed to upload");
}
blockstack.uploadToGaiaHub("AdminFolder/should-work", "hi!", gaiaConfig);
console.log("Write was successful");
export async function loadDocs() {
console.log("loading docs...")
const authProvider = JSON.parse(localStorage.getItem('authProvider'));
if(window.location.href.includes('doc/') || window.location.href.includes('shared/')) {
//Don't do anything right now.
} else {
setGlobal({ loading: true })
if(authProvider === 'blockstack') {
setGlobal({ loading: true });
getFile("documentscollection.json", {decrypt: true})
.then((fileContents) => {
if(fileContents) {
if(JSON.parse(fileContents).value) {
setGlobal({ value: JSON.parse(fileContents).value, countFilesDone: JSON.parse(fileContents).countFilesDone, filteredValue: JSON.parse(fileContents).value, loading: false });
} else {
setGlobal({ value: JSON.parse(fileContents), countFilesDone: JSON.parse(fileContents).countFilesDone, filteredValue: JSON.parse(fileContents), loading: false });
}
if(JSON.parse(fileContents).countFilesDone) {
setGlobal({ countFilesDone: true });
} else {
setGlobal({ countFilesDone: false });
}
} else {
setGlobal({ value: [], filteredValue: [], countFilesDone: true });
}
})
const authProvider = JSON.parse(localStorage.getItem('authProvider'));
htmlContent = document.getElementsByClassName("editor")[0].innerHTML;
if(props.contact.includes('did:')) {
//This is a uPort contact. Need to grab the pubkey
setGlobal({ pubKey: props.pubKey, receiverID: props.contact.name, rtc: false }, () => {
loadMyFile();
})
} else {
setGlobal({ receiverID: props.contact, rtc: false });
const user = props.contact;
const options = {
username: user,
zoneFileLookupURL: "https://core.blockstack.org/v1/names",
decrypt: false
};
getFile("key.json", options)
.then(file => {
setGlobal({ pubKey: JSON.parse(file) });
console.log("Step One: PubKey Loaded");
})
.then(() => {
getFile("graphiteprofile.json", options).then(fileContents => {
if (JSON.parse(fileContents).emailOK) {
const object = {};
object.sharedBy = authProvider === 'uPort' ? JSON.parse(localStorage.getItem('uPortUser')).payload.did : loadUserData().username;
object.title = getGlobal().title;
object.from_email = "contact@graphitedocs.com";
object.to_email = JSON.parse(fileContents).profileEmail;
if (window.location.href.includes("/documents")) {
object.subject =
"New Graphite document shared by " + object.sharedBy;
object.link =
setLoadedFile() {
const { teamMateMostRecent, team, count } = this.state;
console.log("No more teammates");
this.setState({ count: 0 });
console.log(teamMateMostRecent !== "");
if(teamMateMostRecent !== "") {
console.log("There is a more recent file from: ");
console.log(teamMateMostRecent);
let user = teamMateMostRecent;
const options = { username: user, zoneFileLookupURL: "https://core.blockstack.org/v1/names", decrypt: false };
const privateKey = loadUserData().appPrivateKey;
const file = getPublicKeyFromPrivate(loadUserData().appPrivateKey) + '.json';
getFile(file, options)
.then((fileContents) => {
if(fileContents){
console.log("Loading file from: ");
console.log(teamMateMostRecent);
this.setState({
team: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).team,
integrations: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).integrations,
editorView: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorView,
editorName: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorName,
editorRoles: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorRoles,
editorPermissions: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorPermissions,
editorIntegrations: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorIntegrations,
editorPublish: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).editorPublish,
journoView: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoView,
journoName: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoName,
journoRoles: JSON.parse(decryptECIES(privateKey, JSON.parse(fileContents))).journoRoles,
loadCollection() {
getFile("contact.json", {decrypt: true})
.then((fileContents) => {
if(fileContents) {
console.log("Contacts are here");
this.setState({ contacts: JSON.parse(fileContents || '{}').contacts });
this.setState({ filteredContacts: this.state.contacts });
} else {
console.log("No contacts");
}
})
.catch(error => {
console.log(error);
});
}
sharedWith: decryptedContent.sharedWith,
teamDoc: decryptedContent.teamDoc,
compressed: decryptedContent.compressed || false,
spacing: decryptedContent.spacing,
lastUpdate: decryptedContent.lastUpdate,
jsonContent: true,
versions: decryptedContent.versions || [],
loading: false
})
}
await console.log(reader.readAsText(blob));
}
}
//Now we need to determine if the response was from indexedDB or an API call:
} else {
getFile(fullFile, {decrypt: true})
.then((fileContents) => {
let thisContent;
if(JSON.parse(fileContents || '{}').singleDocTags || JSON.parse(fileContents).tags) {
if(JSON.parse(fileContents).singleDocTags) {
if(JSON.parse(fileContents).compressed === true) {
console.log("compressed doc")
setGlobal({
content: html.deserialize(lzjs.decompress(JSON.parse(fileContents).content)),
title: JSON.parse(fileContents || '{}').title,
tags: JSON.parse(fileContents || '{}').tags,
idToLoad: JSON.parse(fileContents || '{}').id,
singleDocIsPublic: JSON.parse(fileContents || '{}').singleDocIsPublic, //adding this...
docLoaded: true,
readOnly: JSON.parse(fileContents || '{}').readOnly, //NOTE: adding this, to setGlobal of readOnly from getFile...
rtc: JSON.parse(fileContents || '{}').rtc || false,
sharedWith: JSON.parse(fileContents || '{}').sharedWith,
componentDidMount() {
getFile('integrations.json', {decrypt: true})
.then((fileContents) => {
if(fileContents) {
this.setState({ integrations: JSON.parse(fileContents || '{}') });
} else {
this.setState({ integrations: [] });
}
})
getFile(loadUserData().username + 'publishedPostscollection.json', {decrypt: false})
.then((fileContents) => {
if(fileContents) {
this.setState({ publishedPostCollection: JSON.parse(fileContents || '{}')})
} else {
this.setState({ publishedPostCollection: []})
}
})
migrateSheets() {
getFile("spread.json", {decrypt: true})
.then((fileContents) => {
if(fileContents) {
this.setState({ oldValue: JSON.parse(fileContents || '{}').sheets });
} else {
this.migrationComplete();
}
})
.then(() => {
if(this.state.oldValue.length > 0){
this.setState({migrationLength: this.state.oldValue.length})
this.startMigration();
} else {
this.migrationComplete();
}
})
importTimeline(timeline) {
if(!!timeline && !!timeline.length) {
return blockstack.getFile(TIMELINE_FILE).then((json) => {
const currentTimeline = JSON.parse(json)
if(!!currentTimeline && currentTimeline.length >= 0) {
return blockstack.putFile(TIMELINE_FILE, JSON.stringify(currentTimeline.concat(timeline)))
} else {
return blockstack.putFile(TIMELINE_FILE, JSON.stringify(timeline))
}
})
}
}