parent
17d6275d96
commit
acbcbc1d97
@ -0,0 +1,104 @@
|
|||||||
|
|
||||||
|
import { BaseFileSystem, ERRNO, Mode, AccessMode, OpenFlags } from "./webfuse/webfuse.js"
|
||||||
|
|
||||||
|
class FileSystem extends BaseFileSystem {
|
||||||
|
|
||||||
|
constructor(tokenProvider, stateListener, files) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.tokenProvider = tokenProvider;
|
||||||
|
this.stateListener = stateListener
|
||||||
|
this.files = new Map();
|
||||||
|
for(const file of files) {
|
||||||
|
this.files.set("/" + file.name, file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
access(path, mode) {
|
||||||
|
// we do not allow write or execute
|
||||||
|
if ((mode & AccessMode.W_OK) || (mode & AccessMode.X_OK)) {
|
||||||
|
return ERRNO.EACCES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((path = "/") || (this.files.has(path))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERRNO.ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
getattr(path) {
|
||||||
|
if (path == "/") {
|
||||||
|
return {
|
||||||
|
nlink: 2,
|
||||||
|
mode: Mode.DIR | 0o555
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (this.files.has(path)) {
|
||||||
|
const file = this.files.get(path);
|
||||||
|
const contents = file.contents();
|
||||||
|
return {
|
||||||
|
nlink: 1,
|
||||||
|
mode: Mode.REG | 0o444,
|
||||||
|
size: contents.length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERRNO.ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
readdir(path) {
|
||||||
|
if (path == "/") {
|
||||||
|
const list = [];
|
||||||
|
for(const file of this.files.values()) {
|
||||||
|
list.push(file.name);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ERRNO.ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
open(path, flags) {
|
||||||
|
if (this.files.has(path)) {
|
||||||
|
const accessMode = flags & OpenFlags.ACCESS_MODE;
|
||||||
|
if (accessMode == OpenFlags.RDONLY) {
|
||||||
|
return [0, 0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return [ERRNO.EPERM, 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [ERRNO.ENOENT, 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
read(path, size, offset, fd) {
|
||||||
|
if (this.files.has(path)) {
|
||||||
|
const file = this.files.get(path);
|
||||||
|
const contents = file.contents();
|
||||||
|
if (offset < contents.length) {
|
||||||
|
const available = contents.length - offset;
|
||||||
|
const length = (size < available) ? size : available;
|
||||||
|
const data = contents.slice(offset, offset + length);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ERRNO.EBADF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getcreds() {
|
||||||
|
const token = this.tokenProvider();
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
connectionstatechanged(state) {
|
||||||
|
this.stateListener(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { FileSystem }
|
@ -1,41 +0,0 @@
|
|||||||
|
|
||||||
import { BaseFileSystem, ERRNO, Mode } from "./webfuse/webfuse.js"
|
|
||||||
|
|
||||||
class StaticFileSystem extends BaseFileSystem {
|
|
||||||
|
|
||||||
constructor(files) {
|
|
||||||
super();
|
|
||||||
this.files = files;
|
|
||||||
}
|
|
||||||
|
|
||||||
getattr(path) {
|
|
||||||
console.log("getattr", path);
|
|
||||||
|
|
||||||
if (path == "/") {
|
|
||||||
return {
|
|
||||||
nlink: 2,
|
|
||||||
mode: Mode.DIR | 0o555
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (this.files.has(path)) {
|
|
||||||
const contents = this.files.get(path);
|
|
||||||
return {
|
|
||||||
nlink: 1,
|
|
||||||
mode: Mode.REG | 0o444,
|
|
||||||
size: contents.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ERRNO.ENOENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
readdir(path) {
|
|
||||||
if (path == "/") {
|
|
||||||
return ["foo", "bar"]
|
|
||||||
}
|
|
||||||
|
|
||||||
return ERRNO.ENOENT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { StaticFileSystem }
|
|
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
const OpenFlags = {
|
||||||
|
ACCESS_MODE: 0x03,
|
||||||
|
RDONLY : 0o00,
|
||||||
|
WRONLY : 0o01,
|
||||||
|
RDWR : 0o02,
|
||||||
|
|
||||||
|
APPEND : 0o00002000,
|
||||||
|
ASYNC : 0o00020000,
|
||||||
|
CLOEXEC : 0o02000000,
|
||||||
|
CREAT : 0o00000100,
|
||||||
|
DIRECT : 0o00040000,
|
||||||
|
DIRECTORY : 0o00200000,
|
||||||
|
DSYNC : 0o00010000,
|
||||||
|
EXCL : 0o00000200,
|
||||||
|
LARGEFILE : 0o00100000,
|
||||||
|
NOATIME : 0o01000000,
|
||||||
|
NOCTTY : 0o00000400,
|
||||||
|
NOFOLLOW : 0o00400000,
|
||||||
|
NONBLOCK : 0o00004000,
|
||||||
|
NDELAY : 0o00004000,
|
||||||
|
PATH : 0o10000000,
|
||||||
|
SYNC : 0o04010000,
|
||||||
|
TMPFILE : 0o20200000,
|
||||||
|
TRUNC : 0o00001000
|
||||||
|
};
|
||||||
|
|
||||||
|
export { OpenFlags }
|
@ -0,0 +1,28 @@
|
|||||||
|
html, body {
|
||||||
|
background-color: #c0c0c0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
background-color: black;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: inline-block;
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#stats {
|
||||||
|
display: inline-block;
|
||||||
|
text-align: right;
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 300px;
|
||||||
|
height: 300px;
|
||||||
|
}
|
Loading…
Reference in new issue