Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/router/database_dump_handler.go

58 lignes
1,4 Kio
Go
Brut Vue normale Historique

2017-05-11 05:06:12 +02:00
package router
import (
2017-05-24 09:11:13 +02:00
"fmt"
"net/http"
2017-05-11 05:06:12 +02:00
"os"
"path/filepath"
2017-05-11 05:06:12 +02:00
"time"
2017-05-18 03:04:18 +02:00
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/util/log"
"github.com/NyaaPantsu/nyaa/util/metainfo"
2017-05-11 05:06:12 +02:00
)
const (
DatabaseDumpPath = "./public/dumps"
GPGPublicKeyPath = "./public/gpg/gpg.key"
)
2017-05-11 05:06:12 +02:00
func DatabaseDumpHandler(w http.ResponseWriter, r *http.Request) {
// db params url
var err error
// TODO Use config from cli
files, err := filepath.Glob(filepath.Join(DatabaseDumpPath, "*.torrent"))
2017-05-11 05:06:12 +02:00
var dumpsJson []model.DatabaseDumpJSON
// TODO Filter *.torrent files
2017-05-24 09:11:13 +02:00
for _, f := range files {
2017-05-11 05:06:12 +02:00
// TODO Use config from cli
file, err := os.Open(f)
2017-05-11 05:06:12 +02:00
if err != nil {
continue
}
var tf metainfo.TorrentFile
err = tf.Decode(file)
if err != nil {
log.CheckError(err)
fmt.Println(err)
continue
}
dump := model.DatabaseDump{
Date: time.Now(),
Filesize: int64(tf.TotalSize()),
Name: tf.TorrentName(),
TorrentLink: "/dbdumps/" + file.Name()}
2017-05-11 05:06:12 +02:00
dumpsJson = append(dumpsJson, dump.ToJSON())
2017-05-24 09:11:13 +02:00
}
2017-05-11 05:06:12 +02:00
// TODO Remove ?
navigationTorrents := Navigation{0, 0, 0, "search_page"}
common := NewCommonVariables(r)
common.Navigation = navigationTorrents
dtv := DatabaseDumpTemplateVariables{common, dumpsJson, "/gpg/gpg.pub"}
2017-05-11 05:06:12 +02:00
err = databaseDumpTemplate.ExecuteTemplate(w, "index.html", dtv)
if err != nil {
log.Errorf("DatabaseDump(): %s", err)
}
}