Merge branch 'master' of https://github.com/ewhal/nyaa
Conflicts: main.go
Cette révision appartient à :
révision
ade17dad04
11 fichiers modifiés avec 197 ajouts et 30 suppressions
18
README.md
18
README.md
|
@ -15,6 +15,24 @@ that anyone will be able to deploy locally or remotely.
|
|||
* `./nyaa`
|
||||
* You can now access your local site over on [localhost:9999](http://localhost:9999)
|
||||
|
||||
## Usage
|
||||
|
||||
Type `./nyaa -h` for the list of options.
|
||||
|
||||
## Systemd
|
||||
|
||||
* Edit the unit file `os/nyaa.service` to your liking
|
||||
* Copy the package's content so that your unit file can find them.
|
||||
* Copy the unit file in `/usr/lib/systemd/system`
|
||||
* `systemctl daemon-reload`
|
||||
* `systemctl start nyaa`
|
||||
|
||||
The provided unit file uses options directly; if you prefer a config file, do the following:
|
||||
|
||||
* `./nyaa -print-defaults > /etc/nyaa.conf`
|
||||
* Edit `nyaa.conf` to your liking
|
||||
* Replace in the unit file the options by `-conf /etc/nyaa.conf`
|
||||
|
||||
## TODO
|
||||
* RSS feeds(work in progress)
|
||||
* torrent sorting (work in progress)
|
||||
|
|
105
config/config.go
Fichier normal
105
config/config.go
Fichier normal
|
@ -0,0 +1,105 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Host string `json: "host"`
|
||||
Port int `json: "port"`
|
||||
DBType string `json: "db_type"`
|
||||
// This will be directly passed to Gorm, and its internal
|
||||
// structure depends on the dialect for each db type
|
||||
DBParams string `json: "db_type"`
|
||||
}
|
||||
|
||||
var Defaults = Config{"localhost", 9999, "sqlite3", "./nyaa.db"}
|
||||
|
||||
var allowedDatabaseTypes = map[string]bool{
|
||||
"sqlite3": true,
|
||||
"postgres": true,
|
||||
"mysql": true,
|
||||
"mssql": true,
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
var config Config
|
||||
config.Host = Defaults.Host
|
||||
config.Port = Defaults.Port
|
||||
config.DBType = Defaults.DBType
|
||||
config.DBParams = Defaults.DBParams
|
||||
return &config
|
||||
}
|
||||
|
||||
type processFlags func() error
|
||||
|
||||
func (config *Config) BindFlags() processFlags {
|
||||
// This function returns a function which is to be used after
|
||||
// flag.Parse to check and copy the flags' values to the Config instance.
|
||||
|
||||
conf_file := flag.String("conf", "", "path to the configuration file")
|
||||
db_type := flag.String("dbtype", Defaults.DBType, "database backend")
|
||||
host := flag.String("host", Defaults.Host, "binding address of the server")
|
||||
port := flag.Int("port", Defaults.Port, "port of the server")
|
||||
db_params := flag.String("dbparams", Defaults.DBParams, "parameters to open the database (see Gorm's doc)")
|
||||
|
||||
return func() error {
|
||||
err := config.HandleConfFileFlag(*conf_file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// You can override fields in the config file with flags.
|
||||
config.Host = *host
|
||||
config.Port = *port
|
||||
config.DBParams = *db_params
|
||||
err = config.SetDBType(*db_type)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func (config *Config) HandleConfFileFlag(path string) error {
|
||||
if path != "" {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Can't read file '%s'.", path))
|
||||
}
|
||||
|
||||
err = config.Read(bufio.NewReader(file))
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf("Failed to parse file '%s' (%s).", path, err))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (config *Config) SetDBType(db_type string) error {
|
||||
if !allowedDatabaseTypes[db_type] {
|
||||
return errors.New(fmt.Sprintf("Unknown database backend '%s'.", db_type))
|
||||
}
|
||||
config.DBType = db_type
|
||||
return nil
|
||||
}
|
||||
|
||||
func (config *Config) Read(input io.Reader) error {
|
||||
return json.NewDecoder(input).Decode(config)
|
||||
}
|
||||
|
||||
func (config *Config) Write(output io.Writer) error {
|
||||
return json.NewEncoder(output).Encode(config)
|
||||
}
|
||||
|
||||
func (config *Config) Pretty(output io.Writer) error {
|
||||
data, err := json.MarshalIndent(config, "", "\t")
|
||||
data = append(data, []byte("\n")...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = output.Write(data)
|
||||
return err
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package config
|
||||
|
||||
const (
|
||||
DbName = "./nyaa.db"
|
||||
)
|
|
@ -1,47 +1,55 @@
|
|||
/* Torrent status colors */
|
||||
.remake {
|
||||
background-color: #f0b0b0;
|
||||
background-color: rgb(240, 176, 128);
|
||||
}
|
||||
.trusted {
|
||||
background-color: #98d9a8;
|
||||
background-color: #a3e9a4;
|
||||
}
|
||||
.aplus {
|
||||
background-color: #60b0f0;
|
||||
background-color: #81d3fa;
|
||||
}
|
||||
|
||||
|
||||
/* Copy of NyaaTorrent theme */
|
||||
/* modified copy of NyaaTorrent theme */
|
||||
nav#mainmenu {
|
||||
background: #1b1b1b;
|
||||
background: #263238;
|
||||
position: fixed;
|
||||
color: white;
|
||||
width: 100%;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
nav#mainmenu a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
div#container {
|
||||
padding-top: 10rem;
|
||||
padding-top: 1.25em;
|
||||
background: white;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #FBFBFB;
|
||||
background-color: #ececec;
|
||||
color: #111111;
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.blockBody {
|
||||
border-radius: 5px;
|
||||
border: 1px solid black;
|
||||
/*.blockBody {
|
||||
padding: 1rem;
|
||||
}
|
||||
}*/
|
||||
|
||||
.torrentNav {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pagination > .active > a {
|
||||
background: #ececec;
|
||||
border-color: #ececec;
|
||||
color: #337ab7; /* restore usual text color */
|
||||
}
|
||||
|
||||
/* Links, Text */
|
||||
a {
|
||||
color: #106655;
|
||||
|
|
|
@ -13,7 +13,8 @@ var ORM, Errs = GormInit()
|
|||
|
||||
// GormInit init gorm ORM.
|
||||
func GormInit() (*gorm.DB, error) {
|
||||
db, err := gorm.Open("sqlite3", config.DbName)
|
||||
conf := config.NewConfig()
|
||||
db, err := gorm.Open(conf.DBType, conf.DBParams)
|
||||
// db, err := gorm.Open("mysql", config.MysqlDSL())
|
||||
//db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
|
||||
|
||||
|
|
28
main.go
28
main.go
|
@ -1,17 +1,22 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"flag"
|
||||
"github.com/gorilla/feeds"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/service/torrent"
|
||||
"github.com/ewhal/nyaa/util/log"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
|
||||
"html"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -26,6 +31,7 @@ type SearchParam struct {
|
|||
Status string
|
||||
Sort string
|
||||
}
|
||||
|
||||
func apiHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
vars := mux.Vars(r)
|
||||
|
@ -263,8 +269,7 @@ func rootHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
func RunServer(conf *config.Config) {
|
||||
router = mux.NewRouter()
|
||||
|
||||
cssHandler := http.FileServer(http.Dir("./css/"))
|
||||
|
@ -289,7 +294,7 @@ func main() {
|
|||
|
||||
// Set up server,
|
||||
srv := &http.Server{
|
||||
Addr: "localhost:9999",
|
||||
Addr: fmt.Sprintf("%s:%d", conf.Host, conf.Port),
|
||||
WriteTimeout: 15 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
}
|
||||
|
@ -297,3 +302,20 @@ func main() {
|
|||
err := srv.ListenAndServe()
|
||||
log.CheckError(err)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
conf := config.NewConfig()
|
||||
conf_bind := conf.BindFlags()
|
||||
defaults := flag.Bool("print-defaults", false, "print the default configuration file on stdout")
|
||||
flag.Parse()
|
||||
if *defaults {
|
||||
stdout := bufio.NewWriter(os.Stdout)
|
||||
conf.Pretty(stdout)
|
||||
stdout.Flush()
|
||||
os.Exit(0)
|
||||
} else {
|
||||
conf_bind()
|
||||
RunServer(conf)
|
||||
}
|
||||
}
|
||||
|
|
12
os/nyaa.service
Fichier normal
12
os/nyaa.service
Fichier normal
|
@ -0,0 +1,12 @@
|
|||
[Unit]
|
||||
Description=Torrent indexer for weebs
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=/srv/nyaa/
|
||||
ExecStart=/usr/local/bin/nyaa -dbtype sqlite3 -dbparams ./nyaa.db
|
||||
StandardOutput=syslog
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
|
@ -16,5 +16,5 @@ for i in "${OSes[@]}"; do
|
|||
echo -e "\nBuilding $os..."
|
||||
echo GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v
|
||||
GOOS=$os GOARCH=amd64 CC=$cc CGO_ENABLED=1 go build -v
|
||||
zip -9 -q nyaa-${version}_${os}_amd64.zip css js *.md *.html nyaa nyaa.exe
|
||||
zip -9 -q nyaa-${version}_${os}_amd64.zip os css js *.md *.html nyaa nyaa.exe
|
||||
done
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<option value="1_2" {{if eq .Search.Category "1_2"}}selected{{end}}>Software - Games</option>
|
||||
</select>
|
||||
<select name="s" class="form-control input-sm">
|
||||
<option value="">Search all</option>
|
||||
<option value="">Show all</option>
|
||||
<option value="2" {{if eq .Search.Status "2"}}selected{{end}}>Remakes</option>
|
||||
<option value="3" {{if eq .Search.Status "3"}}selected{{end}}>Trusted</option>
|
||||
<option value="4" {{if eq .Search.Status "4"}}selected{{end}}>A+</option>
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
{{define "title"}}Home{{end}}
|
||||
{{define "content"}}
|
||||
<div class="blockBody">
|
||||
<nav class="torrentNav" aria-label="Page navigation">
|
||||
<ul class="pagination">
|
||||
{{ genNav .Navigation .URL 10 }}
|
||||
</ul>
|
||||
</nav>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
|
@ -39,10 +44,5 @@
|
|||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
<nav class="torrentNav" aria-label="Page navigation">
|
||||
<ul class="pagination">
|
||||
{{ genNav .Navigation .URL 10 }}
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
@ -50,10 +50,13 @@
|
|||
</div>
|
||||
</nav>
|
||||
|
||||
<!-- top padding -->
|
||||
<div style="padding-top: 10rem"></div>
|
||||
|
||||
<div class="container" id="container">
|
||||
<div class="blockBody" style="display:flex">
|
||||
<h3>Advanced Search</h3>
|
||||
<form class="navbar-form navbar-right" role="search" action="/search" method="get">
|
||||
<div class="blockBody" style="text-align:center">
|
||||
<font size="4.5">Advanced Search</font><br />
|
||||
<form class="navbar-form" role="search" action="/search" method="get">
|
||||
<div class="form-group">
|
||||
{{block "search_common" .}}{{end}}
|
||||
{{block "search_advanced" .}}{{end}}
|
||||
|
@ -66,6 +69,9 @@
|
|||
{{block "content" .}}Nothing Here.{{end}}
|
||||
</div>
|
||||
|
||||
<!-- bottom padding -->
|
||||
<div style="padding-top: 5rem"></div>
|
||||
|
||||
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
||||
<!-- Include all compiled plugins (below), or include individual files as needed -->
|
||||
|
|
Référencer dans un nouveau ticket