diff --git a/apps/client/src/common/api/ontimeApi.ts b/apps/client/src/common/api/ontimeApi.ts index 816d27808..fbc8cec2c 100644 --- a/apps/client/src/common/api/ontimeApi.ts +++ b/apps/client/src/common/api/ontimeApi.ts @@ -239,10 +239,7 @@ export const uploadSheetClientFile = async (file: File) => { .post(`${ontimeURL}/sheet-clientsecrect`, formData, { headers: { 'Content-Type': 'multipart/form-data', - }, - onUploadProgress: (progressEvent) => { - const complete = progressEvent?.total ? Math.round((progressEvent.loaded * 100) / progressEvent.total) : 0; - }, + } }) .then((response) => response.data.id); }; diff --git a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx index 1239f3dfe..60f7a0006 100644 --- a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx +++ b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx @@ -11,21 +11,21 @@ import { ModalOverlay, } from '@chakra-ui/react'; import { useQueryClient } from '@tanstack/react-query'; +import { OntimeRundown, ProjectData, UserFields } from 'ontime-types'; + +import { PROJECT_DATA, RUNDOWN, USERFIELDS } from '../../../common/api/apiConstants'; +import { maybeAxiosError } from '../../../common/api/apiUtils'; import { getSheetsAuthStatus, getSheetsAuthUrl, - postPreviewSheet, - uploadSheetClientFile, patchData, + postPreviewSheet, postPushSheet, + uploadSheetClientFile, } from '../../../common/api/ontimeApi'; -import { OntimeRundown, ProjectData, UserFields } from 'ontime-types'; - -import PreviewExcel from '../upload-modal/preview/PreviewExcel'; import { projectDataPlaceholder } from '../../../common/models/ProjectData'; import { userFieldsPlaceholder } from '../../../common/models/UserFields'; -import { PROJECT_DATA, RUNDOWN, USERFIELDS } from '../../../common/api/apiConstants'; -import { maybeAxiosError } from '../../../common/api/apiUtils'; +import PreviewExcel from '../upload-modal/preview/PreviewExcel'; interface SheetsModalProps { onClose: () => void; @@ -35,7 +35,6 @@ interface SheetsModalProps { export default function SheetsModal(props: SheetsModalProps) { const { isOpen, onClose } = props; const fileInputRef = useRef(null); - const [file, setFile] = useState(null); const [authState, setAuthState] = useState(true); const [rundown, setRundown] = useState(null); @@ -59,12 +58,10 @@ export default function SheetsModal(props: SheetsModalProps) { const handleFile = (event: ChangeEvent) => { const selectedFile = event?.target?.files?.[0]; if (!selectedFile) { - setFile(null); return; } else { uploadSheetClientFile(selectedFile); } - setFile(selectedFile); }; //TODO: do smoething better here @@ -75,8 +72,7 @@ export default function SheetsModal(props: SheetsModalProps) { const handleAuthenticate = () => { getSheetsAuthUrl().then((data) => { console.log(data); - if (data == 'bad') { - } else { + if (data != 'bad') { window.open(data, '_blank', 'noreferrer'); } }); diff --git a/apps/server/src/controllers/ontimeController.ts b/apps/server/src/controllers/ontimeController.ts index ffdc187b2..6c9026b6c 100644 --- a/apps/server/src/controllers/ontimeController.ts +++ b/apps/server/src/controllers/ontimeController.ts @@ -413,7 +413,7 @@ export async function previewSheet(req, res) { */ export async function pushSheet(req, res) { try { - const data = await Sheet.push(req.body.sheetid, req.body.worksheet); + await Sheet.push(req.body.sheetid, req.body.worksheet); res.status(200).send('ok'); } catch (error) { res.status(500).send({ message: error.toString() }); diff --git a/apps/server/src/utils/parser.ts b/apps/server/src/utils/parser.ts index 75f3f1574..057a2aab6 100644 --- a/apps/server/src/utils/parser.ts +++ b/apps/server/src/utils/parser.ts @@ -46,8 +46,8 @@ export const JSON_MIME = 'application/json'; * @returns {object} - parsed object */ export const parseExcel = (excelData: unknown[][], options?: Partial) => { - let projectMetadata = {}; - let rundownMetadata = {}; + const projectMetadata = {}; + const rundownMetadata = {}; const importMap: ExcelImportMap = { ...defaultExcelImportMap, ...options }; const projectData: Partial = { title: '', diff --git a/apps/server/src/utils/sheetsAuth.ts b/apps/server/src/utils/sheetsAuth.ts index 9f01742e3..a9e6062f4 100644 --- a/apps/server/src/utils/sheetsAuth.ts +++ b/apps/server/src/utils/sheetsAuth.ts @@ -6,7 +6,7 @@ import { URL } from 'url'; import { logger } from '../classes/Logger.js'; import { getAppDataPath } from '../setup.js'; import { DatabaseModel, LogOrigin, OntimeRundownEntry, isOntimeEvent } from 'ontime-types'; -import { ExcelImportOptions, isExcelImportMap, defaultExcelImportMap, millisToString } from 'ontime-utils'; +import { isExcelImportMap, defaultExcelImportMap, millisToString } from 'ontime-utils'; import { parseExcel } from './parser.js'; import { parseProject, parseRundown, parseUserFields } from './parserFunctions.js'; import { ensureDirectory } from './fileManagement.js'; @@ -81,7 +81,8 @@ class sheet { range: worksheet + '!A:Z', //FIXME: this is an abitrary range }); if (rq.status === 200) { - const { projectMetadata, rundownMetadata } = parseExcel(rq.data.values, options); + //TODO: projectMetadata + const { rundownMetadata } = parseExcel(rq.data.values, options); const rundown = DataProvider.getRundown(); const titleRow = Object.values(rundownMetadata)[0]['row']; @@ -184,9 +185,9 @@ class sheet { /** * saves Object to appdata path as client_secret.json - * @param {Object} secrets + * @param {} secrets */ - public async saveClientSecrets(secrets: Object) { + public async saveClientSecrets(secrets) { ensureDirectory(this.sheetsFolder); logger.info(LogOrigin.Server, 'Sheets: got new client_secret'); //TODO: test that this is actualy a client file? @@ -236,7 +237,9 @@ class sheet { if (response?.credentials) { return true; } - } catch (_) {} + } catch (_) { + logger.info(LogOrigin.Server, 'Sheets token expired'); + } return false; } @@ -250,12 +253,13 @@ class sheet { metadata, titleCol: number, ): sheets_v4.Schema$Request { - let r: sheets_v4.Schema$CellData[] = []; - const tmp = Object.entries(metadata) - .filter(([key, value]) => value !== undefined) - .sort(([aKey, a], [bKey, b]) => a['col'] - b['col']); - tmp.forEach(([key, value], index, arr) => { + const r: sheets_v4.Schema$CellData[] = []; + const tmp = Object.entries(metadata) + .filter(([_, value]) => value !== undefined) + .sort(([_a, a], [_b, b]) => a['col'] - b['col']); + + tmp.forEach(([_, value], index, arr) => { if (index != 0) { if (arr[index - 1][1]['col'] + 1 < value['col']) { arr.splice(index, 0, ['blank', { col: arr[index - 1][1]['col'] + 1 }]); @@ -263,7 +267,7 @@ class sheet { } }); - tmp.forEach(([key, value]) => { + tmp.forEach(([key, _]) => { if (isOntimeEvent(event)) { if (key === 'blank') { r.push({}); @@ -430,29 +434,4 @@ your keyfile, and add a 'redirect_uris' section. For example: ] `; -function hexToRgb(hex: string) { - if (hex === '' || hex[0] !== '#') { - return { red: 1, green: 1, blue: 1 }; - } - const bigint = parseInt(hex.slice(1), 16); - const r = ((bigint >> 16) & 255) / 255; - const g = ((bigint >> 8) & 255) / 255; - const b = (bigint & 255) / 255; - return { red: r, green: g, blue: b }; -} - -type sheetPos = { - row: number; - col: number; -}; - -function isEqualPartial(a: T, b: Partial) { - for (const [key, value] of Object.entries(a)) { - if (b[key] !== undefined && value !== b[key]) { - return false; - } - } - return true; -} - export const Sheet = new sheet();