From b9fb66069da92939206d4c25cc387749e1c72365 Mon Sep 17 00:00:00 2001 From: Arnas Udovic Date: Mon, 23 Jun 2025 09:15:58 +0300 Subject: [PATCH] index html page --- db.go | 15 +++++++++++++ main.go | 16 ++++++++++++- templates/index.tmpl | 53 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 templates/index.tmpl diff --git a/db.go b/db.go index 6d23618..33ca177 100644 --- a/db.go +++ b/db.go @@ -195,3 +195,18 @@ func getHostsTotal(db *sql.DB, since string, search string) (int, error) { return totali, nil } + +func getRejectedHostsTotal(db *sql.DB) (int, error) { + total := "0" + query := "SELECT count(url) FROM instances WHERE rejected = 1" + + row := db.QueryRow(query) + row.Scan(&total) + + totali, err := strconv.Atoi(total) + if err != nil { + return 0, err + } + + return totali, nil +} diff --git a/main.go b/main.go index 3572001..43aaa5e 100644 --- a/main.go +++ b/main.go @@ -145,9 +145,23 @@ func serve() { defer db.Close() r := gin.Default() + r.LoadHTMLGlob("templates/*") r.GET("/", func(c *gin.Context) { - c.String(200, "index") + filteredInstancesCount, err := getHostsTotal(db, "", "") + if err != nil { + panic(err) + } + + rejectedInstancesCount, err := getRejectedHostsTotal(db) + if err != nil { + panic(err) + } + + c.HTML(http.StatusOK, "index.tmpl", gin.H{ + "FilteredInstancesCount": filteredInstancesCount, + "RejectedInstancesCount": rejectedInstancesCount, + }) }) r.GET("/instances", func(c *gin.Context) { diff --git a/templates/index.tmpl b/templates/index.tmpl new file mode 100644 index 0000000..acd6aaf --- /dev/null +++ b/templates/index.tmpl @@ -0,0 +1,53 @@ + + + + Peertube instance index + + + +

Peertube instance index filter

+ +

By using global index of instances and auto-subscribing there are problem by removing from your instance following because it comes back after next sync.

+

This filter is middleware to collect removed instances and list global index without them

+ +

Source code is available on g.arns.lt/zordsdavini/peertube-instance-index-filter

+

Contact on Fediverse: @zordsdavini@s.arns.lt

+ + + + + + + + + + +
Filtered instances{{ .FilteredInstancesCount }}
Rejected instances{{ .RejectedInstancesCount }}
+ +

Commands

+ +

App can be called directly and do management in console. For now it is the only way.

+ + + +

Links

+ + +

Setup

+ +

Added docker files as example. See /docker folder.

+

./instances-joinpeertube.db is prepared datebase from instances.joinpeertube.org on 2025-06-20. It can be copied to ./instances.db to be used.

+ +

License

+ +

GPLv3

+ +