index html page
This commit is contained in:
parent
91977c20f8
commit
b9fb66069d
3 changed files with 83 additions and 1 deletions
15
db.go
15
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
|
||||
}
|
||||
|
|
16
main.go
16
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) {
|
||||
|
|
53
templates/index.tmpl
Normal file
53
templates/index.tmpl
Normal file
|
@ -0,0 +1,53 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Peertube instance index</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Peertube instance index filter</h1>
|
||||
|
||||
<p>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.</p>
|
||||
<p>This filter is middleware to collect removed instances and list global index without them</p>
|
||||
|
||||
<p>Source code is available on <a href="https://g.arns.lt/zordsdavini/peertube-instance-index-filter">g.arns.lt/zordsdavini/peertube-instance-index-filter</a></p>
|
||||
<p>Contact on Fediverse: <a href="https://s.arns.lt/@zordsdavini">@zordsdavini@s.arns.lt</a></p>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>Filtered instances</th>
|
||||
<td>{{ .FilteredInstancesCount }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Rejected instances</th>
|
||||
<td>{{ .RejectedInstancesCount }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>Commands</h2>
|
||||
|
||||
<p>App can be called directly and do management in console. For now it is the only way.</p>
|
||||
|
||||
<ul>
|
||||
<li><code>peertube-instance-index-filter -command index -url https://instances.joinpeertube.org/api/v1/instances/hosts -instance-url https://instances.joinpeertube.org/api/v1/instances</code> - add url to index of hosts. Later it will be used to collect instances</li>
|
||||
<li><code>peertube-instance-index-filter -command collect</code> - collect instances from index of hosts urls</li>
|
||||
<li><code>peertube-instance-index-filter -command reject -host www.example.com</code> - reject instance from index to exclude it from global index</li>
|
||||
</ul>
|
||||
|
||||
<h2>Links</h2>
|
||||
<ul>
|
||||
<li><a href="/">/</a> - some html information about this filter (this page)</li>
|
||||
<li><a href="/instances">/instances</a> - list of instances in json format with more information. Supports pagination, filter by instance creation date: <code>?start=3&count=100&since=2024-01-10</code>. Sorted by descending creation date. Also it can be used as search by host: <code>?search=www.example.com</code></li>
|
||||
<li><a href="/instances/hosts">/instances/hosts</a> - list of hosts in json format. Supports pagination, filter by instance creation date: <code>?start=3&count=100&since=2024-01-10</code>. Sorted by descending creation date. <b>This should be given to Peertube instance</b></li>
|
||||
</ul>
|
||||
|
||||
<h2>Setup</h2>
|
||||
|
||||
<p>Added docker files as example. See <code>/docker</code> folder.</p>
|
||||
<p><code>./instances-joinpeertube.db</code> is prepared datebase from <em>instances.joinpeertube.org</em> on 2025-06-20. It can be copied to <code>./instances.db</code> to be used.</p>
|
||||
|
||||
<h2>License</h2>
|
||||
|
||||
<p>GPLv3</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue