diff --git a/apps/client/src/common/api/ontimeApi.ts b/apps/client/src/common/api/ontimeApi.ts index 1cb33ea23..d73de7448 100644 --- a/apps/client/src/common/api/ontimeApi.ts +++ b/apps/client/src/common/api/ontimeApi.ts @@ -227,3 +227,25 @@ export async function getLatestVersion(): Promise { export async function postNew(initialData: Partial) { return axios.post(`${ontimeURL}/new`, initialData); } + +/** + * @description sheet Client File + * @return {Promise} + */ +export const uploadSheetClientFile = async ( + file: File +) => { + const formData = new FormData(); + formData.append('userFile', file); + + await axios + .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); +}; \ No newline at end of file diff --git a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx index 025bb1db4..2de43576a 100644 --- a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx +++ b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx @@ -10,6 +10,7 @@ import { ModalHeader, ModalOverlay, } from '@chakra-ui/react'; +import { uploadSheetClientFile } from '../../../common/api/ontimeApi'; interface SheetsModalProps { onClose: () => void; @@ -31,6 +32,8 @@ export default function SheetsModal(props: SheetsModalProps) { if (!selectedFile) { setFile(null); return; + } else { + uploadSheetClientFile(selectedFile) } setFile(selectedFile); }; @@ -64,7 +67,7 @@ export default function SheetsModal(props: SheetsModalProps) { />
Need to add some help here
- +
{file &&
We got a file
}
You are authenticated
diff --git a/apps/server/src/controllers/ontimeController.ts b/apps/server/src/controllers/ontimeController.ts index 089298663..7bb125647 100644 --- a/apps/server/src/controllers/ontimeController.ts +++ b/apps/server/src/controllers/ontimeController.ts @@ -415,18 +415,19 @@ export async function previewSheet(req, res) { * @returns parsed result */ export async function sheetClientFile(req, res) { - if (!req.file) { + if (!req.file.path) { res.status(400).send({ message: 'File not found' }); return; } try { - const clientSecret = JSON.parse(req.body.options); - await Sheet.saveClientSecrets(clientSecret); + const client = JSON.parse( fs.readFileSync(req.file.path as string, 'utf-8')); + await Sheet.saveClientSecrets(client); res.status(200).send('OK'); } catch (error) { res.status(500).send({ message: error.toString() }); } + fs.unlink(req.file.path, (err) => {if(err) (logger.error(LogOrigin.Server, err.message))}); } /** diff --git a/apps/server/src/routes/ontimeRouter.ts b/apps/server/src/routes/ontimeRouter.ts index 99d1c787f..439d46850 100644 --- a/apps/server/src/routes/ontimeRouter.ts +++ b/apps/server/src/routes/ontimeRouter.ts @@ -103,3 +103,6 @@ router.post('/osc-subscriptions', validateOscSubscription, postOscSubscriptions) // create route between controller and '/ontime/new' endpoint router.post('/new', projectSanitiser, postNew); + +// create route between controller and '/ontime/sheet-client' endpoint +router.post('/sheet-clientsecrect', uploadFile, sheetClientFile);