Skip to content

Commit

Permalink
Merge pull request #21 from SebTota/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
SebTota authored Feb 17, 2021
2 parents 810c72b + 7c4ca02 commit 52caff5
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 40 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# Note

Note (new name pending) is a client-side encrypted note taking application that allows you to safely and
Note is a client-side encrypted note taking application that allows you to safely and
securely share notes between multiple computers.

## Important Note
This application is still under development.

## Features
* File encryption (including photos)

* Folder and file name encryption
* The folder structure is still visible, but folder and file names are not

* Files and assets are never stored locally in their decrypted form
* All files and assets are decrypted in app when a certain file is chosen by the user
* This means any application looking for certain file extensions (ex. png, jpg, etc.) will not see these files
in their decrypted state

* Cloud sync
* Sync encrypted notes to Google Drive

## Future Implementation
* Cloud syncing
* Google Drive Sync - currently partially complete
* Live E2E encrypted peer editing


Expand Down
11 changes: 9 additions & 2 deletions lib/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,15 @@ $('#btn-cloud-sign-in').on('click', function(e) {
});
})

$('#btn-sync').on('click', function(e) {
$('#btn-sync').on('click', (e) => {
this.quill['emitter']['_events']['text-change'] = undefined; // Clear on change file save listener
quill.enable(false); // Disable editor
sync.instance.sync().then(() => {
console.log('done sync');
logger.info('Finished sync');
console.log('Finished sync');
// Reopen file if a user was editing a file when sync was initiated
if (currentFile['relativePath']) {
openFile(currentFile['relativePath']);
}
})
})
92 changes: 58 additions & 34 deletions modules/providers/google-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ module.exports = class GoogleAuth {
if (file.mimeType === googleMimeFolder) {
items.folders[encryption.decryptPath(folderPath + file.name)] = {
'path': `${folderPath + file.name}`,
'id': file.id,
'parents': file.parents
'id': file.id
}
let tempItems = await this.listItems(itemType, file.id, `${folderPath + file.name}/`)
// Concat tempItems files dictionary with the current dictionary of files
Expand Down Expand Up @@ -233,13 +232,19 @@ module.exports = class GoogleAuth {
resource: fileMetadata
});

if (folder.hasOwnProperty('id')) {
return folder.id;
console.log(folder)

return folder.data.id

if (folder.hasOwnProperty('id') && folder.hasOwnProperty('parents')) {
return {'id': folder.id, 'parents': folder.parents };
}

if (folder.hasOwnProperty('data') && folder.data.hasOwnProperty('id')) {
return folder.data.id;
if (folder.hasOwnProperty('data') && folder.data.hasOwnProperty('id') && folder.data.hasOwnProperty('parents')) {
return {'id': folder.data.id, 'parents': folder.data.parents };
}

logger.error(`Google Drive Sync: Error creating new cloud folder. Return type didn't include id and parent.`)
}

/*
Expand All @@ -260,9 +265,6 @@ module.exports = class GoogleAuth {
continue;
}

let foldersInPath = key.split('/');
if (foldersInPath[0] === '') foldersInPath.shift(); // Remove "" from folder paths (root folder which always exists!)

if (this.folders.hasOwnProperty(key)) {
// Only exists in the cloud, create the folder locally
/*
Expand All @@ -274,9 +276,12 @@ module.exports = class GoogleAuth {
* to encrypt the entire path meaning the '/test' folder will have a different encrypted name.
*/

let foldersInPath = key.split('/');
if (foldersInPath[0] === '') foldersInPath.shift(); // Remove "" from folder paths (root folder which always exists!)

let subFolderPath = ''; // Holds the path of which folders in the path already exist locally
for (let i = 0; i < foldersInPath.length; i++) {
let tempPath = path.normalize(`${subFolderPath}/${foldersInPath[0]}`);
let tempPath = path.normalize(`${subFolderPath}/${foldersInPath[i]}`);

if (!(folderStructure.folders.hasOwnProperty(tempPath))) {
// Create sub folder because it doesn't yet exist locally
Expand Down Expand Up @@ -304,6 +309,8 @@ module.exports = class GoogleAuth {
folderStructure.createNewFolder(folderPath);
} else {
// Only exists locally, create the folder in the cloud
let foldersInPath = key.split('/');
if (foldersInPath[0] === '') foldersInPath.shift(); // Remove "" from folder paths (root folder which always exists!)

let parentFolderPath = '';
let builtPath = '';
Expand All @@ -314,13 +321,21 @@ module.exports = class GoogleAuth {

if (!this.folders.hasOwnProperty(builtPath)) {
if (this.folders.hasOwnProperty(parentFolderPath)) {
parent = [this.folders[parentFolderPath]];
parent = [this.folders[parentFolderPath].id];
} else {
logger.error(`Google Drive Sync: Error creating cloud folder. Couldn't find parent id of ${parentFolderPath}`);
}

console.log(parent)
this.folders[builtPath] = await this.createNewCloudFolder(builtPath, parent);
let folderId = await this.createNewCloudFolder(folderStructure.folders[builtPath], parent);
console.log(folderId)
if (folderId === undefined) {
logger.error(`Google Drive Sync: Create new cloud folder returned an undefined folder id. Not adding folder to synced folder list. Folder path: ${builtPath}`)
}

this.folders[builtPath] = {
'path': folderStructure.folders[builtPath],
'id': folderId
}
}
parentFolderPath = builtPath;
}
Expand All @@ -339,29 +354,32 @@ module.exports = class GoogleAuth {

logger.info(`Sync file from drive: Syncing file to path: ${filePath}`);

this.drive.files
.get({ fileId, alt: "media"}, {responseType: 'stream'})
.then((res) => {
const dest = fs.createWriteStream(filePath);

const decoder = new TextDecoder("utf-8");
const reader = res.data.getReader()
reader.read().then(function processText({ done, value }) {
if (done) {
if (mtime !== undefined) {
console.log(`Setting time: ${mtime}`);
fs.utimesSync(filePath, mtime, mtime)
return new Promise((resolve) => {
this.drive.files
.get({fileId, alt: "media"}, {responseType: 'stream'})
.then((res) => {
const dest = fs.createWriteStream(filePath);

const decoder = new TextDecoder("utf-8");
const reader = res.data.getReader()
reader.read().then(function processText({done, value}) {
if (done) {
if (mtime !== undefined) {
console.log(`Setting time: ${mtime}`);
fs.utimesSync(filePath, mtime, mtime)
}
console.log("Stream complete");
folderStructure.buildFileMenu()
resolve();
return;
}
console.log("Stream complete");
folderStructure.buildFileMenu()
return;
}
dest.write(decoder.decode(value))
dest.write(decoder.decode(value))

// Read some more, and call this function again
return reader.read().then(processText);
});
})
// Read some more, and call this function again
return reader.read().then(processText);
});
})
});
}

/*
Expand All @@ -372,6 +390,10 @@ module.exports = class GoogleAuth {
* param {string} Unique fileId of the file you want to update. Creates new file if fileId doesn't exist
*/
async uploadFileToDrive(filePath, parents, fileId=undefined) {
if (parents === undefined) return logger.error(`Google Drive Sync: Failed uploading file to drive. Parents not specified for file ${filePath}`) ;
if (typeof parents === 'string') parents = [parents];
if (parents.length > 1) return logger.error(`Google Drive Sync: Failed uploading file to drive. Too many parents specified for file ${filePath}`);

filePath = path.normalize(filePath);

// Make sure file exists before uploading
Expand Down Expand Up @@ -412,6 +434,8 @@ module.exports = class GoogleAuth {
}
}

console.log(uploadFile)

uploadFile.upload()

uploadFile.on('success', function(s) {
Expand Down

0 comments on commit 52caff5

Please sign in to comment.