mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2025-01-03 16:43:47 +01:00
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:
parent
56929c6af7
commit
e09ed8012c
@ -19,23 +19,23 @@ class MalyanControl extends React.Component {
|
|||||||
mounted: true
|
mounted: true
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount = async () => {
|
// componentDidMount = async () => {
|
||||||
const { ip } = this.props;
|
// const { ip } = this.props;
|
||||||
while (this.state.mounted) {
|
// while (this.state.mounted) {
|
||||||
const status = await getMalyanStatus(ip).catch(() => null);
|
// const status = await getMalyanStatus(ip).catch(() => null);
|
||||||
this.setState({ status });
|
// this.setState({ status });
|
||||||
await sleep(1000);
|
// await sleep(1000);
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
|
||||||
home = () => {
|
home = () => {
|
||||||
const { ip } = this.props;
|
const { ip } = this.props;
|
||||||
fetch(`http://${ip}/set?code=G28`, { method: 'GET' });
|
fetch(`http://${ip}/set?code=G28`, { method: 'GET', mode: 'no-cors' });
|
||||||
};
|
};
|
||||||
|
|
||||||
stop = () => {
|
stop = () => {
|
||||||
const { ip } = this.props;
|
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() {
|
componentWillUnmount() {
|
||||||
|
@ -152,10 +152,10 @@ export async function slice(target, name, mesh, settings, updateProgress) {
|
|||||||
steps = 1;
|
steps = 1;
|
||||||
break;
|
break;
|
||||||
case 'WIFI':
|
case 'WIFI':
|
||||||
if (settings.printer === 'doodle3d_printer') {
|
// if (settings.printer === 'doodle3d_printer') {
|
||||||
const { state } = await getMalyanStatus(settings.ip);
|
// const { state } = await getMalyanStatus(settings.ip);
|
||||||
if (state !== 'idle') throw { message: 'printer must be idle before starting a print', code: 1 };
|
// if (state !== 'idle') throw { message: 'printer must be idle before starting a print', code: 1 };
|
||||||
}
|
// }
|
||||||
steps = 2;
|
steps = 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -191,15 +191,25 @@ export async function slice(target, name, mesh, settings, updateProgress) {
|
|||||||
const file = new File([gcode], 'doodle.gcode', { type: 'plain/text' });
|
const file = new File([gcode], 'doodle.gcode', { type: 'plain/text' });
|
||||||
body.append('file', file);
|
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}/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({
|
updateProgress({
|
||||||
action: 'Uploading',
|
action: 'Uploading',
|
||||||
percentage: currentStep / steps + progress.loaded / progress.total / steps
|
percentage: currentStep / steps + progress.loaded / progress.total / steps
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await fetchProgress(`http://${settings.ip}/set?code=M566 ${name}.gcode`, { method: 'GET' });
|
clearInterval(interval);
|
||||||
await fetchProgress(`http://${settings.ip}/set?code=M565`, { method: 'GET' });
|
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 ++;
|
currentStep ++;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user