mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 23:19:09 +00:00
fix: deepsource recommendations
This commit is contained in:
@@ -66,9 +66,7 @@ export default function SheetsModal(props: SheetsModalProps) {
|
|||||||
|
|
||||||
const handleFile = async (event: ChangeEvent<HTMLInputElement>) => {
|
const handleFile = async (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
const selectedFile = event?.target?.files?.[0];
|
const selectedFile = event?.target?.files?.[0];
|
||||||
if (!selectedFile) {
|
if (selectedFile) {
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
await uploadSheetClientFile(selectedFile).catch((err) => {
|
await uploadSheetClientFile(selectedFile).catch((err) => {
|
||||||
console.error(err); //TODO: how to show this to the user
|
console.error(err); //TODO: how to show this to the user
|
||||||
});
|
});
|
||||||
@@ -124,7 +122,7 @@ export default function SheetsModal(props: SheetsModalProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handlePushData = () => {
|
const handlePushData = () => {
|
||||||
postPushSheet().then((_) => {});
|
postPushSheet();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFinalise = async () => {
|
const handleFinalise = async () => {
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ export async function sheetAuthUrl(req, res) {
|
|||||||
* @method GET
|
* @method GET
|
||||||
*/
|
*/
|
||||||
export const getGoogleSheetSettings = async (req, res) => {
|
export const getGoogleSheetSettings = async (req, res) => {
|
||||||
const sheet = DataProvider.getGoogleSheet();
|
const sheet = await DataProvider.getGoogleSheet();
|
||||||
res.status(200).send(sheet);
|
res.status(200).send(sheet);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export function cellRequenstFromEvent(
|
|||||||
worksheetId: number,
|
worksheetId: number,
|
||||||
metadata,
|
metadata,
|
||||||
): sheets_v4.Schema$Request {
|
): sheets_v4.Schema$Request {
|
||||||
const r: sheets_v4.Schema$CellData[] = [];
|
const returnRows: sheets_v4.Schema$CellData[] = [];
|
||||||
const tmp = Object.entries(metadata)
|
const tmp = Object.entries(metadata)
|
||||||
.filter(([_, value]) => value !== undefined)
|
.filter(([_, value]) => value !== undefined)
|
||||||
.sort(([_a, a], [_b, b]) => a['col'] - b['col']) as [string, { col: number; row: number }][];
|
.sort(([_a, a], [_b, b]) => a['col'] - b['col']) as [string, { col: number; row: number }][];
|
||||||
@@ -64,25 +64,25 @@ export function cellRequenstFromEvent(
|
|||||||
tmp.forEach(([key, _]) => {
|
tmp.forEach(([key, _]) => {
|
||||||
if (isOntimeEvent(event)) {
|
if (isOntimeEvent(event)) {
|
||||||
if (key === 'blank') {
|
if (key === 'blank') {
|
||||||
r.push({});
|
returnRows.push({});
|
||||||
} else if (key === 'colour') {
|
} else if (key === 'colour') {
|
||||||
r.push({
|
returnRows.push({
|
||||||
userEnteredValue: { stringValue: event.colour },
|
userEnteredValue: { stringValue: event.colour },
|
||||||
});
|
});
|
||||||
} else if (typeof event[key] === 'number') {
|
} else if (typeof event[key] === 'number') {
|
||||||
r.push({
|
returnRows.push({
|
||||||
userEnteredValue: { stringValue: millisToString(event[key], true) },
|
userEnteredValue: { stringValue: millisToString(event[key], true) },
|
||||||
});
|
});
|
||||||
} else if (typeof event[key] === 'string') {
|
} else if (typeof event[key] === 'string') {
|
||||||
r.push({
|
returnRows.push({
|
||||||
userEnteredValue: { stringValue: event[key] },
|
userEnteredValue: { stringValue: event[key] },
|
||||||
});
|
});
|
||||||
} else if (typeof event[key] === 'boolean') {
|
} else if (typeof event[key] === 'boolean') {
|
||||||
r.push({
|
returnRows.push({
|
||||||
userEnteredValue: { stringValue: event[key] ? 'x' : '' },
|
userEnteredValue: { stringValue: event[key] ? 'x' : '' },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
r.push({});
|
returnRows.push({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -96,7 +96,7 @@ export function cellRequenstFromEvent(
|
|||||||
fields: 'userEnteredValue',
|
fields: 'userEnteredValue',
|
||||||
rows: [
|
rows: [
|
||||||
{
|
{
|
||||||
values: r,
|
values: returnRows,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -115,7 +115,7 @@ export function cellRequenstFromProjectData(
|
|||||||
worksheetId: number,
|
worksheetId: number,
|
||||||
metadata,
|
metadata,
|
||||||
): sheets_v4.Schema$Request {
|
): sheets_v4.Schema$Request {
|
||||||
const r: sheets_v4.Schema$RowData[] = [];
|
const returnRows: sheets_v4.Schema$RowData[] = [];
|
||||||
const tmp = Object.entries(metadata)
|
const tmp = Object.entries(metadata)
|
||||||
.filter(([_, value]) => value !== undefined)
|
.filter(([_, value]) => value !== undefined)
|
||||||
.sort(([_a, a], [_b, b]) => a['col'] - b['col']) as [string, { col: number; row: number }][];
|
.sort(([_a, a], [_b, b]) => a['col'] - b['col']) as [string, { col: number; row: number }][];
|
||||||
@@ -139,9 +139,9 @@ export function cellRequenstFromProjectData(
|
|||||||
}
|
}
|
||||||
tmp.forEach(([key, _]) => {
|
tmp.forEach(([key, _]) => {
|
||||||
if (key == 'blank') {
|
if (key == 'blank') {
|
||||||
r.push({});
|
returnRows.push({});
|
||||||
} else {
|
} else {
|
||||||
r.push({
|
returnRows.push({
|
||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
userEnteredValue: { stringValue: projectData[key] },
|
userEnteredValue: { stringValue: projectData[key] },
|
||||||
@@ -159,7 +159,7 @@ export function cellRequenstFromProjectData(
|
|||||||
columnIndex: minCol,
|
columnIndex: minCol,
|
||||||
},
|
},
|
||||||
fields: 'userEnteredValue',
|
fields: 'userEnteredValue',
|
||||||
rows: r,
|
rows: returnRows,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,123 +122,123 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
const handlers = {
|
const handlers = {
|
||||||
[importMap.projectName]: (row: number, col: number) => {
|
[importMap.projectName]: (row: number, col: number) => {
|
||||||
projectTitleNext = true;
|
projectTitleNext = true;
|
||||||
projectMetadata['title'] = { row: row, col: col };
|
projectMetadata['title'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.projectDescription]: (row: number, col: number) => {
|
[importMap.projectDescription]: (row: number, col: number) => {
|
||||||
projectDescriptionNext = true;
|
projectDescriptionNext = true;
|
||||||
projectMetadata['description'] = { row: row, col: col };
|
projectMetadata['description'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.publicUrl]: (row: number, col: number) => {
|
[importMap.publicUrl]: (row: number, col: number) => {
|
||||||
publicUrlNext = true;
|
publicUrlNext = true;
|
||||||
projectMetadata['publicUrl'] = { row: row, col: col };
|
projectMetadata['publicUrl'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.publicInfo]: (row: number, col: number) => {
|
[importMap.publicInfo]: (row: number, col: number) => {
|
||||||
publicInfoNext = true;
|
publicInfoNext = true;
|
||||||
projectMetadata['publicInfo'] = { row: row, col: col };
|
projectMetadata['publicInfo'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.backstageUrl]: (row: number, col: number) => {
|
[importMap.backstageUrl]: (row: number, col: number) => {
|
||||||
backstageUrlNext = true;
|
backstageUrlNext = true;
|
||||||
projectMetadata['backstageUrl'] = { row: row, col: col };
|
projectMetadata['backstageUrl'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.backstageInfo]: (row: number, col: number) => {
|
[importMap.backstageInfo]: (row: number, col: number) => {
|
||||||
backstageInfoNext = true;
|
backstageInfoNext = true;
|
||||||
projectMetadata['backstageInfo'] = { row: row, col: col };
|
projectMetadata['backstageInfo'] = { row, col };
|
||||||
},
|
},
|
||||||
|
|
||||||
[importMap.timeStart]: (row: number, col: number) => {
|
[importMap.timeStart]: (row: number, col: number) => {
|
||||||
timeStartIndex = col;
|
timeStartIndex = col;
|
||||||
rundownMetadata['timeStart'] = { row: row, col: col };
|
rundownMetadata['timeStart'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.timeEnd]: (row: number, col: number) => {
|
[importMap.timeEnd]: (row: number, col: number) => {
|
||||||
timeEndIndex = col;
|
timeEndIndex = col;
|
||||||
rundownMetadata['timeEnd'] = { row: row, col: col };
|
rundownMetadata['timeEnd'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.duration]: (row: number, col: number) => {
|
[importMap.duration]: (row: number, col: number) => {
|
||||||
durationIndex = col;
|
durationIndex = col;
|
||||||
rundownMetadata['duration'] = { row: row, col: col };
|
rundownMetadata['duration'] = { row, col };
|
||||||
},
|
},
|
||||||
|
|
||||||
[importMap.cue]: (row: number, col: number) => {
|
[importMap.cue]: (row: number, col: number) => {
|
||||||
cueIndex = col;
|
cueIndex = col;
|
||||||
rundownMetadata['cue'] = { row: row, col: col };
|
rundownMetadata['cue'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.title]: (row: number, col: number) => {
|
[importMap.title]: (row: number, col: number) => {
|
||||||
titleIndex = col;
|
titleIndex = col;
|
||||||
rundownMetadata['title'] = { row: row, col: col };
|
rundownMetadata['title'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.presenter]: (row: number, col: number) => {
|
[importMap.presenter]: (row: number, col: number) => {
|
||||||
presenterIndex = col;
|
presenterIndex = col;
|
||||||
rundownMetadata['presenter'] = { row: row, col: col };
|
rundownMetadata['presenter'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.subtitle]: (row: number, col: number) => {
|
[importMap.subtitle]: (row: number, col: number) => {
|
||||||
subtitleIndex = col;
|
subtitleIndex = col;
|
||||||
rundownMetadata['subtitle'] = { row: row, col: col };
|
rundownMetadata['subtitle'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.isPublic]: (row: number, col: number) => {
|
[importMap.isPublic]: (row: number, col: number) => {
|
||||||
isPublicIndex = col;
|
isPublicIndex = col;
|
||||||
rundownMetadata['isPublic'] = { row: row, col: col };
|
rundownMetadata['isPublic'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.skip]: (row: number, col: number) => {
|
[importMap.skip]: (row: number, col: number) => {
|
||||||
skipIndex = col;
|
skipIndex = col;
|
||||||
rundownMetadata['skip'] = { row: row, col: col };
|
rundownMetadata['skip'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.note]: (row: number, col: number) => {
|
[importMap.note]: (row: number, col: number) => {
|
||||||
notesIndex = col;
|
notesIndex = col;
|
||||||
rundownMetadata['note'] = { row: row, col: col };
|
rundownMetadata['note'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.colour]: (row: number, col: number) => {
|
[importMap.colour]: (row: number, col: number) => {
|
||||||
colourIndex = col;
|
colourIndex = col;
|
||||||
rundownMetadata['colour'] = { row: row, col: col };
|
rundownMetadata['colour'] = { row, col };
|
||||||
},
|
},
|
||||||
|
|
||||||
[importMap.endAction]: (row: number, col: number) => {
|
[importMap.endAction]: (row: number, col: number) => {
|
||||||
endActionIndex = col;
|
endActionIndex = col;
|
||||||
rundownMetadata['endAction'] = { row: row, col: col };
|
rundownMetadata['endAction'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.timerType]: (row: number, col: number) => {
|
[importMap.timerType]: (row: number, col: number) => {
|
||||||
timerTypeIndex = col;
|
timerTypeIndex = col;
|
||||||
rundownMetadata['timerType'] = { row: row, col: col };
|
rundownMetadata['timerType'] = { row, col };
|
||||||
},
|
},
|
||||||
|
|
||||||
[importMap.user0]: (row: number, col: number) => {
|
[importMap.user0]: (row: number, col: number) => {
|
||||||
user0Index = col;
|
user0Index = col;
|
||||||
rundownMetadata['user0'] = { row: row, col: col };
|
rundownMetadata['user0'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user1]: (row: number, col: number) => {
|
[importMap.user1]: (row: number, col: number) => {
|
||||||
user1Index = col;
|
user1Index = col;
|
||||||
rundownMetadata['user1'] = { row: row, col: col };
|
rundownMetadata['user1'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user2]: (row: number, col: number) => {
|
[importMap.user2]: (row: number, col: number) => {
|
||||||
user2Index = col;
|
user2Index = col;
|
||||||
rundownMetadata['user2'] = { row: row, col: col };
|
rundownMetadata['user2'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user3]: (row: number, col: number) => {
|
[importMap.user3]: (row: number, col: number) => {
|
||||||
user3Index = col;
|
user3Index = col;
|
||||||
rundownMetadata['user3'] = { row: row, col: col };
|
rundownMetadata['user3'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user4]: (row: number, col: number) => {
|
[importMap.user4]: (row: number, col: number) => {
|
||||||
user4Index = col;
|
user4Index = col;
|
||||||
rundownMetadata['user4'] = { row: row, col: col };
|
rundownMetadata['user4'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user5]: (row: number, col: number) => {
|
[importMap.user5]: (row: number, col: number) => {
|
||||||
user5Index = col;
|
user5Index = col;
|
||||||
rundownMetadata['user5'] = { row: row, col: col };
|
rundownMetadata['user5'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user6]: (row: number, col: number) => {
|
[importMap.user6]: (row: number, col: number) => {
|
||||||
user6Index = col;
|
user6Index = col;
|
||||||
rundownMetadata['user6'] = { row: row, col: col };
|
rundownMetadata['user6'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user7]: (row: number, col: number) => {
|
[importMap.user7]: (row: number, col: number) => {
|
||||||
user7Index = col;
|
user7Index = col;
|
||||||
rundownMetadata['user7'] = { row: row, col: col };
|
rundownMetadata['user7'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user8]: (row: number, col: number) => {
|
[importMap.user8]: (row: number, col: number) => {
|
||||||
user8Index = col;
|
user8Index = col;
|
||||||
rundownMetadata['user8'] = { row: row, col: col };
|
rundownMetadata['user8'] = { row, col };
|
||||||
},
|
},
|
||||||
[importMap.user9]: (row: number, col: number) => {
|
[importMap.user9]: (row: number, col: number) => {
|
||||||
user9Index = col;
|
user9Index = col;
|
||||||
rundownMetadata['user9'] = { row: row, col: col };
|
rundownMetadata['user9'] = { row, col };
|
||||||
},
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
@@ -336,8 +336,8 @@ export const parseExcel = (excelData: unknown[][], options?: Partial<ExcelImport
|
|||||||
version: '2.0.0',
|
version: '2.0.0',
|
||||||
},
|
},
|
||||||
userFields: customUserFields,
|
userFields: customUserFields,
|
||||||
projectMetadata: projectMetadata,
|
projectMetadata,
|
||||||
rundownMetadata: rundownMetadata,
|
rundownMetadata,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
import { OAuth2Client } from 'google-auth-library';
|
|
||||||
import { readFile, writeFile } from 'fs/promises';
|
|
||||||
import { sheets, sheets_v4 } from '@googleapis/sheets';
|
import { sheets, sheets_v4 } from '@googleapis/sheets';
|
||||||
|
import { readFile, writeFile } from 'fs/promises';
|
||||||
|
import { OAuth2Client } from 'google-auth-library';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
|
import { DatabaseModel, GoogleSheetState, LogOrigin } from 'ontime-types';
|
||||||
|
import { join } from 'path';
|
||||||
import { URL } from 'url';
|
import { URL } from 'url';
|
||||||
import { logger } from '../classes/Logger.js';
|
import { logger } from '../classes/Logger.js';
|
||||||
|
import { DataProvider } from '../classes/data-provider/DataProvider.js';
|
||||||
import { getAppDataPath } from '../setup.js';
|
import { getAppDataPath } from '../setup.js';
|
||||||
import { DatabaseModel, LogOrigin } from 'ontime-types';
|
import { ensureDirectory } from './fileManagement.js';
|
||||||
|
import { cellRequenstFromEvent, cellRequenstFromProjectData, getA1Notation } from './googleSheetUtils.js';
|
||||||
import { parseExcel } from './parser.js';
|
import { parseExcel } from './parser.js';
|
||||||
import { parseProject, parseRundown, parseUserFields } from './parserFunctions.js';
|
import { parseProject, parseRundown, parseUserFields } from './parserFunctions.js';
|
||||||
import { ensureDirectory } from './fileManagement.js';
|
|
||||||
import { DataProvider } from '../classes/data-provider/DataProvider.js';
|
|
||||||
import { GoogleSheetState } from 'ontime-types';
|
|
||||||
import { cellRequenstFromEvent, cellRequenstFromProjectData, getA1Notation } from './googleSheetUtils.js';
|
|
||||||
import { join } from 'path';
|
|
||||||
|
|
||||||
type ResponseOK = {
|
type ResponseOK = {
|
||||||
data: Partial<DatabaseModel>;
|
data: Partial<DatabaseModel>;
|
||||||
@@ -24,9 +23,9 @@ class sheet {
|
|||||||
private readonly sheetsFolder;
|
private readonly sheetsFolder;
|
||||||
private readonly client_secret;
|
private readonly client_secret;
|
||||||
private static authUrl: null | string = null;
|
private static authUrl: null | string = null;
|
||||||
private worksheetId: number = 0;
|
private worksheetId = 0;
|
||||||
private sheetId: string = '';
|
private sheetId = '';
|
||||||
private range: string = '';
|
private range = '';
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
const appDataPath = getAppDataPath();
|
const appDataPath = getAppDataPath();
|
||||||
@@ -87,10 +86,13 @@ class sheet {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (spreadsheets.status === 200) {
|
if (spreadsheets.status === 200) {
|
||||||
const w = spreadsheets.data.sheets.find((p) => p.properties.title == worksheet);
|
const ourWorksheetData = spreadsheets.data.sheets.find((n) => n.properties.title == worksheet);
|
||||||
if (w !== undefined) {
|
if (ourWorksheetData !== undefined) {
|
||||||
const endCell = getA1Notation(w.properties.gridProperties.rowCount, w.properties.gridProperties.columnCount);
|
const endCell = getA1Notation(
|
||||||
return { worksheetId: w.properties.sheetId, range: `${worksheet}!A1:${endCell}` };
|
ourWorksheetData.properties.gridProperties.rowCount,
|
||||||
|
ourWorksheetData.properties.gridProperties.columnCount,
|
||||||
|
);
|
||||||
|
return { worksheetId: ourWorksheetData.properties.sheetId, range: `${worksheet}!A1:${endCell}` };
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -317,7 +319,7 @@ class sheet {
|
|||||||
}
|
}
|
||||||
const code = searchParams.get('code');
|
const code = searchParams.get('code');
|
||||||
const { tokens } = await client.getToken({
|
const { tokens } = await client.getToken({
|
||||||
code: code,
|
code,
|
||||||
redirect_uri: redirectUri.toString(),
|
redirect_uri: redirectUri.toString(),
|
||||||
});
|
});
|
||||||
client.credentials = tokens;
|
client.credentials = tokens;
|
||||||
@@ -338,7 +340,7 @@ class sheet {
|
|||||||
listenPort = Number(redirectUri.port);
|
listenPort = Number(redirectUri.port);
|
||||||
}
|
}
|
||||||
//TODO: the server might not start correctly
|
//TODO: the server might not start correctly
|
||||||
server.listen(listenPort, () => {});
|
server.listen(listenPort);
|
||||||
const address = server.address();
|
const address = server.address();
|
||||||
if (typeof address !== 'string') {
|
if (typeof address !== 'string') {
|
||||||
redirectUri.port = String(address.port);
|
redirectUri.port = String(address.port);
|
||||||
@@ -353,7 +355,7 @@ class sheet {
|
|||||||
this.authServerTimeout = setTimeout(
|
this.authServerTimeout = setTimeout(
|
||||||
() => {
|
() => {
|
||||||
sheet.authUrl = null;
|
sheet.authUrl = null;
|
||||||
server.unref;
|
server.unref();
|
||||||
},
|
},
|
||||||
2 * 60 * 1000,
|
2 * 60 * 1000,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import { OSCSettings } from './core/OscSettings.type.js';
|
|||||||
import { Settings } from './core/Settings.type.js';
|
import { Settings } from './core/Settings.type.js';
|
||||||
import { UserFields } from './core/UserFields.type.js';
|
import { UserFields } from './core/UserFields.type.js';
|
||||||
import { ViewSettings } from './core/Views.type.js';
|
import { ViewSettings } from './core/Views.type.js';
|
||||||
import { GoogleSheet } from '../index.js';
|
import { GoogleSheet, HttpSettings } from '../index.js';
|
||||||
import { HttpSettings } from '../index.js';
|
|
||||||
|
|
||||||
export type DatabaseModel = {
|
export type DatabaseModel = {
|
||||||
rundown: OntimeRundown;
|
rundown: OntimeRundown;
|
||||||
|
|||||||
Reference in New Issue
Block a user