This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const readline = require('readline'); | |
const {google} = require('googleapis'); | |
// If modifying these scopes, delete token.json. | |
const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']; | |
// The file token.json stores the user's access and refresh tokens, and is | |
// created automatically when the authorization flow completes for the first | |
// time. | |
const TOKEN_PATH = 'token.json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileMetadata = { | |
'name': 'photo.jpg' | |
}; | |
var media = { | |
mimeType: 'image/jpeg', | |
body: fs.createReadStream('files/photo.jpg') | |
}; | |
drive.files.create({ | |
resource: fileMetadata, | |
media: media, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//const SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']; | |
const SCOPES = ['https://www.googleapis.com/auth/drive']; | |
//function listFiles(auth) {...} | |
function upload(auth) { | |
var fileMetadata = { | |
'name': 'photo.jpg' | |
}; | |
var media = { | |
mimeType: 'image/jpeg', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Virtru = require('virtru-sdk'); | |
var fs = require('fs'); | |
const email = 'some-email'; | |
const appId = 'some-appid'; | |
const sourceDir = 'some-input-dir'; | |
const destDir = 'some-output-dir'; | |
// Initialize the client. | |
const client = new Virtru.Client({email, appId}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function virtruStart(auth) { | |
promises = fs.readdirSync('./encrypt-in/').filter(function(x) { | |
return x !== '.DS_Store'; | |
}).map(fileName => encrypt(fileName, auth)); // calling encrypt() on each file. | |
Promise.all(promises).then(() => | |
console.log(`Encrypted & Uploaded:`)); | |
} | |
// *** Google Auth *** | |
// Load client secrets from a local file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function encrypt(fileName){ | |
const encryptParams = new Virtru.EncryptParamsBuilder() | |
.withFileSource(`./encrypt-in/${fileName}`) | |
.withDisplayFilename(fileName) | |
.build(); | |
ct = await client.encrypt(encryptParams); | |
var ctString = await ct.toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function encrypt(fileName, auth){ | |
const encryptParams = new Virtru.EncryptParamsBuilder() | |
.withFileSource(`./encrypt-in/${fileName}`) | |
.withDisplayFilename(fileName) | |
.build(); | |
ct = await client.encrypt(encryptParams); | |
var ctString = await ct.toString(); | |
const drive = google.drive({version: 'v3', auth}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drive.files.list({ | |
fields: 'nextPageToken, files(id, name)', | |
q: `'${folderId}' in parents and name contains "tdf3.html" and trashed = false` | |
}, (err, res) => { | |
if (err) return console.log('The API returned an error: ' + err); | |
// Generate list of files. | |
const files = res.data.files; | |
if (files.length) { | |
files.map((file) => { | |
// Get name and ID of each file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
var dest = fs.createWriteStream(`/tmp/${uFileName}`); // download encrypted content to /tmp | |
drive.files.get({ | |
fileId: fileId, | |
alt: 'media' | |
}, { | |
responseType: 'stream' | |
}... | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
var fileName = file.name; | |
// Assign a unique name (uFileName) to each file (fileName | |
// + randnum)to ensure client will not attempt to use same | |
//set of keys for multiple files of the same name. | |
var uFileName = `${fileName}|${Math.random()}`; | |
// Set temporary storage location in /tmp/ | |
var dest = fs.createWriteStream(`/tmp/${uFileName}`); | |
... |