0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-04 16:52:38 +00:00

Merge pull request #2696 from MichielDeMey/feature/trim-google-apis

[Draft] Trimming Google APIs
This commit is contained in:
Trevor Buckner
2023-03-07 14:53:20 -05:00
committed by GitHub
3 changed files with 29146 additions and 29148 deletions

58270
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -72,6 +72,7 @@
"@babel/plugin-transform-runtime": "^7.21.0", "@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.19.4", "@babel/preset-env": "^7.19.4",
"@babel/preset-react": "^7.18.6", "@babel/preset-react": "^7.18.6",
"@googleapis/drive": "^4.0.2",
"body-parser": "^1.20.2", "body-parser": "^1.20.2",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"codemirror": "^5.65.6", "codemirror": "^5.65.6",
@@ -82,7 +83,6 @@
"express-async-handler": "^1.2.0", "express-async-handler": "^1.2.0",
"express-static-gzip": "2.1.7", "express-static-gzip": "2.1.7",
"fs-extra": "11.1.0", "fs-extra": "11.1.0",
"googleapis": "111.0.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"jwt-simple": "^0.5.6", "jwt-simple": "^0.5.6",
"less": "^3.13.1", "less": "^3.13.1",

View File

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