Skip to content

Commit

Permalink
pass params in post req
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Aug 30, 2024
1 parent 4781e0c commit 37102e3
Show file tree
Hide file tree
Showing 4 changed files with 212 additions and 104 deletions.
143 changes: 109 additions & 34 deletions subnet/deployment-generator/src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,12 @@ router.get("/", (req, res) => {
});

router.post("/submit", (req, res) => {
console.log(req.body)
tempFile=
`
#subnet config
NETWORK_NAME=localsubnet
NUM_MACHINE=1
NUM_SUBNET=3
# MAIN_IP=127.0.0.1
MAIN_IP=192.168.1.1
# PUBLIC_IP=9.9.9.9
RELAYER_MODE=full
# optional
# PUBLIC_IP
#parentchain config
PARENTNET=devnet
PARENTNET_WALLET_PK=0x1111111111111111111111111111111111111111111111111111111111111111
#optional
GRANDMASTER_PK=0x3333333333333333333333333333333333333333333333333333333333333333
OS=mac
# docker image versions, default to stable
# VERSION_SUBNET=feature-upgrade-validator
# VERSION_SUBNET=feature-upgrade-validator
# VERSION_BOOTNODE=v0.2.2
# VERSION_RELAYER
# VERSION_STATS
# VERSION_FRONTEND
`
temp='teststr'
valid = genGenEnv(req.body)
if (!valid){
res.render("submit", { message: "failed, please try again" })
return
}

fs.writeFileSync(path.join(__dirname, "gen.env"), tempFile, (err) => {
if (err) {
console.error(err);
Expand Down Expand Up @@ -95,4 +68,106 @@ function callExec(command) {
throw Error(error);
}
}
}
}

function genGenEnv(input){
console.log(input)

let os = ''
let content_os = ''
switch (input.osradio){
case 'os-radio-mac':
os = 'mac'
content_os += `\nMAIN_IP=127.0.0.1`
content_os += `\nNUM_MACHINE=1`
break
case 'os-radio-linux':
os = 'linux'
content_os += `\nMAIN_IP=${input["text-private-ip"]}`
if (input["text-public-ip"] != ''){
content_os += `\nPRIVATE_IP=${input["text-public-ip"]}`
}
if (input["text-num-machine"] != ''){
content_os += `\nNUM_MACHINE=${input["text-num-machine"]}`
} else {
content_os += `\nNUM_MACHINE=1`
}
break
}

let parentnet = ''
switch (input.pnradio){
case 'pn-radio-testnet':
parentnet = 'testnet'
break
case 'pn-radio-devnet':
parentnet = 'devnet'
break
case 'pn-radio-mainnet':
parentnet = 'mainnet'
break
}

let relayer_mode = ''
switch (input.rmradio){
case 'rm-radio-full':
relayer_mode = 'full'
break
case 'rm-radio-lite':
relayer_mode = 'lite'
break
}

let content_custom_key = ''
if (input["grandmaster-pk"] != ''){
content_custom_key += `\nGRANDMASTER_PK=${input["grandmaster-pk"]}`
}

let subnet_keys=[]
let idx = 1
while ('subnet-key'+idx.toString() in input){
key = 'subnet-key'+idx.toString()
subnet_keys.push(input[key])
idx++
}
if (subnet_keys.length > 0){
key_string = subnet_keys.join(',')
content_custom_key += `\nSUBNETS_PK=${key_string}`
}

let content_version = ''
if (input["customversion-subnet"] != ''){
content_version += `\nVERSION_SUBNET=${input["customversion-subnet"]}`
}
if (input["customversion-bootnode"] != ''){
content_version += `\nVERSION_BOOTNODE=${input["customversion-bootnode"]}`
}
if (input["customversion-relayer"] != ''){
content_version += `\nVERSION_RELAYER=${input["customversion-relayer"]}`
}
if (input["customversion-stats"] != ''){
content_version += `\nVERSION_STATS=${input["customversion-stats"]}`
}
if (input["customversion-frontend"] != ''){
content_version += `\nVERSION_FRONTEND=${input["customversion-frontend"]}`
}


content=`
NETWORK_NAME=${input["text-subnet-name"]}
NUM_MACHINE=${input["text-num-subnet"]}
OS=${os}
PARENTNET=${parentnet}
PARENTNET_WALLET_PK=${input["parentnet-wallet-pk"]}
RELAYER_MODE=${relayer_mode}
`
content+=content_os
content+='\n'
content+=content_custom_key
content+='\n'
content+=content_version

console.log(content)

return false
}
13 changes: 4 additions & 9 deletions subnet/deployment-generator/src/views/custom.css
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
.myForm {
#myForm {
margin-left: 200px;
/* margin-right: 200px; */
max-width: 1100px;
}

.test{
background-color: rgb(255, 165, 223);
}

/* body{
background-color: red;
} */

.content {
display: none;
background-color: #f0f0f0;
Expand All @@ -33,6 +25,9 @@
color:red
}

#incomplete-required-warning{
color:red
}

/* hover trick */
.info-container {
Expand Down
Loading

0 comments on commit 37102e3

Please sign in to comment.