Skip to content

Instantly share code, notes, and snippets.

@mororor
Last active February 25, 2019 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mororor/586701aa70094c1a425d71b0465b4eef to your computer and use it in GitHub Desktop.
Save mororor/586701aa70094c1a425d71b0465b4eef to your computer and use it in GitHub Desktop.
authorizeWriter rewrite
async authorizeWriter (key, writerKey, structures) {
if (!structures) return this.authorizeWriter(key, writerKey, [key])
let library = await getLibrary(this.session)
let archive = await library.getArchive(key)
let results = []
for (let i of structures) {
let structure = archive.structures.get(i)
console.log(structure)
results.push(structure.authorizeWriter(writerKey))
}
return results
}
@Frando
Copy link

Frando commented Feb 25, 2019

console output:

{ ready: [AsyncFunction: ready],
  replicate: [Function: replicate],
  getState: [Function: getState],
  structure: [Function: structure],
  feeds: [Function: feeds],
  authorized: [Function: authorized],
  authorize: [AsyncFunction: authorize],
  storeInfo: [AsyncFunction: storeInfo],
  fetchInfo: [AsyncFunction: fetchInfo],
  watchInfo: [Function: watchInfo],
  api:
   { drive:
      Hyperdrive {
        _events: [Object: null prototype] {},
        _eventsCount: 0,
        _maxListeners: undefined,
        contentStorage: true,
        key:
         <Buffer 93 d6 a5 dd 33 d2 7f 1a 60 64 1a 46 67 bc 57 93 4c 47 6e 9e fd 02 a2 a5 e5 97 96 cc f8 3a 4b 1b>,
        discoveryKey:
         <Buffer b3 4c 02 3c 1d fc fd 97 22 06 f2 ad 42 91 5d d4 27 1a 19 7e 28 11 48 f8 03 3d 2e 62 49 7b ed 5b>,
        local:
         Hypercore(
           key: 93d6a5..1b
           discoveryKey: b34c02..5b
           opened: true
           writable: true
           length: 5
           byteLength: 310
           peers: 0
         ),
        localContent:
         Hypercore(
           key: e43e6d..dd
           discoveryKey: f10aa5..ba
           opened: true
           writable: true
           length: 4
           byteLength: 46015
           peers: 0
         ),
        sparse: false,
        feeds: [Array],
        contentFeeds: [Array],
        db: [HyperDB],
        _lock: [Function],
        localContentData: [RandomAccessFile] },
     asyncWriteStream: [Function: asyncWriteStream],
     watch: [Function: watch],
     history: [Function: history],
     ready: [Function: ret],
     readFile: [Function: ret],
     writeFile: [Function: ret],
     readdir: [Function: ret],
     mkdir: [Function: ret],
     stat: [Function: ret],
     authorize: [Function: ret],
     createWriteStream: [Function: bound ],
     createReadStream: [Function: bound ],
     replicate: [Function: bound ] },
  type: 'hyperdrive',
  key:
   '93d6a5dd33d27f1a60641a4667bc57934c476e9efd02a2a5e59796ccf83a4b1b',
  writable: true }
{ ready: [AsyncFunction: ready],
  structure: [Function: structure],
  replicate: [Function: replicate],
  feeds: [Function: feeds],
  getState: [Function: getState],
  api:
   { ready: [Function: ret],
     put: [Function: ret],
     get: [Function: ret] },
  type: 'hypergraph',
  key:
   '001a1fe0fe6733b437d6cfc4ed29ef915067fa3e6f811ee95f6e2f05bae3e2e3' }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment