RC1
All checks were successful
release-tag / release-image (push) Successful in 1m39s

This commit is contained in:
2025-06-16 22:26:33 +02:00
parent cc622587b0
commit aeb3b62b64
3 changed files with 122 additions and 4 deletions

49
main.go
View File

@@ -24,6 +24,7 @@ package main
import (
"bufio"
"encoding/json"
"flag"
"fmt"
"io"
@@ -577,17 +578,18 @@ type target struct {
const (
indexTemplateHTML = `<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"><title>IPv64 Blocklists</title>
<head><meta charset="utf-8"><title>IP Blocklists</title>
<style>body{font-family:system-ui, sans-serif;margin:2rem}table{border-collapse:collapse}td,th{padding:4px 8px;border:1px solid #ddd}</style></head>
<body>
<h1>IPv64 Blocklists</h1>
<p>Es sind {{len .Files}} Dateien verfügbar (letztes Update: {{.Updated}}).</p>
<h1>IP Blocklists</h1>
<p>There are {{len .Files}} files available (last Update: {{.Updated}}).</p>
<table>
<tr><th>Datei</th><th>Größe</th><th>Zuletzt geändert</th></tr>
<tr><th>File</th><th>Row Count</th><th>Last Changed</th></tr>
{{range .Files}}
<tr><td><a href="/lists/{{.Name}}">{{.Name}}</a></td><td align="right">{{.Size}}</td><td>{{.ModTime}}</td></tr>
{{end}}
</table>
<p><a href="/lists.json">/lists.json</a> - Full list as JSON</p>
</body>
</html>`
)
@@ -647,6 +649,16 @@ func main() {
tmpl.Execute(w, data)
})
// JSON API /lists.json
http.HandleFunc("/lists.json", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
if err := enc.Encode(defaultLists); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
log.Printf("HTTP server listening on %s, serving %s", *listenAddr, *outDir)
log.Fatal(http.ListenAndServe(*listenAddr, nil))
}
@@ -722,6 +734,35 @@ func fetchAndSave(client *http.Client, t target, outDir string) error {
return os.Rename(tmp, dst)
}
// ──────────────────────────────────────────────────────────────────────────────
// Helpers
// ──────────────────────────────────────────────────────────────────────────────
// ExportListJSON schreibt die Map als prettified JSONDatei.
func ExportListJSON(path string, m map[string]string) error {
f, err := os.Create(path)
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
return enc.Encode(m)
}
// ImportListJSON liest eine JSONDatei und gibt map[string]string zurück.
func ImportListJSON(path string) (map[string]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()
var m map[string]string
if err := json.NewDecoder(f).Decode(&m); err != nil {
return nil, err
}
return m, nil
}
// buildIndexData assembles a directory listing for the /index route.
func buildIndexData(dir string) (struct {
Files []fileInfo