publication-igid
Version:
Authorization gateway relying on an auth service for providing user editing interfaces
93 lines (70 loc) • 2.55 kB
JavaScript
const { DBClass } = require('copious-transitions')
const {CategoricalRelays} = require('./cat_relays')
let g_persistence = false
function random_enough_dash_id() {
let dd = Math.random()*934593411
dd = Math.floor(dd)
return("Dash" + dd)
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
//
class PublicationDBClass extends DBClass {
//
constructor() {
//
g_persistence = new CategoricalRelays()
super(false,false,g_persistence,false)
}
// // //
async initialize(conf) {
//
let self = this
// when connected to services that create publications per user...
let asset_intake = (obj) => {
self.asset_intake(obj)
}
await super.initialize(conf)
//g_persistence.message_fowarding.subscribe('user-publication',{ "source" : "dashboad", "m_path" : "persistence" },asset_intake)
//
}
// // //
// // //
async fetch_user(fdata) { // G_users_trns.from_cache()
let udata = await this.fetch_user_from_key_value_store(fdata[G_users_trns.kv_store_key()])
if ( udata ) {
return(udata)
}
return(false)
}
//
all_keys(category) {
return(this.pdb.all_keys(category))
}
//
asset_intake(obj) { // This object has not been put into static store by the backend. the backned created the file and sent it.
let diff_key = G_publication_trns.primary_key()
let static_dash = 'publication+' + obj[diff_key]
//
let dash_obj = decodeURIComponent(obj.publication) //
try {
dash_obj = JSON.parse(dash_obj)
} catch(e) {
dash_obj = {}
}
dash_obj[diff_key] = obj[diff_key]
dash_obj.owner = obj[diff_key]
dash_obj._id = static_dash
dash_obj.which_publication = random_enough_dash_id()
//
let extension = {}
// avoid publication looping...
extension._tx_no_remote = true // tell local DB handler that this object has already been created elsewhere, so just keep a local copy
extension[diff_key] = obj[diff_key] // who it belongs to
G_publication_trns.update(extension) // get further refinement by custom data operators.'
// wrap the object in a carrier, in which the object is serialized with its mime-type for future transport..
this.put_static_store(static_dash,dash_obj,"application/json",extension) // store it ... means a local file copy... staticDB
}
}
//
//
module.exports = new PublicationDBClass()