mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-04 15:08:01 +00:00
handle client secret upload
This commit is contained in:
@@ -227,3 +227,25 @@ export async function getLatestVersion(): Promise<HasUpdate> {
|
||||
export async function postNew(initialData: Partial<ProjectData>) {
|
||||
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);
|
||||
};
|
||||
@@ -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) {
|
||||
/>
|
||||
<div>Need to add some help here</div>
|
||||
<div>
|
||||
<Button onClick={handleClick}>Upload Token</Button>
|
||||
<Button onClick={handleClick}>Upload Client Secrect</Button>
|
||||
</div>
|
||||
{file && <div>We got a file</div>}
|
||||
<div>You are authenticated</div>
|
||||
|
||||
@@ -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))});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user