Compare commits
2 commits
91977c20f8
...
f3f3a6c216
Author | SHA1 | Date | |
---|---|---|---|
|
f3f3a6c216 | ||
|
b9fb66069d |
7 changed files with 142 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
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
FROM golang:1.24
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
ADD peertube-instance-index-filter ./
|
||||
|
||||
ADD instances.db ./
|
||||
|
||||
RUN go mod download && go mod verify
|
||||
|
||||
RUN go build -v -o /usr/local/bin/peertube-instance-index-filter ./...
|
||||
|
||||
ENV GIN_MODE release
|
||||
|
||||
RUN set -ex; \
|
||||
echo '0 1 * * * /usr/local/bin/peertube-instance-index-filter -command collect' > /var/spool/cron/crontabs/root
|
||||
|
||||
CMD ["peertube-instance-index-filter"]
|
15
docker/Makefile
Normal file
15
docker/Makefile
Normal file
|
@ -0,0 +1,15 @@
|
|||
### help: Show help message (default target)
|
||||
.PHONY: help
|
||||
help:
|
||||
@printf "%s\n\n" "make: List of possible targets:"
|
||||
@grep '^### .*:' $(lastword $(MAKEFILE_LIST)) | sed 's/^### \([^:]*\): \(.*\)/\1:\t\2/' | column -ts "$$(printf '\t')"
|
||||
|
||||
### add-index: Add index host. Arguments: url and instance-url (optional)
|
||||
.PHONY: add-index
|
||||
add-index:
|
||||
docker compose -f docker-compose.yaml exec -it peertube-instance-index-filter peertube-instance-index-filter -command index -url $(url) -instance-url $(instance-url)
|
||||
|
||||
### reject: Reject host. Arguments: host and reason (optional)
|
||||
.PHONY: reject
|
||||
reject:
|
||||
docker compose -f docker-compose.yaml exec -it peertube-instance-index-filter peertube-instance-index-filter -command reject -host $(host) -reject-reason $(reason)
|
6
docker/README
Normal file
6
docker/README
Normal file
|
@ -0,0 +1,6 @@
|
|||
Usualy I seperate git repo from Dockerfile, so I copy these docker files to same directory where repo is cloned. I serve it under traefik, so I added labels to composer.
|
||||
|
||||
`instances.db` should be copied, too.
|
||||
|
||||
`Makefile` is wrapper to add index hosts and reject hosts. Run `make help` for more info.
|
||||
|
20
docker/docker-compose.yaml
Normal file
20
docker/docker-compose.yaml
Normal file
|
@ -0,0 +1,20 @@
|
|||
version: "3.9"
|
||||
|
||||
services:
|
||||
peertube-instance-index-filter:
|
||||
build: ./peertube-instance-index-filter
|
||||
volumes:
|
||||
- ./instances.db:/usr/src/app/instances.db
|
||||
expose:
|
||||
- 8081
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.peertube_instance_index.rule=Host(`index.tv.arns.lt`)
|
||||
- traefik.http.routers.peertube_instance_index.tls.certresolver=le
|
||||
- traefik.http.routers.peertube_instance_index.entrypoints=websecure
|
||||
restart: always
|
||||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: traefik_default
|
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