fs 0.0.1
[henge/kiak.git] / src / strapp.js
index 9ec9d09..aefbc1b 100644 (file)
@@ -6,8 +6,17 @@
 * @copyright August 2017 - Ken Grimes, Jordan Lavatai
 * @summmary  Bootstrapper for the strapp.io mechanism
 */
+import LocalForage from "localforage"
 
 const StrappFile = (() => {
+  const localforage = LocalForage.createInstance({
+    driver: [LocalForage.LOCALSTORAGE,
+             LocalForage.INDEXEDDB,
+             LocalForage.WEBSQL],
+    name: 'strapp',
+    version: 0.1,
+    storeName: 'strapp'
+  })
   const authorize = (pubKey, mode, stat) => {
     let allowed
     if (pubKey === stat.owner)
@@ -50,6 +59,15 @@ const StrappFile = (() => {
     static PermissionDenied() {
       return new Promise((resolve, reject) => reject('Permission denied'))
     }
+    static get(path) {
+      return localforage.getItem(path)
+    }
+    static set(path, data) {
+      return localforage.setItem(path, data)
+    }
+    static delete(path) {
+      return localforage.removeItem(path)
+    }
     HEAD(opt) {
       if (authorize(opt.pubKey, 'r', this.stat))
         return new Promise((resolve, reject) => resolve(''))
@@ -86,13 +104,46 @@ const StrappFile = (() => {
     }
   }
   StrappFile.defaults = {
-    type: 'mime/type',
-    perm: 0,
-    owner: 'thisOwnerPubKey',
-    group: 'groupname',
-    changed: 'time',
-    created: 'time',
-    accessed: 'time - not saved'
+    stat: {
+      type: 'mime/type',
+      perm: 0,
+      owner: 'thisOwnerPubKey',
+      group: 'groupname',
+      changed: 'time',
+      created: 'time',
+      accessed: 'time - not saved'
+    }
   }
   return StrappFile
 })()
+
+const StrappPeerConnection = (() => {
+  class StrappPeerConnection extends StrappFile {
+    GET(opts) {
+      //get metadata (held in filesystem), with owner, usage info, etc
+      //if unauthed, send message down socket
+    }
+    PUT(opts) {
+      //create w/ sdp, register callback (or pipe), set owner
+    }
+    POST(opts) {
+      //send msg
+    }
+    CONNECT(opts) {
+      //send routing message down socket
+      //POST(opts.routemessage)
+    }
+  }
+  return StrappPeerConnection
+})()
+
+const StrappDirectory = (() => {
+  class StrappDirectory extends StrappFile {
+  }
+  return StrappDirectory
+})()
+
+
+
+export default StrappFile
+export { StrappPeerConnection, StrappDirectory }