use fetch no-cors mode to make form posts to malyan

so we can upload from cross origin
because fetch has no progress we fake malyan upload progress by
updating 20kb every second

@companje
This commit is contained in:
casperlamboo 2018-01-25 12:12:47 +01:00
parent 56929c6af7
commit e09ed8012c
2 changed files with 27 additions and 17 deletions

View File

@ -19,23 +19,23 @@ class MalyanControl extends React.Component {
mounted: true
};
componentDidMount = async () => {
const { ip } = this.props;
while (this.state.mounted) {
const status = await getMalyanStatus(ip).catch(() => null);
this.setState({ status });
await sleep(1000);
}
};
// componentDidMount = async () => {
// const { ip } = this.props;
// while (this.state.mounted) {
// const status = await getMalyanStatus(ip).catch(() => null);
// this.setState({ status });
// await sleep(1000);
// }
// };
home = () => {
const { ip } = this.props;
fetch(`http://${ip}/set?code=G28`, { method: 'GET' });
fetch(`http://${ip}/set?code=G28`, { method: 'GET', mode: 'no-cors' });
};
stop = () => {
const { ip } = this.props;
fetch(`http://${ip}/set?cmd={P:X}`, { method: 'GET' });
fetch(`http://${ip}/set?cmd={P:X}`, { method: 'GET', mode: 'no-cors' });
};
componentWillUnmount() {

View File

@ -152,10 +152,10 @@ export async function slice(target, name, mesh, settings, updateProgress) {
steps = 1;
break;
case 'WIFI':
if (settings.printer === 'doodle3d_printer') {
const { state } = await getMalyanStatus(settings.ip);
if (state !== 'idle') throw { message: 'printer must be idle before starting a print', code: 1 };
}
// if (settings.printer === 'doodle3d_printer') {
// const { state } = await getMalyanStatus(settings.ip);
// if (state !== 'idle') throw { message: 'printer must be idle before starting a print', code: 1 };
// }
steps = 2;
break;
default:
@ -191,15 +191,25 @@ export async function slice(target, name, mesh, settings, updateProgress) {
const file = new File([gcode], 'doodle.gcode', { type: 'plain/text' });
body.append('file', file);
let loaded = 0;
const interval = setInterval(() => {
loaded += 15 * 1024;
updateProgress({
action: 'Uploading',
percentage: (currentStep + loaded / file.size) / steps
});
}, 1000);
// await fetchProgress(`http://${settings.ip}/set?code=M563 S4`, { method: 'GET' });
await fetchProgress(`http://${settings.ip}/upload`, { method: 'POST', body }, (progress) => {
await fetch(`http://${settings.ip}/upload`, { method: 'POST', body, mode: 'no-cors' }, (progress) => {
updateProgress({
action: 'Uploading',
percentage: currentStep / steps + progress.loaded / progress.total / steps
});
});
await fetchProgress(`http://${settings.ip}/set?code=M566 ${name}.gcode`, { method: 'GET' });
await fetchProgress(`http://${settings.ip}/set?code=M565`, { method: 'GET' });
clearInterval(interval);
await fetch(`http://${settings.ip}/set?code=M566 ${name}.gcode`, { method: 'GET', mode: 'no-cors' });
await fetch(`http://${settings.ip}/set?code=M565`, { method: 'GET', mode: 'no-cors' });
currentStep ++;
} else {