-
Notifications
You must be signed in to change notification settings - Fork 39
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
Uploading New Files #42
Comments
Hi @jaydenlo08, thanks for the kind feedback! Sorry about the greyed out menu, that was just some teasing meant to pressure me into implementing it quickly, and... it's still not completely there, but actually it now just needs a bit of UI support. Also, you're right to assume just modifying the URL would do the trick. It's literally just some gzipped JSON state, and here's the snippet you'd need to add a single scad file (adapted from fragment-state.ts; can just paste this in the JS debugger console and go check your new file in the file picker / include it from /playground.scad): async function compressString(input) {
return btoa(String.fromCharCode(...new Uint8Array(await new Response(new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(input));
controller.close();
}
}).pipeThrough(new CompressionStream('gzip'))).arrayBuffer())));
}
async function decompressString(compressedInput) {
return new TextDecoder().decode(await new Response(new ReadableStream({
start(controller) {
controller.enqueue(Uint8Array.from(atob(compressedInput), c => c.charCodeAt(0)));
controller.close();
}
}).pipeThrough(new DecompressionStream('gzip'))).arrayBuffer());
}
async function addFile(path, content) {
const state = JSON.parse(await decompressString(window.location.hash.substring(1)));
// console.log(JSON.stringify(state, null, 2)); // Put a breakpoint here if you wanna peek into the state
state.params.sources.push({ path, content });
window.history.pushState(state, '', '#' + await compressString(JSON.stringify(state)));
window.location.reload();
}
addFile("/include_me.scad", "echo(\"Hello, World!\");").then(() => console.log("File added!")); As to how the UI should look like to expose this functionality, suggestions are welcome! (there's also partial support for |
First of all thank you @ochafik for all your hard work. It's absolutely amazing and I love it.
The options for file management are greyed out, with no way to upload or create new files (or libraries).
I see that the current content appears to be saved as base64 in the URL (or encoded) which could potentially allow me to put a new file there but I'm slightly too stupid to do so...
Is this feature not implemented yet, or is it to do with persistent storage with browser?
The text was updated successfully, but these errors were encountered: