0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 23:32:58 +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

74
package-lock.json generated
View File

@@ -14,6 +14,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",
@@ -24,7 +25,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",
@@ -3168,6 +3168,17 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/@googleapis/drive": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@googleapis/drive/-/drive-4.0.2.tgz",
"integrity": "sha512-NBD2wwkK0iVm5le1YqqDPCgUWl4aeEFIZPciiIIKYBz6kpNtdObj5uHDrtGRUxNzqsUUtYbV9FD1743B8jRZUQ==",
"dependencies": {
"googleapis-common": "^6.0.3"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/@humanwhocodes/config-array": { "node_modules/@humanwhocodes/config-array": {
"version": "0.11.8", "version": "0.11.8",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
@@ -7285,18 +7296,6 @@
"node": ">=12.0.0" "node": ">=12.0.0"
} }
}, },
"node_modules/googleapis": {
"version": "111.0.0",
"resolved": "https://registry.npmjs.org/googleapis/-/googleapis-111.0.0.tgz",
"integrity": "sha512-nIIH+J/o/xjIscJcv3H3BCYgsFiI5ziM3Nbh2lHOWglYGqXE0Nqdt2lfCt4hX257QHEyC1y1iODDkmAMPWDYlw==",
"dependencies": {
"google-auth-library": "^8.0.2",
"googleapis-common": "^6.0.0"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/googleapis-common": { "node_modules/googleapis-common": {
"version": "6.0.3", "version": "6.0.3",
"resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-6.0.3.tgz", "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-6.0.3.tgz",
@@ -15238,9 +15237,9 @@
} }
}, },
"node_modules/supertest/node_modules/formidable": { "node_modules/supertest/node_modules/formidable": {
"version": "2.1.1", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.1.tgz", "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz",
"integrity": "sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==", "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"dezalgo": "^1.0.4", "dezalgo": "^1.0.4",
@@ -15280,17 +15279,17 @@
} }
}, },
"node_modules/supertest/node_modules/superagent": { "node_modules/supertest/node_modules/superagent": {
"version": "8.0.6", "version": "8.0.9",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-8.0.6.tgz", "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.0.9.tgz",
"integrity": "sha512-HqSe6DSIh3hEn6cJvCkaM1BLi466f1LHi4yubR0tpewlMpk4RUFFy35bKz8SsPBwYfIIJy5eclp+3tCYAuX0bw==", "integrity": "sha512-4C7Bh5pyHTvU33KpZgwrNKh/VQnvgtCSqPRfJAUdmrtSYePVzVg4E4OzsrbkhJj9O7SO6Bnv75K/F8XVZT8YHA==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"component-emitter": "^1.3.0", "component-emitter": "^1.3.0",
"cookiejar": "^2.1.3", "cookiejar": "^2.1.4",
"debug": "^4.3.4", "debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1", "fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"formidable": "^2.1.1", "formidable": "^2.1.2",
"methods": "^1.1.2", "methods": "^1.1.2",
"mime": "2.6.0", "mime": "2.6.0",
"qs": "^6.11.0", "qs": "^6.11.0",
@@ -19026,6 +19025,14 @@
} }
} }
}, },
"@googleapis/drive": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/@googleapis/drive/-/drive-4.0.2.tgz",
"integrity": "sha512-NBD2wwkK0iVm5le1YqqDPCgUWl4aeEFIZPciiIIKYBz6kpNtdObj5uHDrtGRUxNzqsUUtYbV9FD1743B8jRZUQ==",
"requires": {
"googleapis-common": "^6.0.3"
}
},
"@humanwhocodes/config-array": { "@humanwhocodes/config-array": {
"version": "0.11.8", "version": "0.11.8",
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
@@ -22291,15 +22298,6 @@
"node-forge": "^1.3.1" "node-forge": "^1.3.1"
} }
}, },
"googleapis": {
"version": "111.0.0",
"resolved": "https://registry.npmjs.org/googleapis/-/googleapis-111.0.0.tgz",
"integrity": "sha512-nIIH+J/o/xjIscJcv3H3BCYgsFiI5ziM3Nbh2lHOWglYGqXE0Nqdt2lfCt4hX257QHEyC1y1iODDkmAMPWDYlw==",
"requires": {
"google-auth-library": "^8.0.2",
"googleapis-common": "^6.0.0"
}
},
"googleapis-common": { "googleapis-common": {
"version": "6.0.3", "version": "6.0.3",
"resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-6.0.3.tgz", "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-6.0.3.tgz",
@@ -28126,9 +28124,9 @@
} }
}, },
"formidable": { "formidable": {
"version": "2.1.1", "version": "2.1.2",
"resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.1.tgz", "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz",
"integrity": "sha512-0EcS9wCFEzLvfiks7omJ+SiYJAiD+TzK4Pcw1UlUoGnhUxDcMKjt0P7x8wEb0u6OHu8Nb98WG3nxtlF5C7bvUQ==", "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==",
"dev": true, "dev": true,
"requires": { "requires": {
"dezalgo": "^1.0.4", "dezalgo": "^1.0.4",
@@ -28153,17 +28151,17 @@
} }
}, },
"superagent": { "superagent": {
"version": "8.0.6", "version": "8.0.9",
"resolved": "https://registry.npmjs.org/superagent/-/superagent-8.0.6.tgz", "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.0.9.tgz",
"integrity": "sha512-HqSe6DSIh3hEn6cJvCkaM1BLi466f1LHi4yubR0tpewlMpk4RUFFy35bKz8SsPBwYfIIJy5eclp+3tCYAuX0bw==", "integrity": "sha512-4C7Bh5pyHTvU33KpZgwrNKh/VQnvgtCSqPRfJAUdmrtSYePVzVg4E4OzsrbkhJj9O7SO6Bnv75K/F8XVZT8YHA==",
"dev": true, "dev": true,
"requires": { "requires": {
"component-emitter": "^1.3.0", "component-emitter": "^1.3.0",
"cookiejar": "^2.1.3", "cookiejar": "^2.1.4",
"debug": "^4.3.4", "debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1", "fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0", "form-data": "^4.0.0",
"formidable": "^2.1.1", "formidable": "^2.1.2",
"methods": "^1.1.2", "methods": "^1.1.2",
"mime": "2.6.0", "mime": "2.6.0",
"qs": "^6.11.0", "qs": "^6.11.0",

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 drive = 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 = drive.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,8 +22,6 @@ if(!config.get('service_account')){
} }
} }
google.options({ auth: serviceAuth || config.get('google_api_key') });
const GoogleActions = { const GoogleActions = {
authCheck : (account, res, updateTokens=true)=>{ authCheck : (account, res, updateTokens=true)=>{
@@ -33,7 +31,7 @@ const GoogleActions = {
throw (err); throw (err);
} }
const oAuth2Client = new google.auth.OAuth2( const oAuth2Client = new drive.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 +58,7 @@ const GoogleActions = {
}, },
getGoogleFolder : async (auth)=>{ getGoogleFolder : async (auth)=>{
const drive = google.drive({ version: 'v3', auth }); const drive = drive({ version: 'v3', auth });
fileMetadata = { fileMetadata = {
'name' : 'Homebrewery', 'name' : 'Homebrewery',
@@ -97,7 +95,7 @@ const GoogleActions = {
}, },
listGoogleBrews : async (auth)=>{ listGoogleBrews : async (auth)=>{
const drive = google.drive({ version: 'v3', auth }); const drive = drive({ version: 'v3', auth });
const obj = await drive.files.list({ const obj = await drive.files.list({
pageSize : 1000, pageSize : 1000,
@@ -136,7 +134,7 @@ const GoogleActions = {
}, },
updateGoogleBrew : async (brew)=>{ updateGoogleBrew : async (brew)=>{
const drive = google.drive({ version: 'v3' }); const drive = drive({ version: 'v3' });
await drive.files.update({ await drive.files.update({
fileId : brew.googleId, fileId : brew.googleId,
@@ -167,7 +165,7 @@ const GoogleActions = {
}, },
newGoogleBrew : async (auth, brew)=>{ newGoogleBrew : async (auth, brew)=>{
const drive = google.drive({ version: 'v3', auth }); const drive = drive({ version: 'v3', auth });
const media = { const media = {
mimeType : 'text/plain', mimeType : 'text/plain',
@@ -218,7 +216,7 @@ const GoogleActions = {
}, },
getGoogleBrew : async (id, accessId, accessType)=>{ getGoogleBrew : async (id, accessId, accessType)=>{
const drive = google.drive({ version: 'v3' }); const drive = drive({ version: 'v3' });
const obj = await drive.files.get({ const obj = await drive.files.get({
fileId : id, fileId : id,
@@ -274,7 +272,7 @@ const GoogleActions = {
}, },
deleteGoogleBrew : async (auth, id, accessId)=>{ deleteGoogleBrew : async (auth, id, accessId)=>{
const drive = google.drive({ version: 'v3', auth }); const drive = drive({ version: 'v3', auth });
const obj = await drive.files.get({ const obj = await drive.files.get({
fileId : id, fileId : id,
@@ -300,7 +298,7 @@ const GoogleActions = {
}, },
increaseView : async (id, accessId, accessType, brew)=>{ increaseView : async (id, accessId, accessType, brew)=>{
const drive = google.drive({ version: 'v3' }); const drive = drive({ version: 'v3' });
await drive.files.update({ await drive.files.update({
fileId : brew.googleId, fileId : brew.googleId,