feat: Add initial domain plugins
All checks were successful
Build Docker / Build Image (push) Successful in 31s
All checks were successful
Build Docker / Build Image (push) Successful in 31s
This commit is contained in:
parent
25fc3bbc27
commit
78eae529e5
Binary file not shown.
@ -665,9 +665,8 @@ def getxPub(account):
|
||||
|
||||
#endregion
|
||||
|
||||
def generateReport(account):
|
||||
def generateReport(account,format="{name},{expiry},{value},{maxBid}"):
|
||||
domains = getDomains(account)
|
||||
format = str('{name},{expiry},{value},{maxBid}')
|
||||
|
||||
lines = [format.replace("{","").replace("}","")]
|
||||
for domain in domains:
|
||||
@ -689,4 +688,7 @@ def generateReport(account):
|
||||
line = line.replace("{openHeight}",str(domain['height']))
|
||||
lines.append(line)
|
||||
|
||||
return lines
|
||||
return lines
|
||||
|
||||
def convertHNS(value: int):
|
||||
return value/1000000
|
21
main.py
21
main.py
@ -371,11 +371,30 @@ def manage(domain: str):
|
||||
else:
|
||||
finalize_time = "now"
|
||||
|
||||
plugins = "<div class='container-fluid'>"
|
||||
# Execute domain plugins
|
||||
plugin_links = os.listdir("plugins")
|
||||
for plugin in plugin_links:
|
||||
if os.path.isdir("plugins/" + plugin):
|
||||
module = importlib.import_module("plugins." + plugin + ".main")
|
||||
moduleFunctions = module.listFunctions()
|
||||
for moduleFunction in moduleFunctions:
|
||||
data = moduleFunctions[moduleFunction]
|
||||
if "type" in data:
|
||||
if data["type"] == "domain":
|
||||
# Run function
|
||||
print(data)
|
||||
functionOutput = module.runFunction(moduleFunction,{"domain":domain},account_module.check_account(request.cookies.get("account")))
|
||||
print(functionOutput)
|
||||
plugins += render.plugin_output(functionOutput,data['returns'])
|
||||
plugins += "</div>"
|
||||
|
||||
|
||||
return render_template("manage.html", account=account, sync=account_module.getNodeSync(),
|
||||
error=errorMessage, address=address,
|
||||
domain=domain,expiry=expiry, dns=dns,
|
||||
raw_dns=urllib.parse.quote(raw_dns),
|
||||
finalize_time=finalize_time)
|
||||
finalize_time=finalize_time,plugins=plugins)
|
||||
|
||||
|
||||
@app.route('/manage/<domain>/finalize')
|
||||
|
4
plugins/domain/domain.json
Normal file
4
plugins/domain/domain.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"name":"Domains Plugin",
|
||||
"description":"This is plugin for the domain page"
|
||||
}
|
48
plugins/domain/main.py
Normal file
48
plugins/domain/main.py
Normal file
@ -0,0 +1,48 @@
|
||||
import json
|
||||
import account
|
||||
|
||||
|
||||
functions = {
|
||||
"bids": {
|
||||
"name": "Bid info",
|
||||
"type": "domain",
|
||||
"description": "Check when the domain was last updated",
|
||||
"params": {
|
||||
"domain": {
|
||||
"name":"domain to check",
|
||||
"type":"domain"
|
||||
}
|
||||
},
|
||||
"returns": {
|
||||
"highest":
|
||||
{
|
||||
"name": "Highest bid",
|
||||
"type": "text"
|
||||
},
|
||||
"paid":
|
||||
{
|
||||
"name": "Amount paid in auction",
|
||||
"type": "text"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def listFunctions():
|
||||
return functions
|
||||
|
||||
def runFunction(function, params, authentication):
|
||||
if function == "bids":
|
||||
return bids(params['domain'], authentication)
|
||||
else:
|
||||
return "Function not found"
|
||||
|
||||
|
||||
def bids(domain, authentication):
|
||||
wallet = authentication.split(":")[0]
|
||||
data = account.getDomain(domain)
|
||||
value = str(account.convertHNS(data['info']['value'])) + " HNS"
|
||||
highest = str(account.convertHNS(data['info']['highest'])) + " HNS"
|
||||
|
||||
|
||||
return {"highest": highest,"paid":value}
|
25
render.py
25
render.py
@ -196,11 +196,30 @@ def plugin_functions(functions, pluginName):
|
||||
name = functions[function]['name']
|
||||
description = functions[function]['description']
|
||||
params = functions[function]['params']
|
||||
returns = functions[function]['returns']
|
||||
returnsRaw = functions[function]['returns']
|
||||
|
||||
returns = ""
|
||||
for output in returnsRaw:
|
||||
returns += f"{returnsRaw[output]['name']}, "
|
||||
|
||||
returns = returns.removesuffix(', ')
|
||||
|
||||
functionType = "manual"
|
||||
if "type" in functions[function]:
|
||||
functionType = functions[function]["type"]
|
||||
|
||||
|
||||
html += f'<div class="card" style="margin-top: 50px;">'
|
||||
html += f'<div class="card-body">'
|
||||
html += f'<h4 class="card-title">{name}</h4>'
|
||||
html += f'<h6 class="text-muted card-subtitle mb-2">{description}</h6>'
|
||||
html += f'<h6 class="text-muted card-subtitle mb-2">Function type: {functionType.capitalize()}</h6>'
|
||||
|
||||
if functionType != "manual":
|
||||
html += f'<p class="card-text">Returns: {returns}</p>'
|
||||
html += f'</div>'
|
||||
html += f'</div>'
|
||||
continue
|
||||
|
||||
# Form
|
||||
html += f'<form method="post" style="padding: 20px;" action="/plugin/{pluginName}/{function}">'
|
||||
@ -271,6 +290,4 @@ def plugin_output(outputs, returns):
|
||||
|
||||
|
||||
|
||||
return html
|
||||
|
||||
|
||||
return html
|
@ -68,7 +68,7 @@
|
||||
<h6 class="text-muted card-subtitle mb-2">Expires in {{expiry}} days</h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>{{plugins|safe}}
|
||||
<div class="container-fluid" style="margin-top: 50px;">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
|
Loading…
Reference in New Issue
Block a user