mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +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>) {
|
export async function postNew(initialData: Partial<ProjectData>) {
|
||||||
return axios.post(`${ontimeURL}/new`, initialData);
|
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,
|
ModalHeader,
|
||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
|
import { uploadSheetClientFile } from '../../../common/api/ontimeApi';
|
||||||
|
|
||||||
interface SheetsModalProps {
|
interface SheetsModalProps {
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -31,6 +32,8 @@ export default function SheetsModal(props: SheetsModalProps) {
|
|||||||
if (!selectedFile) {
|
if (!selectedFile) {
|
||||||
setFile(null);
|
setFile(null);
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
uploadSheetClientFile(selectedFile)
|
||||||
}
|
}
|
||||||
setFile(selectedFile);
|
setFile(selectedFile);
|
||||||
};
|
};
|
||||||
@@ -64,7 +67,7 @@ export default function SheetsModal(props: SheetsModalProps) {
|
|||||||
/>
|
/>
|
||||||
<div>Need to add some help here</div>
|
<div>Need to add some help here</div>
|
||||||
<div>
|
<div>
|
||||||
<Button onClick={handleClick}>Upload Token</Button>
|
<Button onClick={handleClick}>Upload Client Secrect</Button>
|
||||||
</div>
|
</div>
|
||||||
{file && <div>We got a file</div>}
|
{file && <div>We got a file</div>}
|
||||||
<div>You are authenticated</div>
|
<div>You are authenticated</div>
|
||||||
|
|||||||
@@ -415,18 +415,19 @@ export async function previewSheet(req, res) {
|
|||||||
* @returns parsed result
|
* @returns parsed result
|
||||||
*/
|
*/
|
||||||
export async function sheetClientFile(req, res) {
|
export async function sheetClientFile(req, res) {
|
||||||
if (!req.file) {
|
if (!req.file.path) {
|
||||||
res.status(400).send({ message: 'File not found' });
|
res.status(400).send({ message: 'File not found' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const clientSecret = JSON.parse(req.body.options);
|
const client = JSON.parse( fs.readFileSync(req.file.path as string, 'utf-8'));
|
||||||
await Sheet.saveClientSecrets(clientSecret);
|
await Sheet.saveClientSecrets(client);
|
||||||
res.status(200).send('OK');
|
res.status(200).send('OK');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).send({ message: error.toString() });
|
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
|
// create route between controller and '/ontime/new' endpoint
|
||||||
router.post('/new', projectSanitiser, postNew);
|
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