aboutsummaryrefslogtreecommitdiffstats
path: root/extension
diff options
context:
space:
mode:
authorOmar Rizwan <omar.rizwan@gmail.com>2018-11-11 16:31:02 -0800
committerOmar Rizwan <omar.rizwan@gmail.com>2018-11-11 16:31:02 -0800
commit47d855c7309dfb86093fd4cd272935e3b24a6ee9 (patch)
treed5c15f3e0496e00bd9b550707745e30994427a8e /extension
parentbf631cfc0fb3d819076f2d72084535c9bb5e2dd9 (diff)
Tabs subfolder.
Diffstat (limited to 'extension')
-rw-r--r--extension/background.js42
-rw-r--r--extension/manifest.json2
2 files changed, 32 insertions, 12 deletions
diff --git a/extension/background.js b/extension/background.js
index 09ecad9..dd409dc 100644
--- a/extension/background.js
+++ b/extension/background.js
@@ -24,6 +24,32 @@ const unix = {
S_IFSOCK: 0140000, // socket
}
+function readdir(path) {
+ if (path === "/") {
+ return ["tabs"];
+
+ } else if (path === "/tabs") {
+ return ["hello.txt"];
+ }
+}
+
+function getattr(path) {
+ const response = {};
+ if (path === "/" || path === "/tabs") {
+ response.st_mode = unix.S_IFDIR | 0755;
+ response.st_nlink = 3;
+
+ } else if (path === "/tabs/hello.txt") {
+ response.st_mode = unix.S_IFREG | 0444;
+ response.st_nlink = 1;
+ response.st_size = 10; // FIXME
+
+ } else {
+ response.error = unix.ENOENT;
+ }
+ return response;
+}
+
ws.onmessage = function(event) {
const req = JSON.parse(event.data);
console.log('req', Object.entries(ops).find(([op, opcode]) => opcode === req.op)[0], req);
@@ -32,25 +58,17 @@ ws.onmessage = function(event) {
if (req.op === ops.READDIR) {
response = {
op: ops.READDIR,
- entries: [".", "..", "hello.txt"]
+ entries: [".", "..", ...readdir(req.path)]
};
+
} else if (req.op === ops.GETATTR) {
response = {
op: ops.GETATTR,
st_mode: 0,
st_nlink: 0,
- st_size: 0
+ st_size: 0,
+ ...getattr(req.path)
};
- 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);
diff --git a/extension/manifest.json b/extension/manifest.json
index 0049977..374f21d 100644
--- a/extension/manifest.json
+++ b/extension/manifest.json
@@ -5,6 +5,8 @@
"description": "Connects to ChromeFS filesystem",
"version": "1.0",
+ "permissions": ["tabs"],
+
"background": {
"scripts": ["background.js"],
"persistent": true