added viewing/clearing of url cache
This commit is contained in:
parent
94856b6f00
commit
50df6c2d83
2 changed files with 32 additions and 1 deletions
17
main.go
17
main.go
|
@ -134,6 +134,16 @@ func (web Web) watchUpdate(c *gin.Context) {
|
|||
c.Redirect(http.StatusSeeOther, fmt.Sprintf("/watch/%d", watch.ID))
|
||||
}
|
||||
|
||||
func (web Web) cacheView(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "cacheView", web.urlCache)
|
||||
}
|
||||
|
||||
func (web Web) cacheClear(c *gin.Context) {
|
||||
url := c.PostForm("url")
|
||||
delete(web.urlCache, url)
|
||||
c.Redirect(http.StatusSeeOther, "/cache/view")
|
||||
}
|
||||
|
||||
func passiveBot(bot *tgbotapi.BotAPI) {
|
||||
u := tgbotapi.NewUpdate(0)
|
||||
u.Timeout = 60
|
||||
|
@ -176,7 +186,7 @@ func main() {
|
|||
web := Web{
|
||||
//bot,
|
||||
db: db,
|
||||
urlCache: make(map[string]string, 5),
|
||||
urlCache: make(map[string]string, 2),
|
||||
}
|
||||
router := gin.Default()
|
||||
|
||||
|
@ -187,6 +197,8 @@ func main() {
|
|||
templates.AddFromFiles("watchCreate", "templates/base.html", "templates/watch/create.html")
|
||||
templates.AddFromFiles("watchView", "templates/base.html", "templates/watch/view.html")
|
||||
|
||||
templates.AddFromFiles("cacheView", "templates/base.html", "templates/cache/view.html")
|
||||
|
||||
templates.AddFromFiles("500", "templates/base.html", "templates/500.html")
|
||||
router.HTMLRender = templates
|
||||
|
||||
|
@ -198,5 +210,8 @@ func main() {
|
|||
router.POST("/watch/update", web.watchUpdate)
|
||||
router.POST("/watch/delete", web.deleteWatch)
|
||||
|
||||
router.GET("/cache/view", web.cacheView)
|
||||
router.POST("/cache/clear", web.cacheClear)
|
||||
|
||||
router.Run("0.0.0.0:8080")
|
||||
}
|
||||
|
|
16
templates/cache/view.html
vendored
Normal file
16
templates/cache/view.html
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
{{define "content"}}
|
||||
{{ range $url, $content := . }}
|
||||
<div class="card text-center">
|
||||
<div class="card-header">
|
||||
{{ $url }}
|
||||
<form action="/cache/clear" method="post">
|
||||
<input type="hidden" name="url" value="{{ $url }}">
|
||||
<input type="submit" class="btn btn-danger btn-sm" value="Clear">
|
||||
</form>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<code class="card-text">{{ $content }}</code>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{end}}
|
Loading…
Add table
Reference in a new issue