0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 14:12:40 +00:00

Trimming Google APIs

This commit is contained in:
Michiel De Mey
2023-02-26 14:34:23 +01:00
parent 4d7e273f7d
commit 27ea00e9ce
3 changed files with 47 additions and 51 deletions

View File

@@ -1,6 +1,6 @@
/* eslint-disable max-lines */
const _ = require('lodash');
const { google } = require('googleapis');
const drive = require('@googleapis/drive');
const { nanoid } = require('nanoid');
const token = require('./token.js');
const config = require('./config.js');
@@ -14,7 +14,7 @@ if(!config.get('service_account')){
config.get('service_account');
try {
serviceAuth = google.auth.fromJSON(keys);
serviceAuth = drive.auth.fromJSON(keys);
serviceAuth.scopes = ['https://www.googleapis.com/auth/drive'];
} catch (err) {
console.warn(err);
@@ -22,8 +22,6 @@ if(!config.get('service_account')){
}
}
google.options({ auth: serviceAuth || config.get('google_api_key') });
const GoogleActions = {
authCheck : (account, res, updateTokens=true)=>{
@@ -33,7 +31,7 @@ const GoogleActions = {
throw (err);
}
const oAuth2Client = new google.auth.OAuth2(
const oAuth2Client = new drive.auth.OAuth2(
config.get('google_client_id'),
config.get('google_client_secret'),
'/auth/google/redirect'
@@ -60,7 +58,7 @@ const GoogleActions = {
},
getGoogleFolder : async (auth)=>{
const drive = google.drive({ version: 'v3', auth });
const drive = drive({ version: 'v3', auth });
fileMetadata = {
'name' : 'Homebrewery',
@@ -97,7 +95,7 @@ const GoogleActions = {
},
listGoogleBrews : async (auth)=>{
const drive = google.drive({ version: 'v3', auth });
const drive = drive({ version: 'v3', auth });
const obj = await drive.files.list({
pageSize : 1000,
@@ -136,7 +134,7 @@ const GoogleActions = {
},
updateGoogleBrew : async (brew)=>{
const drive = google.drive({ version: 'v3' });
const drive = drive({ version: 'v3' });
await drive.files.update({
fileId : brew.googleId,
@@ -167,7 +165,7 @@ const GoogleActions = {
},
newGoogleBrew : async (auth, brew)=>{
const drive = google.drive({ version: 'v3', auth });
const drive = drive({ version: 'v3', auth });
const media = {
mimeType : 'text/plain',
@@ -218,7 +216,7 @@ const GoogleActions = {
},
getGoogleBrew : async (id, accessId, accessType)=>{
const drive = google.drive({ version: 'v3' });
const drive = drive({ version: 'v3' });
const obj = await drive.files.get({
fileId : id,
@@ -274,7 +272,7 @@ const GoogleActions = {
},
deleteGoogleBrew : async (auth, id, accessId)=>{
const drive = google.drive({ version: 'v3', auth });
const drive = drive({ version: 'v3', auth });
const obj = await drive.files.get({
fileId : id,
@@ -300,7 +298,7 @@ const GoogleActions = {
},
increaseView : async (id, accessId, accessType, brew)=>{
const drive = google.drive({ version: 'v3' });
const drive = drive({ version: 'v3' });
await drive.files.update({
fileId : brew.googleId,