add locastorage init for a wwws appnamme

This commit is contained in:
2024-04-18 11:35:29 +02:00
parent 9651b2b3d2
commit 152a7ac2b9
4 changed files with 172 additions and 31 deletions

View File

@@ -3,9 +3,89 @@ const path = require("path");
const dnsSync = require("dns-sync");
const mustache = require("mustache");
const readlineSync = require("readline-sync");
const Odmdb = require("./Odmdb.js");
const conf = require(`../../../conf.json`);
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) => {
if (fs.existsSync(`${conf.dirtown}/conf.json`)) {
console.log("You already have a conf on this town");
@@ -49,7 +129,7 @@ const Wwws = {};
Wwws.create = (paramnginx) => {
/**
* Create an nginx conf to make available a spaceweb for a tribe /www/appname/
*
*
*/
const res = {
status: 200,