Merge branch 'master' into fix/rest-download-images
This commit is contained in:
commit
acab64ea45
4 changed files with 52 additions and 25 deletions
|
@ -1,4 +1,6 @@
|
|||
import { IdentityContext, Snippet, VM } from "@budibase/types"
|
||||
import { OAuth2Client } from "google-auth-library"
|
||||
import { GoogleSpreadsheet } from "google-spreadsheet"
|
||||
|
||||
// keep this out of Budibase types, don't want to expose context info
|
||||
export type ContextMap = {
|
||||
|
@ -12,4 +14,8 @@ export type ContextMap = {
|
|||
vm?: VM
|
||||
cleanup?: (() => void | Promise<void>)[]
|
||||
snippets?: Snippet[]
|
||||
googleSheets?: {
|
||||
oauthClient: OAuth2Client
|
||||
clients: Record<string, GoogleSpreadsheet>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@
|
|||
"dotenv": "8.2.0",
|
||||
"form-data": "4.0.0",
|
||||
"global-agent": "3.0.0",
|
||||
"google-spreadsheet": "4.1.2",
|
||||
"google-spreadsheet": "npm:@budibase/google-spreadsheet@4.1.2",
|
||||
"ioredis": "5.3.2",
|
||||
"isolated-vm": "^4.7.2",
|
||||
"jimp": "0.22.10",
|
||||
|
|
|
@ -228,6 +228,10 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
|||
|
||||
private async connect() {
|
||||
try {
|
||||
const bbCtx = context.getCurrentContext()
|
||||
let oauthClient = bbCtx?.googleSheets?.oauthClient
|
||||
|
||||
if (!oauthClient) {
|
||||
await setupCreationAuth(this.config)
|
||||
|
||||
// Initialise oAuth client
|
||||
|
@ -236,7 +240,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
|||
throw new HTTPError("Google config not found", 400)
|
||||
}
|
||||
|
||||
const oauthClient = new OAuth2Client({
|
||||
oauthClient = new OAuth2Client({
|
||||
clientId: googleConfig.clientID,
|
||||
clientSecret: googleConfig.clientSecret,
|
||||
})
|
||||
|
@ -251,9 +255,26 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
|||
refresh_token: this.config.auth.refreshToken,
|
||||
access_token: tokenResponse.access_token,
|
||||
})
|
||||
if (bbCtx && !bbCtx.googleSheets) {
|
||||
bbCtx.googleSheets = {
|
||||
oauthClient,
|
||||
clients: {},
|
||||
}
|
||||
bbCtx.cleanup = bbCtx.cleanup || []
|
||||
}
|
||||
}
|
||||
|
||||
this.client = new GoogleSpreadsheet(this.spreadsheetId, oauthClient)
|
||||
await this.client.loadInfo()
|
||||
let client = bbCtx?.googleSheets?.clients[this.spreadsheetId]
|
||||
if (!client) {
|
||||
client = new GoogleSpreadsheet(this.spreadsheetId, oauthClient)
|
||||
await client.loadInfo()
|
||||
|
||||
if (bbCtx?.googleSheets?.clients) {
|
||||
bbCtx.googleSheets.clients[this.spreadsheetId] = client
|
||||
}
|
||||
}
|
||||
|
||||
this.client = client
|
||||
} catch (err: any) {
|
||||
// this happens for xlsx imports
|
||||
if (err.message?.includes("operation is not supported")) {
|
||||
|
|
|
@ -11540,10 +11540,10 @@ google-p12-pem@^4.0.0:
|
|||
dependencies:
|
||||
node-forge "^1.3.1"
|
||||
|
||||
google-spreadsheet@4.1.2:
|
||||
"google-spreadsheet@npm:@budibase/google-spreadsheet@4.1.2":
|
||||
version "4.1.2"
|
||||
resolved "https://registry.yarnpkg.com/google-spreadsheet/-/google-spreadsheet-4.1.2.tgz#92e30fdba7e0d78c55d50731528df7835d58bfee"
|
||||
integrity sha512-HFBweDAkOcyC2qO9kmWESKbNuOcn+R7UzZN/tj5LLNxVv8FHmg113u0Ow+yaKwwIOt/NnDtPLuptAhaxTs0FYw==
|
||||
resolved "https://registry.yarnpkg.com/@budibase/google-spreadsheet/-/google-spreadsheet-4.1.2.tgz#90548ccba2284b3042b08d2974ef3caeaf772ad9"
|
||||
integrity sha512-dxoY3rQGGnuNeZiXhNc9oYPduzU8xnIjWujFwNvaRRv3zWeUV7mj6HE2o/OJOeekPGt7o44B+w6DfkiaoteZgg==
|
||||
dependencies:
|
||||
axios "^1.4.0"
|
||||
lodash "^4.17.21"
|
||||
|
|
Loading…
Reference in a new issue