这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/actions/google/drive/sheets/google_sheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class GoogleSheetsAction extends google_drive_1.GoogleDriveAction {
return url.toString();
}
async sendOverwriteData(filename, request, drive, sheet) {
var _a, _b;
winston.info(`${LOG_PREFIX} Beginning sendOverwriteData`, { webhookId: request.webhookId });
let folder;
if (request.formParams.folderid) {
winston.info("Using manual folder id");
Expand Down Expand Up @@ -171,12 +173,14 @@ class GoogleSheetsAction extends google_drive_1.GoogleDriveAction {
else {
options.corpora = "user";
}
winston.info(`${LOG_PREFIX} Searching for existing file with options: ${JSON.stringify(options)}`, { webhookId: request.webhookId });
const files = await this.retriableFileList(drive, options, 0, request.webhookId)
.catch((e) => {
this.sanitizeGaxiosError(e);
winston.warn(`Error listing drives. Error ${e.toString()}`, { webhookId: request.webhookId });
throw e;
});
winston.info(`${LOG_PREFIX} File list call complete. Found ${(_b = (_a = files.data.files) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0} files.`, { webhookId: request.webhookId });
if (files.data.files === undefined || files.data.files.length === 0) {
winston.debug(`New file: ${filename}`, { webhookId: request.webhookId });
return this.sendData(filename, request, drive);
Expand All @@ -191,6 +195,7 @@ class GoogleSheetsAction extends google_drive_1.GoogleDriveAction {
winston.debug(`Error retrieving spreadsheet. Error ${e.toString()}`, { webhookId: request.webhookId });
throw e;
});
winston.info(`${LOG_PREFIX} Spreadsheet get call complete.`, { webhookId: request.webhookId });
if (!sheets.data.sheets || sheets.data.sheets[0].properties === undefined ||
sheets.data.sheets[0].properties.gridProperties === undefined) {
throw "Now sheet data available";
Expand All @@ -203,6 +208,7 @@ class GoogleSheetsAction extends google_drive_1.GoogleDriveAction {
const requestBody = { requests: [] };
let rowCount = 0;
let finished = false;
winston.info(`${LOG_PREFIX} Beginning stream processing.`, { webhookId: request.webhookId });
return request.stream(async (readable) => {
return new Promise(async (resolve, reject) => {
try {
Expand Down
11 changes: 11 additions & 0 deletions src/actions/google/drive/sheets/google_sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export class GoogleSheetsAction extends GoogleDriveAction {
}

async sendOverwriteData(filename: string, request: Hub.ActionRequest, drive: Drive, sheet: Sheet) {
winston.info(`${LOG_PREFIX} Beginning sendOverwriteData`, {webhookId: request.webhookId})
let folder: string | undefined
if (request.formParams.folderid) {
winston.info("Using manual folder id")
Expand Down Expand Up @@ -189,13 +190,20 @@ export class GoogleSheetsAction extends GoogleDriveAction {
options.corpora = "user"
}

winston.info(`${LOG_PREFIX} Searching for existing file with options: ${JSON.stringify(options)}`,
{webhookId: request.webhookId},
)
const files = await this.retriableFileList(drive, options, 0, request.webhookId!)
.catch((e: any) => {
this.sanitizeGaxiosError(e)
winston.warn(`Error listing drives. Error ${e.toString()}`,
{webhookId: request.webhookId})
throw e
})
winston.info(`${LOG_PREFIX} File list call complete. Found ${files.data.files?.length ?? 0} files.`,
{webhookId: request.webhookId},
)

if (files.data.files === undefined || files.data.files.length === 0) {
winston.debug(`New file: ${filename}`,
{webhookId: request.webhookId})
Expand All @@ -214,6 +222,8 @@ export class GoogleSheetsAction extends GoogleDriveAction {
{webhookId: request.webhookId})
throw e
})
winston.info(`${LOG_PREFIX} Spreadsheet get call complete.`, {webhookId: request.webhookId})

if (!sheets.data.sheets || sheets.data.sheets[0].properties === undefined ||
sheets.data.sheets[0].properties.gridProperties === undefined) {
throw "Now sheet data available"
Expand All @@ -227,6 +237,7 @@ export class GoogleSheetsAction extends GoogleDriveAction {
let rowCount = 0
let finished = false

winston.info(`${LOG_PREFIX} Beginning stream processing.`, {webhookId: request.webhookId})
return request.stream(async (readable) => {
return new Promise<void>(async (resolve, reject) => {
try {
Expand Down
4 changes: 4 additions & 0 deletions src/actions/google/drive/sheets/test_google_sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import concatStream = require("concat-stream")

import * as Hub from "../../../../hub"

import * as winston from "winston"
import { ActionCrypto } from "../../../../hub"
import { GoogleSheetsAction } from "./google_sheets"

Expand Down Expand Up @@ -96,6 +97,7 @@ describe(`${action.constructor.name} unit tests`, () => {
}),
},
})
const winstonSpy = sinon.spy(winston, "info")
const flushSpy = sinon.spy(async (buffer: any, _sheet: any, _spreadsheetId: number) => {
chai.expect(buffer).to.deep.equal({
requests: [
Expand Down Expand Up @@ -174,10 +176,12 @@ describe(`${action.constructor.name} unit tests`, () => {
}
chai.expect(action.validateAndExecute(request)).to.eventually.be.fulfilled.then( () => {
chai.expect(flushSpy).to.have.been.calledOnce
chai.expect(winstonSpy).to.have.been.calledWith("[GOOGLE_SHEETS] Beginning sendOverwriteData")
stubDriveClient.restore()
stubSheetClient.restore()
stubFlush.restore()
stubRetriableResize.restore()
winstonSpy.restore()
done()
})

Expand Down