testing empty audit
This commit is contained in:
parent
32b4679eea
commit
58db0a28c7
4 changed files with 55 additions and 3 deletions
38
audit.go
38
audit.go
|
@ -17,17 +17,55 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func doAudit(host string, filter string) bool {
|
||||
db := connectDB()
|
||||
defer db.Close()
|
||||
|
||||
switch filter {
|
||||
case "dead":
|
||||
_, err := http.Get("https://" + host)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
case "empty":
|
||||
resp, err := http.Get("https://" + host + "/api/v1/server/stats")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return false
|
||||
}
|
||||
|
||||
var generic map[string]any
|
||||
err = json.NewDecoder(resp.Body).Decode(&generic)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
videos := generic["totalLocalVideos"].(float64)
|
||||
if videos != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
instance, err := getInstance(db, host)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
currentTime := time.Now()
|
||||
last3Month := currentTime.AddDate(0,-3,0)
|
||||
if instance.CreatedAt < last3Month.Format("2006-01-02T15:04:05Z") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
|
6
db.go
6
db.go
|
@ -228,6 +228,12 @@ func getDuplicateIds(db *sql.DB) ([]string, error) {
|
|||
return ids, nil
|
||||
}
|
||||
|
||||
func getInstance(db *sql.DB, url string) (Instance, error) {
|
||||
var instance Instance
|
||||
err := db.QueryRow("SELECT url, data, created_at, rejected, reject_reason FROM instances WHERE url = ?", url).Scan(&instance.Url, &instance.Data, &instance.CreatedAt, &instance.Rejected, &instance.RejectReason)
|
||||
return instance, err
|
||||
}
|
||||
|
||||
func removeInstance(db *sql.DB, id string) {
|
||||
db.Exec("DELETE FROM instances WHERE id = ?", id)
|
||||
}
|
||||
|
|
|
@ -17,5 +17,5 @@ reject:
|
|||
### audit: Audit hosts. Arguments: filter, start (skip instances)
|
||||
.PHONY: audit
|
||||
audit:
|
||||
docker compose -f docker-compose.yml exec -it peertube-instance-index-filter peertube-instance-index-filter -command audit -filter $(filter) -start $(start)
|
||||
docker compose -f docker-compose.yml exec -it peertube-instance-index-filter peertube-instance-index-filter -command audit -filter $(filter) -last-id $(start)
|
||||
|
||||
|
|
|
@ -11,7 +11,11 @@
|
|||
<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>
|
||||
<p>
|
||||
Contact on Fediverse: <img src="https://cdn.fosstodon.org/custom_emojis/images/000/691/237/static/fe937eadd5c9cb08.png" height="18">
|
||||
<a href="https://s.arns.lt/@zordsdavini">@zordsdavini@s.arns.lt</a><br>
|
||||
<a href="https://www.buymeacoffee.com/zordsdavini" target="_blank" rel="nofollow noopener"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="40px"></a>
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
|
@ -48,6 +52,10 @@
|
|||
|
||||
<h2>License</h2>
|
||||
|
||||
<p>GPLv3</p>
|
||||
<p>
|
||||
<a href="https://www.gnu.org/licenses/gpl-3.0.html" target="_blank">
|
||||
<img src="https://www.gnu.org/graphics/gplv3-127x51.png" height="20" alt="GNU GPL v3.0" />
|
||||
</a>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Add table
Reference in a new issue