Skip to content
Snippets Groups Projects
Commit 8ee11205 authored by Evan Feenstra's avatar Evan Feenstra
Browse files

embed static files as go strings

parent 2fe232bc
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
This diff is collapsed.
var fs = require('fs');
async function run() {
var content = 'package ui\n\nvar files = map[string]string{\n'
var files = walk('.')
var skip = ['favicon.ico','builder.js']
await asyncForEach(files, async function(file){
var fileName = file.substring(2, file.length)
if(skip.includes(fileName)) return
var data = await readFile(file)
content += addContent(fileName, data)
})
content += '\n}\n'
fs.writeFile('../files.go',content,function(){
console.log('files.go created!')
})
}
function addContent(fileName, data) {
return '\t"'+fileName+'":`' +data +'`,\n'
}
function readFile(file) {
return new Promise(function(resolve,reject){
fs.readFile(file, {encoding: 'utf-8'}, function(err,data){
if (!err) {
resolve(data)
} else {
reject(err)
}
});
})
}
var walk = function(dir) {
var results = [];
var list = fs.readdirSync(dir);
list.forEach(function(file) {
file = dir + '/' + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* Recurse into a subdirectory */
results = results.concat(walk(file));
} else {
/* Is a file */
results.push(file);
}
});
return results;
}
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
run()
\ No newline at end of file
File moved
File moved
......@@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="ui/favicon.ico">
<title>Shimmer UI</title>
<link rel="stylesheet" href="ui/css/bulma-darkly.css">
<link rel="stylesheet" href="https://unpkg.com/bulmaswatch@0.7.5/darkly/bulmaswatch.min.css">
<link rel="stylesheet" href="ui/css/styles.css">
</head>
......@@ -69,7 +69,7 @@
<tr v-for="log in logs">
<td>{{ log.time }}</td>
<td>{{ log.source }}: {{ log.message }}</td>
<td>[<span :style="`color:${log.color};`">{{ log.label }}</span>]</td>
<td>[<span :style="'color:'+log.color+';'">{{ log.label }}</span>]</td>
</tr>
</tbody>
</table>
......@@ -119,7 +119,7 @@
<td v-if="selectedTxHash!==tx.hash">{{ tx.value }}</td>
<td>
<span v-if="selectedTxHash!==tx.hash">{{ tx.hash }}</span>
<pre v-if="selectedTxHash===tx.hash" :style="`width:calc(${windowWidth-2}px - 3rem);`">{{ JSON.stringify(tx,null,2) }}</pre>
<pre v-if="selectedTxHash===tx.hash" :style="'width:calc('+(windowWidth-2)+'px - 3rem);'">{{ JSON.stringify(tx,null,2) }}</pre>
</td>
</tr>
</tbody>
......@@ -138,7 +138,7 @@
</section>
<!-- <script src="https://unpkg.com/vue@2.5.9"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
<script src="https://unpkg.com/vue@2.6.10/dist/vue.min.js"></script>
<script src="https://unpkg.com/dayjs@1.8.15"></script>
<script src="https://unpkg.com/3d-force-graph"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
......
......@@ -48,11 +48,11 @@ Vue.component('force-graph', {
.graphData(this.makeGraph())
},
template: `<div style="height:100%;">
<div id="3d-graph"></div>
<div v-if="hoveredNode" class="hovered-node">
ID: {{hoveredNode.id}} &nbsp;&nbsp;
<span v-if="hoveredNode.address">Address: {{hoveredNode.address}}</span>
</div>
</div>`
template: '<div style="height:100%;">'+
'<div id="3d-graph"></div>'+
'<div v-if="hoveredNode" class="hovered-node">'+
'ID: {{hoveredNode.id}} &nbsp;&nbsp; '+
'<span v-if="hoveredNode.address">Address: {{hoveredNode.address}}</span>'+
'</div>'+
'</div>'
})
\ No newline at end of file
File moved
File moved
......@@ -43,11 +43,11 @@ new Vue({
},
footerContainerStyle() {
const size = Math.max(window.innerHeight-this.headerSize, 300)
return `height:calc(${size-1}px - 3.6rem);`
return 'height:calc('+(size-1 )+'px - 3.6rem);'
},
startSpam() {
console.log('start spam', this.tpsToSpam)
api.get(`spammer?cmd=start&tps=${this.tpsToSpam}`)
api.get('spammer?cmd=start&tps='+this.tpsToSpam+')')
},
stopSpam() {
console.log('stop spam')
......@@ -123,10 +123,10 @@ new Vue({
infoValues() {
const i = this.info
return i.id ? [
`${i.receivedTps} received / ${i.solidTps} new`,
i.receivedTps+' received / '+i.solidTps+ 'new',
i.id,
`${i.chosenNeighbors.length} chosen / ${i.acceptedNeighbors.length} accepted`,
`${i.knownPeers} total / ${i.neighborhood} neighborhood`,
i.chosenNeighbors.length+' chosen / '+i.acceptedNeighbors.length+' accepted',
i.knownPeers+' total / '+i.neighborhood+' neighborhood',
uptimeConverter(i.uptime)
] : Array(5).fill('...')
},
......
File moved
File moved
......@@ -2,6 +2,7 @@ package ui
import (
"net/http"
"strings"
"sync/atomic"
"time"
......@@ -18,6 +19,13 @@ import (
)
func configure(plugin *node.Plugin) {
//webapi.Server.Static("ui", "plugins/ui/src")
webapi.AddEndpoint("ui", func(c echo.Context) error {
return c.HTML(http.StatusOK, files["index.html"])
})
webapi.AddEndpoint("ui/**", staticFileServer)
webapi.AddEndpoint("ws", upgrader)
webapi.AddEndpoint("loghistory", func(c echo.Context) error {
return c.JSON(http.StatusOK, logHistory)
......@@ -48,9 +56,21 @@ func configure(plugin *node.Plugin) {
}))
}
func run(plugin *node.Plugin) {
func staticFileServer(c echo.Context) error {
url := c.Request().URL.String()
path := url[4:] // trim off "/ui/"
res := c.Response()
header := res.Header()
if strings.HasPrefix(path, "css") {
header.Set(echo.HeaderContentType, "text/css")
}
if strings.HasPrefix(path, "js") {
header.Set(echo.HeaderContentType, "application/javascript")
}
return c.String(http.StatusOK, files[path])
}
webapi.Server.Static("ui", "plugins/ui")
func run(plugin *node.Plugin) {
daemon.BackgroundWorker("UI Refresher", func() {
for {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment