From bf631cfc0fb3d819076f2d72084535c9bb5e2dd9 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sun, 11 Nov 2018 16:18:21 -0800 Subject: Can ls and see hello.txt. --- extension/background.js | 51 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) (limited to 'extension') diff --git a/extension/background.js b/extension/background.js index aa10b37..09ecad9 100644 --- a/extension/background.js +++ b/extension/background.js @@ -1,15 +1,58 @@ const ws = new WebSocket("ws://localhost:8888"); +const ops = { + NONE: 0, + GETATTR: 1, + READDIR: 2 +}; +const unix = { + EPERM: 1, + ENOENT: 2, + ESRCH: 3, + EINTR: 4, + EIO: 5, + ENXIO: 6, + + // Unix file types + S_IFMT: 0170000, // type of file mask + S_IFIFO: 010000, // named pipe (fifo) + S_IFCHR: 020000, // character special + S_IFDIR: 040000, // directory + S_IFBLK: 060000, // block special + S_IFREG: 0100000, // regular + S_IFLNK: 0120000, // symbolic link + S_IFSOCK: 0140000, // socket +} + ws.onmessage = function(event) { const req = JSON.parse(event.data); + console.log('req', Object.entries(ops).find(([op, opcode]) => opcode === req.op)[0], req); let response; - if (req.op === "readdir") { + if (req.op === ops.READDIR) { + response = { + op: ops.READDIR, + entries: [".", "..", "hello.txt"] + }; + } else if (req.op === ops.GETATTR) { response = { - op: "readdir", - names: [".", "..", "hi.txt"] + op: ops.GETATTR, + st_mode: 0, + st_nlink: 0, + st_size: 0 }; - } + if (req.path === "/") { + response.st_mode = unix.S_IFDIR | 0755; + response.st_nlink = 3; + } else if (req.path === "/hello.txt") { + response.st_mode = unix.S_IFREG | 0444; + response.st_nlink = 1; + response.st_size = 10; // FIXME + } else { + response.error = unix.ENOENT; + } + } + console.log('response', Object.entries(ops).find(([op, opcode]) => opcode === response.op)[0], response); ws.send(JSON.stringify(response)); }; -- cgit v1.2.3