new(all); ROUTER.
This commit is contained in:
parent
5798463e5f
commit
9b17ebeecf
1 changed files with 30 additions and 25 deletions
|
@ -677,11 +677,9 @@ await fs.writeFile('.env', env);
|
||||||
public async setConfig(min, name: string, value: any): Promise<any> {
|
public async setConfig(min, name: string, value: any): Promise<any> {
|
||||||
if (GBConfigService.get('STORAGE_NAME')) {
|
if (GBConfigService.get('STORAGE_NAME')) {
|
||||||
// Handles calls for BASIC persistence on sheet files.
|
// Handles calls for BASIC persistence on sheet files.
|
||||||
|
|
||||||
GBLog.info(`Defining Config.xlsx variable ${name}= '${value}'...`);
|
GBLog.info(`Defining Config.xlsx variable ${name}= '${value}'...`);
|
||||||
|
|
||||||
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
|
||||||
|
|
||||||
const maxLines = 512;
|
const maxLines = 512;
|
||||||
const file = 'Config.xlsx';
|
const file = 'Config.xlsx';
|
||||||
const packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
const packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||||
|
@ -689,36 +687,43 @@ await fs.writeFile('.env', env);
|
||||||
let document = await new SystemKeywords().internalGetDocument(client, baseUrl, packagePath, file);
|
let document = await new SystemKeywords().internalGetDocument(client, baseUrl, packagePath, file);
|
||||||
|
|
||||||
// Creates book session that will be discarded.
|
// Creates book session that will be discarded.
|
||||||
|
|
||||||
let sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
let sheets = await client.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets`).get();
|
||||||
|
|
||||||
|
// Get the current rows in column A
|
||||||
let results = await client
|
let results = await client
|
||||||
.api(
|
.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='A1:A${maxLines}')`)
|
||||||
`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='A1:A${maxLines}')`
|
|
||||||
)
|
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
const rows = results.text;
|
const rows = results.values;
|
||||||
let address = '';
|
let address = '';
|
||||||
|
let lastEmptyRow = -1;
|
||||||
|
let isEdit = false;
|
||||||
|
|
||||||
// Fills the row variable.
|
// Loop through column A to find the row where name matches, or find the next empty row
|
||||||
|
|
||||||
for (let i = 1; i <= rows.length; i++) {
|
for (let i = 1; i <= rows.length; i++) {
|
||||||
let result = rows[i - 1][0];
|
let result = rows[i - 1][0];
|
||||||
if (result && result.toLowerCase() === name.toLowerCase()) {
|
if (result && result.toLowerCase() === name.toLowerCase()) {
|
||||||
address = `B${i}:B${i}`;
|
address = `B${i}:B${i}`; // Match found, update value in column B
|
||||||
|
isEdit = true; // We are in editing mode
|
||||||
break;
|
break;
|
||||||
|
} else if (!result && lastEmptyRow === -1) {
|
||||||
|
lastEmptyRow = i; // Store the first empty row if no match is found
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = { values: [[]] };
|
// If no match was found and there's an empty row, add a new entry
|
||||||
body.values[0][0] = value;
|
if (!isEdit && lastEmptyRow !== -1) {
|
||||||
|
address = `A${lastEmptyRow}:B${lastEmptyRow}`; // Add new entry in columns A and B
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare the request body based on whether it's an edit or add operation
|
||||||
|
let body = { values: isEdit ? [[value]] : [[name, value]] };
|
||||||
|
|
||||||
|
// Update or add the new value in the found address
|
||||||
await client
|
await client
|
||||||
.api(
|
.api(`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='${address}')`)
|
||||||
`${baseUrl}/drive/items/${document.id}/workbook/worksheets('${sheets.value[0].name}')/range(address='${address}')`
|
|
||||||
)
|
|
||||||
.patch(body);
|
.patch(body);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
let packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
let packagePath = GBUtil.getGBAIPath(min.botId, `gbot`);
|
||||||
const config = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, 'config.csv');
|
const config = path.join(GBConfigService.get('STORAGE_LIBRARY'), packagePath, 'config.csv');
|
||||||
|
|
Loading…
Add table
Reference in a new issue