Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This PR creates a method that uses fetch to grab the zip from the debug "dump" button #50

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}

.clone-btn {
margin-left: 10px;
}
36 changes: 33 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,34 @@ class App extends Component {
}
}

downloadPatternArchive = async (event, deviceId) => {
event.preventDefault()
await fetch(`./controllers/${deviceId}/dump`)
.then(async res => {
let filename = ''
for (const header of res.headers) {
if (header[1].includes('filename')) {
const dispositionHeader = header[1]
// ignoring warning for `_`
// eslint-disable-next-line no-unused-vars
const [_, rawFilename] = dispositionHeader.split('=')
// removing double quotes
filename = rawFilename.replace(/^"(.+(?="$))"$/, '$1')
}
}
const url = URL.createObjectURL(await res.blob())
const element = document.createElement("a");
element.setAttribute("href", url);
element.setAttribute("download", filename);
element.style.display = "none";
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
URL.revokeObjectURL(url);
})
.catch(err => console.error(err));
}


render() {
let cloneDialog = null;
Expand Down Expand Up @@ -337,9 +365,11 @@ class App extends Component {
const dName = d.name
return (
<li className="list-group-item" key={dName}>
<a className={"btn btn-secondary float-right " + (!this.state.showDevControls && "d-none")} href={"controllers/" + d.id + "/dump"} download>Dump</a>
<button className="btn btn-secondary float-right" onClick={(event)=>this.openCloneDialog(event, d.id)}>Clone</button>
<a className="btn btn-primary float-right" href={"http://" + d.address} target="_blank" rel="noopener noreferrer">Open</a>
<button className={"clone-btn btn btn-secondary float-right " + (!this.state.showDevControls && "d-none")}
onClick={async (event) => await this.downloadPatternArchive(event, d.id)}>
Dump</button>
<button className="clone-btn btn btn-secondary float-right" onClick={(event)=>this.openCloneDialog(event, d.id)}>Clone</button>
<a className="clone-btn btn btn-primary float-right" href={"http://" + d.address} target="_blank" rel="noopener noreferrer">Open</a>
<h5>{dName} v{d.ver} @ {d.address}</h5>
</li>
)
Expand Down