1
0
mirror of https://github.com/falk-werner/webfuse synced 2026-10-23 05:08:36 +00:00

add javascript example

This commit is contained in:
Falk Werner
2023-02-05 11:37:19 +01:00
parent 17d6275d96
commit acbcbc1d97
10 changed files with 244 additions and 70 deletions

View File

@@ -1,19 +1,40 @@
import { Webfuse } from "./webfuse/webfuse.js";
import { StaticFileSystem } from "./static_filesystem.js";
import { FileSystem } from "./filesystem.js";
function encode(value) {
const encoder = new TextEncoder('utf-8');
return encoder.encode(value);
}
function get_contents() {
const contentTextArea = document.querySelector("#contents");
const contents = contentTextArea.value;
return encode(contents);
}
function get_token() {
const tokenTextfield = document.querySelector('#token');
const token = tokenTextfield.value;
return token;
}
function update_state(state) {
const stateTextField = document.querySelector("#state");
stateTextField.textContent = (state == "connected") ? "connected" : "disconnected";
}
let webfuse = null;
const filesystem = new StaticFileSystem(new Map([
["/foo", "foo"],
["/bar", "foo"]
]));
const filesystem = new FileSystem(get_token, update_state, [
{name: "README.md", contents: get_contents }
]);
function onConnectButtonClicked() {
if (webfuse) { webfuse.close(); }
const urlTextfield = document.querySelector('#url');
const url = urlTextfield.value;
console.log(url);
webfuse = new Webfuse(url, filesystem);
}