mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-10 18:03:47 +00:00
8c740b7111
* add dependency adding dependency to parse the excel file in the node side * import file ability to import file - add extension - safeguard file type and size * user is able to upload json or excel * chore: extract logic into self contained function * associate model with version * test id generation * parse excel data * prevent UI crash on bad data * extract validation into self contained function * chore: add more tests for bad data * config: stop from opening browser on start * fix comma in sample db * handle corrupt files * error boundary around main components * jsdocs * increase id length * parse excel time string * feat: excel parsing * validate json db before import * chore: test event validator * feat: make function to clean convert strings * chore: test parser * chore: jsdocs * fix: bug on upload prevent bug where the component would prevent upload of same file twice
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
import axios from 'axios';
|
|
import { ontimeURL } from './apiConstants';
|
|
|
|
export const ontimePlaceholderInfo = {
|
|
networkInterfaces: [],
|
|
version: '',
|
|
serverPort: 4001,
|
|
oscInPort: '',
|
|
oscOutPort: '',
|
|
oscOutIP: '',
|
|
};
|
|
|
|
export const getInfo = async () => {
|
|
const res = await axios.get(ontimeURL + '/info');
|
|
return res.data;
|
|
};
|
|
|
|
export const postInfo = async (data) => {
|
|
const res = await axios.post(ontimeURL + '/info', data);
|
|
return res;
|
|
};
|
|
|
|
export const downloadEvents = async () => {
|
|
await axios({
|
|
url: ontimeURL + '/db',
|
|
method: 'GET',
|
|
responseType: 'blob', // important
|
|
}).then((response) => {
|
|
let headerLine = response.headers['Content-Disposition'];
|
|
let filename = 'events.json';
|
|
|
|
// try and get the filename from the response
|
|
if (headerLine != null) {
|
|
let startFileNameIndex = headerLine.indexOf('"') + 1;
|
|
let endFileNameIndex = headerLine.lastIndexOf('"');
|
|
filename = headerLine.substring(startFileNameIndex, endFileNameIndex);
|
|
}
|
|
|
|
const url = window.URL.createObjectURL(new Blob([response.data]));
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.setAttribute('download', filename);
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
});
|
|
};
|
|
|
|
export const uploadEvents = async (file) => {
|
|
const formData = new FormData();
|
|
formData.append('userFile', file); // appending file
|
|
await axios
|
|
.post(ontimeURL + '/db', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
})
|
|
.then((res) => console.log(res.data))
|
|
.catch((err) => console.error(err));
|
|
};
|
|
|
|
export const uploadEventsWithPath = async (filepath) => {
|
|
await axios.post(ontimeURL + '/dbpath', { path: filepath });
|
|
};
|