Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0

Don't make path configurable, detect empty directory

Cette révision appartient à :
tomleb 2017-05-11 12:30:38 -04:00
Parent 546a39bb14
révision 9c6c66d0e9
5 fichiers modifiés avec 19 ajouts et 16 suppressions

Voir le fichier

@ -1,6 +0,0 @@
package config
const (
DefaultDatabaseDumpPath = "./public/dumps/"
DefaultGPGPublicKeyPath = "./public/gpg/"
)

Voir le fichier

@ -24,6 +24,10 @@ import (
// RunServer runs webapp mainloop
func RunServer(conf *config.Config) {
// TODO Use config from cli
os.Mkdir(router.DatabaseDumpPath, 700)
// TODO Use config from cli
os.Mkdir(router.GPGPublicKeyPath, 700)
http.Handle("/", router.Router)
// Set up server,

Voir le fichier

@ -1,13 +1,12 @@
package router
import (
"io/ioutil"
"os"
"path/filepath"
"net/http"
"fmt"
"time"
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/util/languages"
"github.com/ewhal/nyaa/util/log"
@ -15,19 +14,21 @@ import (
"github.com/gorilla/mux"
)
const (
DatabaseDumpPath = "./public/dumps"
GPGPublicKeyPath = "./public/gpg/gpg.key"
)
func DatabaseDumpHandler(w http.ResponseWriter, r *http.Request) {
// db params url
var err error
// TODO Use config from cli
files, _ := ioutil.ReadDir(config.DefaultDatabaseDumpPath)
if len(files) <= 0 {
return
}
files, err := filepath.Glob(filepath.Join(DatabaseDumpPath, "*.torrent"))
var dumpsJson []model.DatabaseDumpJSON
// TODO Filter *.torrent files
for _, f := range files {
// TODO Use config from cli
file, err := os.Open(config.DefaultDatabaseDumpPath + f.Name())
file, err := os.Open(f)
if err != nil {
continue
}
@ -42,7 +43,7 @@ func DatabaseDumpHandler(w http.ResponseWriter, r *http.Request) {
Date: time.Now(),
Filesize: int64(tf.TotalSize()),
Name: tf.TorrentName(),
TorrentLink: "/dbdumps/" + f.Name()}
TorrentLink: "/dbdumps/" + file.Name()}
dumpsJson = append(dumpsJson, dump.ToJSON())
}

Voir le fichier

@ -17,10 +17,10 @@ func init() {
imgHandler := http.FileServer(http.Dir("./public/img/"))
// TODO Use config from cli
// TODO Make sure the directory exists
dumpsHandler := http.FileServer(http.Dir(config.DefaultDatabaseDumpPath))
dumpsHandler := http.FileServer(http.Dir(DatabaseDumpPath))
// TODO Use config from cli
// TODO Make sure the directory exists
gpgKeyHandler := http.FileServer(http.Dir(config.DefaultGPGPublicKeyPath))
gpgKeyHandler := http.FileServer(http.Dir(GPGPublicKeyPath))
gzipHomeHandler := http.HandlerFunc(HomeHandler)
gzipAPIHandler := http.HandlerFunc(ApiHandler)
gzipAPIViewHandler := http.HandlerFunc(ApiViewHandler)

Voir le fichier

@ -10,6 +10,7 @@
</nav>
<div class="table-responsive">
{{ if gt (len .ListDumps) 0 }}
<table class="table custom-table-hover">
<tr>
<th class="col-xs-8">{{T "name"}}</th>
@ -35,6 +36,9 @@
</tr>
{{end}}
</table>
{{else}}
<h1>{{T "no_database_dumps_available"}}</h1>
{{end}}
</div>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">