forked from apxtri/apxtri
add locastorage init for a wwws appnamme
This commit is contained in:
parent
9651b2b3d2
commit
152a7ac2b9
@ -3,9 +3,89 @@ const path = require("path");
|
|||||||
const dnsSync = require("dns-sync");
|
const dnsSync = require("dns-sync");
|
||||||
const mustache = require("mustache");
|
const mustache = require("mustache");
|
||||||
const readlineSync = require("readline-sync");
|
const readlineSync = require("readline-sync");
|
||||||
|
const Odmdb = require("./Odmdb.js");
|
||||||
const conf = require(`../../../conf.json`);
|
const conf = require(`../../../conf.json`);
|
||||||
const Wwws = {};
|
const Wwws = {};
|
||||||
|
|
||||||
|
Wwws.initlocaldata = (tribe, appname, profils,lg) => {
|
||||||
|
const fileparam = `../../${tribe}/objects/wwws/itm/${appname}.json`;
|
||||||
|
if (!fs.existsSync(fileparam)) {
|
||||||
|
return res
|
||||||
|
.status(404)
|
||||||
|
.json({ status: 404, ref: "Wwws", msg: "appdoesnotexist", data: {} });
|
||||||
|
}
|
||||||
|
const locals = fs.readJSONSync(fileparam);
|
||||||
|
const localstorage = {
|
||||||
|
headers: locals.headers,
|
||||||
|
req: {},
|
||||||
|
itm: {},
|
||||||
|
itms: {},
|
||||||
|
options: {},
|
||||||
|
tpl: {},
|
||||||
|
ref: {},
|
||||||
|
schema: {},
|
||||||
|
};
|
||||||
|
localstorage.headers.xlang=lg;
|
||||||
|
profils.forEach((p) => {
|
||||||
|
if (locals.profils[p]) {
|
||||||
|
if (locals.profils[p].req){
|
||||||
|
localstorage.req[p] = locals.profils[p].req;
|
||||||
|
}
|
||||||
|
if (locals.profils[p].ref){
|
||||||
|
Object.keys(locals.profils[p].ref).forEach(r=>{
|
||||||
|
const src= `../../${locals.profils[p].ref[r]}_${lg}.json`;
|
||||||
|
if (fs.existsSync(src)){
|
||||||
|
localstorage.ref[r]=fs.readJSONSync(src)
|
||||||
|
}else{
|
||||||
|
localstorage.ref[r]=`Check your ${fileparam} for ref in ${p} and ${r}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (locals.profils[p].options){
|
||||||
|
Object.keys(locals.profils[p].options).forEach(r=>{
|
||||||
|
const src= `../../${locals.profils[p].options[r]}_${lg}.json`;
|
||||||
|
if (fs.existsSync(src)){
|
||||||
|
localstorage.options[r]=fs.readJSONSync(src)
|
||||||
|
}else{
|
||||||
|
localstorage.options[r]=`Check your ${fileparam} for options in ${p} profil and ${r}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (locals.profils[p].tpl){
|
||||||
|
Object.keys(locals.profils[p].tpl).forEach(r=>{
|
||||||
|
let src= `../../${locals.profils[p].tpl[r]}`;
|
||||||
|
if (!fs.existsSync(src)){
|
||||||
|
src+=`_${lg}.mustache`
|
||||||
|
}
|
||||||
|
if (fs.existsSync(src)){
|
||||||
|
localstorage.tpl[r]=fs.readJSONSync(src)
|
||||||
|
}else{
|
||||||
|
localstorage.tpl[r]=`Check your ${fileparam} for template in ${p} profil and ${r}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (locals.profils[p].schema){
|
||||||
|
locals.profils[p].schema.forEach(objpath=>{
|
||||||
|
const name=path.basename(objpath)
|
||||||
|
const schema=Odmdb.Schema(`../../${objpath}`,false,lg)
|
||||||
|
if (schema.status==200){
|
||||||
|
localstorage.schema[name]=schema.data.schema
|
||||||
|
}else{
|
||||||
|
console.log(schema)
|
||||||
|
localstorage.schema[name]=`Check your ${fileparam} for schema in ${p} profil`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
ref: "Wwws",
|
||||||
|
msg: "initdbsuccess",
|
||||||
|
data: { localstorage },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/*Wwws.apxtriinstall = (paramconf) => {
|
/*Wwws.apxtriinstall = (paramconf) => {
|
||||||
if (fs.existsSync(`${conf.dirtown}/conf.json`)) {
|
if (fs.existsSync(`${conf.dirtown}/conf.json`)) {
|
||||||
console.log("You already have a conf on this town");
|
console.log("You already have a conf on this town");
|
||||||
|
@ -58,6 +58,7 @@ router.get("/schema/:tribe/:objectname", checkHeaders, isAuthenticated, (req, re
|
|||||||
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang)
|
const retschema = Odmdb.Schema(objectPathname, true, req.header.xlang)
|
||||||
res.status(retschema.status).json(retschema);
|
res.status(retschema.status).json(retschema);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} /adminapi/odmdb/options/:tribe/objects/option/:optionname - Get option list in header language
|
* @api {get} /adminapi/odmdb/options/:tribe/objects/option/:optionname - Get option list in header language
|
||||||
* @apiGroup Odmdb
|
* @apiGroup Odmdb
|
||||||
@ -266,30 +267,70 @@ router.put("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res)
|
|||||||
res.status(postitm.status).json(postitm);
|
res.status(postitm.status).json(postitm);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get(
|
/**
|
||||||
|
* @api {delete} /adminapi/odmdb/itm/:tribe/:objectname/:primaryid - item Delete
|
||||||
|
* @apiGroup Odmdb
|
||||||
|
* @apiName deleteItm
|
||||||
|
* @apiPermission none
|
||||||
|
* @apiDescription Delete an item (data) into a collection of objectname items. This will reindex all idx for this object, but this won't check if this item.apxid is not already use somewhere else. If you use this endpoint be sure that no one will use it, if not then a get request will answer not found. For data integrity is better to use a scpecifc endpoint per tribe to manage a bunch of objects.
|
||||||
|
* @apiParam {string} tribe adminapi or tribe name (smatchit), where object is store
|
||||||
|
* @apiParam {string} objectname Place where to create new item, schema and version are available in /objectname/conf.json
|
||||||
|
*
|
||||||
|
* @apiBody {Object} data must pass Checkjson.js with schema
|
||||||
|
*
|
||||||
|
* @apiSuccess {json} data idxprimary Value of idxprimary into objectname collection
|
||||||
|
* @apiSuccessExample {json} Success-Response:
|
||||||
|
* HTTP/1.1 200 OK
|
||||||
|
* {"status":200, "ref":"Odmdb", "msg":"cudsuccessfull", "data":{"itm":{}}}
|
||||||
|
*
|
||||||
|
* @apiError {json} schemanotfound The objectname schema is not found
|
||||||
|
* @apiError {json} pathnamedoesnotexist The objectname does not exist for the tribe
|
||||||
|
* @apiError {json} missingprimarykey Body data must have primarykey to be created
|
||||||
|
* @apiError {json} unconsistencyapxidx some Body data get unique key that already exist
|
||||||
|
* @apiError {json} checkjsonfalse The body data are not consistent with the schema
|
||||||
|
* @apiErrorExample {json}
|
||||||
|
* HTTP/1.1 404 Not Found
|
||||||
|
* {"status":404,"ref":"Odmdb","msg":"see nationchains/model/lg/Odmdb_xx.json","data":"object to render with msg"}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
router.put("/itm/:tribe/:objectname", checkHeaders, isAuthenticated, (req, res) => {
|
||||||
|
// Create an item of an object with no specificities
|
||||||
|
// if specificities then create a route / model that import odmdb
|
||||||
|
const objectPathname=`../../${req.params.tribe}/objects/${req.params.objectname}`;
|
||||||
|
const postitm=Odmdb.cud(objectPathname,"U",req.body,{xprofils:req.session.header.xprofils,xalias:req.session.header.xalias});
|
||||||
|
res.status(postitm.status).json(postitm);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {post} /adminapi/odmdb/searchitms/:tribe/:objectname - items Search
|
||||||
|
* @apiGroup Odmdb
|
||||||
|
* @apiName searchItm
|
||||||
|
* @apiPermission none
|
||||||
|
* @apiDescription Search in an object collection of items
|
||||||
|
* @apiParam {string} tribe adminapi or tribe name (smatchit), where object is store
|
||||||
|
* @apiParam {string} objectname object name where looking for
|
||||||
|
* @apiBody {array}} fields list of properties at least apxid propertie
|
||||||
|
* @apiBody {string} question a specific syntaxe to find quickly items by using index litteral text @TODO : create a query syntaxe...
|
||||||
|
*
|
||||||
|
* @apiSuccess {json}
|
||||||
|
* @apiSuccessExample {json} Success-Response:
|
||||||
|
* HTTP/1.1 200 OK
|
||||||
|
* {"status":200, "ref":"Odmdb", "msg":"searchresult", "data":{"itms":[{itm fields}]}}
|
||||||
|
* @apiError {json} objectdoesnotexist the obbject does not exist for the tribe
|
||||||
|
* @apiError {json} unconsistentquestion the question format is not relevant
|
||||||
|
* @apiErrorExample {json}
|
||||||
|
* HTTP/1.1 404 Not Found
|
||||||
|
* {"status":404,"ref":"Odmdb","msg":"templatestring Odmdb_xx.json","data":"object to render with msg"}
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
router.post(
|
||||||
"/searchitems/:objectname/:question",
|
"/searchitems/:objectname/:question",
|
||||||
checkHeaders,
|
checkHeaders,
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
/**
|
// voir comment sortir isAuthenticated poure autoriser l'acces au search sur des object plublic
|
||||||
*
|
res.status(200).json({status:200,ref:"Odmdb",msg:"TODO",data:{}})
|
||||||
*
|
|
||||||
*/
|
|
||||||
console.log(
|
|
||||||
"route referentials get all language" +
|
|
||||||
req.params.objectname +
|
|
||||||
"-" +
|
|
||||||
req.params.question
|
|
||||||
);
|
|
||||||
const getref = Referentials.getref(
|
|
||||||
true,
|
|
||||||
req.params.source,
|
|
||||||
req.params.idref,
|
|
||||||
req.session.header.xworkon,
|
|
||||||
req.session.header.xlang
|
|
||||||
);
|
|
||||||
// Return any status the data if any erreur return empty object
|
|
||||||
res.jsonp(getref.payload.data);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ const router = express.Router();
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias exist then return public key or not
|
* Alias exist then return public key or not
|
||||||
* @api {get} adminapi/pagans/alias/:alias - alias Get
|
* @api {get} /api/adminapi/pagans/alias/:alias - alias Get
|
||||||
* @apiName isalias
|
* @apiName isalias
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription If alias exist return its publickey
|
* @apiDescription If alias exist return its publickey
|
||||||
@ -44,7 +44,7 @@ router.get("/alias/:alias", (req, res) => {
|
|||||||
res.status(getalias.status).send(getalias);
|
res.status(getalias.status).send(getalias);
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* @api {get} adminapi/pagans/logout - pagan Logout
|
* @api {get} /api/adminapi/pagans/logout - pagan Logout
|
||||||
* @apiName Removetoken
|
* @apiName Removetoken
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription Remove server's token only the owner of the token (no one else can delete a token )
|
* @apiDescription Remove server's token only the owner of the token (no one else can delete a token )
|
||||||
@ -66,7 +66,7 @@ router.get("/logout", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
res.status(logout.status).json(logout);
|
res.status(logout.status).json(logout);
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* @api {get} adminapi/pagans/isauth - pagan isAuthenticated?
|
* @api {get} /api/adminapi/pagans/isauth - pagan isAuthenticated?
|
||||||
* @apiName isAuth
|
* @apiName isAuth
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription Check if pagan's token is still valid
|
* @apiDescription Check if pagan's token is still valid
|
||||||
@ -95,7 +95,7 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
// @a pi Body {object} schema:pagans <a href='/nationchains/schema/pagans.json' target='_blank'>/nationchains/schema/pagans.json</a>
|
// @a pi Body {object} schema:pagans <a href='/nationchains/schema/pagans.json' target='_blank'>/nationchains/schema/pagans.json</a>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} adminapi/pagans - pagan Post
|
* @api {post} /api/adminapi/pagans - pagan Post
|
||||||
* @apiName addpagan
|
* @apiName addpagan
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription
|
* @apiDescription
|
||||||
@ -192,7 +192,7 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* @api {delete} adminapi/pagans/alias/:alias - pagan Delete
|
* @api {delete} /api/adminapi/pagans/alias/:alias - pagan Delete
|
||||||
* @apiName deletepagan
|
* @apiName deletepagan
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription
|
* @apiDescription
|
||||||
@ -210,12 +210,12 @@ router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
if (log) console.log(delperson)
|
if (log) console.log(delperson)
|
||||||
res.status(delperson.status).json(delperson);
|
res.status(delperson.status).json(delperson);
|
||||||
|
|
||||||
if (log) console.log(`DELETE pagans adminapi/objects/pagans/${req.params.alias}.json`);
|
if (log) console.log(`DELETE pagans /api/adminapi/objects/pagans/${req.params.alias}.json`);
|
||||||
const result = Pagans.delete(req.params.alias, req.session.header);
|
const result = Pagans.delete(req.params.alias, req.session.header);
|
||||||
res.status(result.status).send(result);
|
res.status(result.status).send(result);
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* @api {delete} adminapi/pagans/person/:tribe/:alias - person Delete
|
* @api {delete} /api/adminapi/pagans/person/:tribe/:alias - person Delete
|
||||||
* @apiName deleteperson
|
* @apiName deleteperson
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription
|
* @apiDescription
|
||||||
@ -239,7 +239,7 @@ router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res)
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {get} adminapi/pagans/person/:alias - person Get
|
* @api {get} /api/adminapi/pagans/person/:alias - person Get
|
||||||
* @apiName getpersondata
|
* @apiName getpersondata
|
||||||
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
|
* @apiDescription Get person information from his alias for a xtribe (data and profils per apps)
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
@ -265,7 +265,7 @@ router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {put} adminapi/pagans/person/:tribe - person Put
|
* @api {put} /api/adminapi/pagans/person/:tribe - person Put
|
||||||
* @apiName updateperson
|
* @apiName updateperson
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription add or update a person = alias in tribe. xalias authenticated (in header) must have a profil with accessright into schema person to create a person.
|
* @apiDescription add or update a person = alias in tribe. xalias authenticated (in header) must have a profil with accessright into schema person to create a person.
|
||||||
@ -289,7 +289,7 @@ router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} adminapi/pagans/keyrecovery - recovery keys
|
* @api {post} /api/adminapi/pagans/keyrecovery - recovery keys
|
||||||
* @apiName recoveryKey
|
* @apiName recoveryKey
|
||||||
* @apiGroup Pagans
|
* @apiGroup Pagans
|
||||||
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register). Search can be request by email or by alias for a tribe. It is looking for in person.recoveryauth.email to send keys. One mail is sent by alias. So if n alias has the same recoveryaut.email then it will send n email.
|
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register). Search can be request by email or by alias for a tribe. It is looking for in person.recoveryauth.email to send keys. One mail is sent by alias. So if n alias has the same recoveryaut.email then it will send n email.
|
||||||
|
@ -16,4 +16,24 @@ router.get("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res)
|
|||||||
router.post("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res) => {
|
router.post("/conf/:tribeId/:website", checkHeaders, isAuthenticated, (req, res) => {
|
||||||
res.send(Wwws.create(req.params.tribeId));
|
res.send(Wwws.create(req.params.tribeId));
|
||||||
});
|
});
|
||||||
|
/**
|
||||||
|
* @api {get} /adminapi/wwws/localstorage/:tribe/:appname - Get app data model
|
||||||
|
* @apiGroup Odmdb
|
||||||
|
* @apiName getOption
|
||||||
|
* @apiDescription Get data from backend to custome app
|
||||||
|
*
|
||||||
|
* @apiParams {string} tribe (adminapi,smatchit,..) to looking for
|
||||||
|
* @apiParams {string} appname agregate a full data referential to store localy
|
||||||
|
* @apiSuccess {object} contain data model for a local web or mobile app in a PWA logical in the language of the header
|
||||||
|
* @apiSuccessExample {json} Success-Response:
|
||||||
|
* HTTP/1.1 200 OK
|
||||||
|
* {"status":200, "ref":"Odmdb", "msg":"datamodel", "data":{}
|
||||||
|
*/
|
||||||
|
router.get("/initlocaldb/:tribe/:appname", checkHeaders, isAuthenticated, (req, res) => {
|
||||||
|
console.log('pass localstorage')
|
||||||
|
const getlocal = Wwws.initlocaldata(req.params.tribe,req.params.appname,req.session.header.xprofils,req.session.header.xlang);
|
||||||
|
res.status(getlocal.status).json(getlocal)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user