Add an HTML page for #status channel.
This commit is contained in:
parent
1fd64db523
commit
57425f0d48
|
@ -17,5 +17,7 @@ RUN apk add --no-cache ca-certificates bash
|
|||
COPY --from=builder /go/src/github.com/mandrigin/status-go-bots/pinger /usr/local/bin/
|
||||
COPY --from=builder /go/src/github.com/mandrigin/status-go-bots/chanreader /usr/local/bin/
|
||||
|
||||
VOLUME ["/tmp/sg_bots"]
|
||||
|
||||
# 30304 is used for Discovery v5
|
||||
EXPOSE 8080 8545 30303 30303/udp 30304/udp
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
<html>
|
||||
<!--
|
||||
ID string `json:"id"`
|
||||
From string `json:"from"`
|
||||
Text string `json:"text"`
|
||||
ChannelName string `json:"channel"`
|
||||
Timestamp int64 `json:"ts"`
|
||||
Raw string `json:"-"`
|
||||
|
||||
-->
|
||||
<style type="text/css">
|
||||
|
||||
html {
|
||||
font-family: PostGrotesk-Medium, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0px;
|
||||
background-color: #EEF2F5;
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: white;
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
.content {
|
||||
max-width: 600px;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
|
||||
.header {
|
||||
background-color: #648FCE;
|
||||
line-height: 5rem;
|
||||
}
|
||||
|
||||
.chat {
|
||||
width: 100%;
|
||||
border-collapse: separate;
|
||||
}
|
||||
.message {
|
||||
background-color: white;
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
margin: 10px 0px;
|
||||
}
|
||||
|
||||
.cell {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 0.7rem;
|
||||
opacity: 0.6;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.from {
|
||||
font-size: 0.8rem;
|
||||
color: #70808D;
|
||||
padding-bottom: 3px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="header">
|
||||
<h1>#status</h1>
|
||||
</div>
|
||||
<div class="chat">
|
||||
{{range .Messages}}
|
||||
<div class="message">
|
||||
<div class="cell from">{{ .From }}</div>
|
||||
<div class="cell text">{{ .Text }}</div>
|
||||
<div class="cell time">{{ .TimeString }}</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -2,7 +2,6 @@ package bots
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
)
|
||||
|
@ -86,7 +85,7 @@ func NodeConfig() (*params.NodeConfig, error) {
|
|||
}
|
||||
}`
|
||||
|
||||
cwd, _ := os.Getwd()
|
||||
cwd := "/tmp/sg_bots/node"
|
||||
|
||||
config := fmt.Sprintf(configFormat, cwd, cwd, cwd, cwd)
|
||||
return params.LoadNodeConfig(config)
|
||||
|
|
|
@ -9,6 +9,8 @@ import (
|
|||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -36,6 +38,11 @@ func NewStatusMessage(from, text, channel string) StatusMessage {
|
|||
}
|
||||
}
|
||||
|
||||
func (m StatusMessage) TimeString() string {
|
||||
t := time.Unix(m.Timestamp/1000, 0)
|
||||
return humanize.RelTime(t, time.Now(), "earlier", "later")
|
||||
}
|
||||
|
||||
func (m StatusMessage) ToPayload() string {
|
||||
payloadFormat := `{:message-id "%s", :group-id "%s", :content "%s", :username "%s", :type :public-group-message, :show? true, :clock-value 1, :requires-ack? false, :content-type "text/plain", :timestamp %d}`
|
||||
message := fmt.Sprintf(payloadFormat,
|
||||
|
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -30,11 +31,17 @@ func main() {
|
|||
log.Println("Node started, %v", node)
|
||||
|
||||
r := gin.Default()
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
r.LoadHTMLGlob("_assets/html/*")
|
||||
r.GET("/json", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"messages": messages.Messages(conf.Channel),
|
||||
})
|
||||
})
|
||||
r.GET("/html", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
"Messages": messages.Messages(conf.Channel),
|
||||
})
|
||||
})
|
||||
r.Run() // listen and serve on 0.0.0.0:8080
|
||||
|
||||
return nil
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/mandrigin/status-go-bots/bots"
|
||||
|
@ -19,7 +18,7 @@ type ByTimestamp []bots.StatusMessage
|
|||
|
||||
func (a ByTimestamp) Len() int { return len(a) }
|
||||
func (a ByTimestamp) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByTimestamp) Less(i, j int) bool { return a[i].Timestamp < a[j].Timestamp }
|
||||
func (a ByTimestamp) Less(i, j int) bool { return a[i].Timestamp > a[j].Timestamp }
|
||||
|
||||
type messagesStore struct {
|
||||
db *leveldb.DB
|
||||
|
@ -28,8 +27,7 @@ type messagesStore struct {
|
|||
}
|
||||
|
||||
func NewMessagesStore(maxCount int) *messagesStore {
|
||||
cwd, _ := os.Getwd()
|
||||
db, err := leveldb.OpenFile(cwd+"/messages_store", nil)
|
||||
db, err := leveldb.OpenFile("/tmp/sg_bots/sg_spectator/messages_store", nil)
|
||||
if err != nil {
|
||||
log.Fatal("can't open levelDB file. ERR: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue