UNPKG

publication-igid

Version:

Authorization gateway relying on an auth service for providing user editing interfaces

196 lines (166 loc) 4.98 kB
const {MultiPathRelayClient} = require("categorical-handlers") // Code that takes the authorized path commands and forwards the operations to category handlers. // (See NW_app in copious-blog-entries) // ---- // Note the distinction between paid and free paths for publication commands // class CategoricalRelays { // constructor() { this.ready = false } // initialize(conf,db) { this.conf = conf this.setup_relays(conf) } /** * add_connection * @param {object} conf */ async add_connection(conf) { if ( this.msg_relay ) { this.msg_relay.add_relay_path(conf,conf) } } seeking_endpoint_paths() { return ["persistence", "paid-persistence" ] } async close_connection(conf) { this.msg_relay.closeAll() } /** * setup_relays * * @param {object} conf */ async setup_relays(conf) { let relayer = conf.relayer if ( relayer === undefined ) { relayer = {} } this.msg_relay = new MultiPathRelayClient(relayer) this.path_ucwids = false if ( conf._wrapper_key === undefined ) { this.await_ready() } else { const UCWID = require('ucwid') this.ucwid_factory = new UCWID({ "_wrapper_key" : conf._wrapper_key }) this.path_ucwids = { "persistence" : {}, "paid-persistence" : {} } for ( let path in conf._wrapper_keys ) { // plural let asset_wrapper = conf._wrapper_keys[path] for ( let a_type in asset_wrapper ) { this.path_ucwids[path][a_type] = new UCWID({ "_wrapper_key" : asset_wrapper[a_type] }) } } await this.await_ready() } } async await_ready() { try { await this.msg_relay.await_ready("persistence") this.ready = true } catch (e) { } } /** * get_entry * * @param {object} data * @returns object */ async get_entry(data) { if ( (this.messenger === false) || !(this.ready) ) return // ... do actions on behalf of the Renderer if ( data && data._id ) { let persistence_path = data._paid ? "paid-persistence" : "persistence" let resp = await this.messenger.get_on_path(data,persistence_path) if ( resp.status === "OK" ) { let output = JSON.parse(resp.data) if ( output.mime_type.indexOf("/json") > 0 ) { output = JSON.parse(output.string) } return output } } } // // // // // // // // // // /** * delete_entry * * @param {object} data * @returns void */ async delete_entry(data) { if ( (this.messenger === false) || !(this.ready) ) return // ... do actions on behalf of the Renderer if ( data && data._id ) { let persistence_path = data._paid ? "paid-persistence" : "persistence" let resp = await this.messenger.del_on_path(data,persistence_path) if ( resp.status === "OK" ) { console.log("deleted") } } } // // // // // // // // // // /** * publish_entry * * @param {object} data * @returns string */ async publish_entry(data) { // if ( (this.messenger === false) || !(this.ready) ) return // ... do actions on behalf of the Renderer if ( data && data._id ) { let persistence_path = data._paid ? "paid-persistence" : "persistence" let resp = await this.messenger.publication_on_path(data,persistence_path) if ( resp.status === "OK" ) { //add_to_manifest(resp.data) console.log("published") return resp._tracking } // } // } // // // // // // // // // // /** * unpublish_entry * * @param {object} data * @returns string */ async unpublish_entry(data) { // if ( (this.messenger === false) || !(this.ready) ) return // ... do actions on behalf of the Renderer if ( data && data._id ) { let persistence_path = data._paid ? "paid-persistence" : "persistence" let resp = await this.messenger.unpublish_on_path(data,persistence_path) if ( resp.status === "OK" ) { //add_to_manifest(resp.data) console.log("unpublish") return resp._tracking } // } // } delete(id,dont_remote) { return(false) } search_one(key) { return "OK" } update(info_obj) { return "OK" } create(info_obj) { return "OK" } } module.exports = CategoricalRelays