Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function uploadDatabaseDump(auth) {
const drive = google.drive({ version: 'v3', auth });
// get file path from arguments
const [, , inputFilePath] = process.argv;
if (!inputFilePath) {
console.error('Error: No filename was specified in arguments');
process.exit(1);
}
drive.files.list(
{
q:
"name='Database Dumps' and mimeType='application/vnd.google-apps.folder'",
},
(err, listFileResponse) => {
if (err) {
throw err;
}
console.log('Google credentials not set, skip Gdrive initialization.');
return;
}
const { token, secrets } = JSON.parse(process.env.GOOGLE_CREDENTIALS);
// Authorize a client with the loaded credentials, then call the
// Drive API.
const clientSecret = secrets.installed.client_secret;
const clientId = secrets.installed.client_id;
const redirectUrl = secrets.installed.redirect_uris[0];
const oauth2Client = new OAuth2(clientId, clientSecret, redirectUrl);
// Check if we have previously stored a token.
oauth2Client.setCredentials(token);
drive = google.drive({ version: 'v3', auth: oauth2Client });
}
const main = async () => {
const auth = await google.auth.getClient({ scopes: SCOPES });
const sheets = google.sheets({ version: 'v4', auth });
const token = (await fs.readFile('githubToken.json')).toString().trim();
const octokit = new Octokit({ auth: `token ${token}` });
const drive = google.drive({ version: 'v3', auth })
await deleteAllFiles(drive);
// const title = 'Statistics from GitHub and food survey for I/O talk';
// let id = await checkForSheet(drive, title);
// if (!id) {
// id = await createSpreadsheet(sheets, title);
// await writeHeader(sheets, id, 0);
// await addUser(drive, id, 'fhinkel.demo@gmail.com');
// await addUser(drive, id, 'GSuite.demos@gmail.com');
// }
// let cloneData = await numberOfClones(octokit);
// await appendCloneData(sheets, id, cloneData);
}
function getFileID(folder, name, cb) {
var drive = google.drive('v3');
// debug("GET FILE ID : %s/%s",folder,name);
drive.files.list({
q: "name = '" + name + "' and trashed = false and '" + folder + "' in parents",
fields: 'files(id, name)',
spaces: 'drive',
// parents: [folder],
auth: auth
}, function(err, result) {
// debug("GET FILE ID result",result,err);
cb(err, result);
});
}
function getFolder(folder, cb) {
var drive = google.drive('v3');
// debug("getFolder",folder);
drive.files.list({
q: "mimeType='application/vnd.google-apps.folder' and name = '" + folder + "' and trashed = false",
fields: 'nextPageToken, files(id, name)',
spaces: 'drive',
auth: auth
}, function(err, res) {
if (err) {
debug("getFolder - err", err);
cb(err, folder);
} else {
if (res.data.files.length > 0) {
if (res.data.files.length > 1) {
debug("Multiple folders with same name, taking the first one", folder, 'in', res.data.files);
}
// debug('Found Folder: ', res.files[0].name, res.files[0].id);
function downloadAllFilesFromTheGoogleDrive(auth){
const drive = google.drive({ version: 'v3', auth});
return new Promise((resolve,reject) => {
drive.files.list({
spaces: 'appDataFolder',
fields: 'nextPageToken, files(id, name)',
pageSize: 100
}, function (err, res) {
if (err) {
console.error(err);
reject(err);
}else{
let i = 0;
for(let file of res.data.files) {
if(file.name != '_init'){
const dest = fs.createWriteStream(__dirname + '/gdriveCred/'+file.name);
function updateIdCallback(auth, accountName, username, password, masterPassword){
const drive = google.drive({ version: 'v3', auth});
return new Promise((resolve,reject) => {
updateAccountGdrive(drive,{
name: accountName,
username: username,
password: password,
},masterPassword).then(createdResult => {
resolve(createdResult);
}).catch(e => {
reject(e);
});
});
}
const checkAuth = async (client_id, client_secret, code) => {
let key = `${client_id}:${client_secret}`
const oauth2 = clientMap[key]
let res = await oauth2.getToken(code)
if (res.tokens) {
saveAuth(key , res.tokens)
oauth2.setCredentials(res.tokens)
driveMap[key] = google.drive({ version: 'v3', oauth2 })
return res.tokens
} else {
return false
}
}
constructor() {
this.sheetsAPI = google.sheets('v4');
this.driveAPI = google.drive('v3');
this.docsAPI = google.docs('v1');
}
static async copyPresentation(oauth2Client, title, presentationId) {
let drive = google.drive({ version: 'v3', auth: oauth2Client});
let res = await drive.files.copy({
fileId: presentationId,
resource: {
name: title
}
});
return SlideGenerator.forPresentation(oauth2Client, res.data.id);
}