publication-igid
Version:
Authorization gateway relying on an auth service for providing user editing interfaces
118 lines (103 loc) • 4.61 kB
JavaScript
//
const {GeneralDynamic} = require('copious-transitions')
const {MultiPathRelayClient} = require('message-relay-services')
const myStorageClass = null
//
class PublicationDynamic extends GeneralDynamic {
//
constructor() {
super(myStorageClass)
this.server_id = "test-only"
this.db = null
this.uploader_connections = false
}
/**
* fetch_elements
*
* @param {string} transition
* @param {object} transtionObj
* @returns pair - the first part are the elements to be sent
*/
async fetch_elements(transition,transtionObj) {
if ( G_publication_commands_trns.tagged(transition,'dynamic') ) {
if ( this.uploader_connections ) {
if ( this.path_list.indexOf(transtionObj.uploader_type) >= 0 ) {
if ( transtionObj.meta !== undefined ) { // supplies a persitence meta object (good_data)
// file_list, file_name, file_type
let meta = transtionObj.meta
transtionObj.file_list = []
//
let fname = meta.media.source.name
let ftype = meta.media.source.mtype
transtionObj.file_list.push({ "file_name" : fname, "file_type" : ftype })
//
fname = meta.media.poster.name
ftype = meta.media.poster.mtype
transtionObj.file_list.push({ "file_name" : fname, "file_type" : ftype })
//
transtionObj.file_type = meta.media.source.mtype
transtionObj.file_name = transtionObj.hash
transtionObj.server_id = this.server_id
}
// communicate to the actual uploader
try {
transtionObj.server_id = this.server_id
let save_token = transtionObj.token
delete transtionObj.token
// If successful, the primary transition data will be stored in the transition tables of the uploader
// The uploader will be ready for a secondary transition from the client (this waits until the uploader
// is ready before responding to the client)
if ( this.uploader_connections ) {
let response = await this.uploader_connections.set_on_path(transtionObj,transtionObj.uploader_type)
if ( response.OK === "true" ) {
let send_elements = response.elements // forwarding the send elements on behalf of the orininal requestor
send_elements.token = response.transition.token
transtionObj.token = save_token
return [send_elements,false]
}
}
} catch (e) {
throw e /// allow transition processing to catch it...
}
}
}
}
throw new Error("wrong kind of transition object or configuration")
}
/**
* initialize
*
* @param {object} db - a reference to the DB class instance
* @param {object} conf - the configuration object
*/
initialize(db,conf) {
//
this.db = db
this.class_conf = conf.dynamic_assets // This is the config file... Initialization takes is section off of the top conf
let cconf = this.class_conf
//console.log("publication dynamic !!!!!! ")
//console.dir(conf)
//
if ( typeof cconf.uploader_paths === "object" ) {
this.server_id = cconf.uploader_paths.server_id
this.path_list = cconf.uploader_paths.path_list
if ( cconf.create_uploader_connections_with_com_link ) {
this.uploader_connections = new MultiPathRelayClient({})
} else {
this.uploader_connections = new MultiPathRelayClient(cconf.uploader_paths)
}
}
}
seeking_endpoint_paths() {
return this.path_list
}
set_messenger(path,instance,conf) {
if ( !(this.uploader_connections) ) {
this.uploader_connections = instance
}
this.uploader_connections.add_relay_path(conf,{
"path" : path
})
}
}
module.exports = new PublicationDynamic()