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

Updated my own branch

Cette révision appartient à :
akuma06 2017-05-06 17:53:17 +02:00
révision dc050d29fc
9 fichiers modifiés avec 224 ajouts et 47 suppressions

Voir le fichier

@ -8,8 +8,7 @@ import (
"fmt"
"io"
"os"
"sync"
)
)
type Config struct {
Host string `json: "host"`
@ -17,11 +16,11 @@ type Config struct {
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"`
DBParams string `json: "db_params"`
}
var Defaults = Config{"localhost", 9999, "sqlite3", "./nyaa.db?cache_size=50"}
var PrintDefaults *bool
var allowedDatabaseTypes = map[string]bool{
"sqlite3": true,
"postgres": true,
@ -29,45 +28,39 @@ var allowedDatabaseTypes = map[string]bool{
"mssql": true,
}
var instance *Config
var once sync.Once
func GetInstance() *Config {
once.Do(func() {
instance = &Config{}
instance.Host = Defaults.Host
instance.Port = Defaults.Port
instance.DBType = Defaults.DBType
instance.DBParams = Defaults.DBParams
instance.BindFlags()
})
return instance
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() 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.
// 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)")
PrintDefaults = flag.Bool("print-defaults", false, "print the default configuration file on stdout")
flag.Parse()
err := config.HandleConfFileFlag(*conf_file)
if err != nil {
return func() error {
// 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)
if err != nil {
return err
}
err = config.HandleConfFileFlag(*conf_file)
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 {
@ -109,4 +102,4 @@ func (config *Config) Pretty(output io.Writer) error {
data = append(data, []byte("\n")...)
_, err = output.Write(data)
return err
}
}

149
css/style-night.css Fichier normal
Voir le fichier

@ -0,0 +1,149 @@
/* Torrent status colors */
.remake {
background-color: #a05013;
}
.trusted {
background-color: #238025;
}
.aplus {
background-color: #0777ab;
}
/* modified copy of NyaaTorrent theme */
#mainmenu {
background: #263238;
position: fixed;
color: #f2f2f2;
width: 100%;
z-index: 4;
border: 0px solid #263238;
}
#mainmenu a {
color: #eff5f5;
}
#container {
padding-top: 1.25em;
}
#container.cont-home {
background: #29363d url(/img/megumin.png) no-repeat;
}
#container.cont-view {
background: #29363d url(/img/megumin.png) no-repeat;
background-size: 75px, 100px;
}
body {
background-color: #264040;
color: #eff5f5;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.torrentNav {
text-align: center;
}
.pagination {
background-color: #264040;
}
.pagination > .active > a {
background-color: #ececec;
border-color: #ececec;
color: #337ab7; /* restore usual text color */
}
/* Links, Text */
a {
color: #1cb093;
text-decoration : none;
}
.download-btn {
font-size: 20px;
}
.table-borderless > tbody > tr > td,
.table-borderless > tbody > tr > th,
.table-borderless > tfoot > tr > td,
.table-borderless > tfoot > tr > th,
.table-borderless > thead > tr > td,
.table-borderless > thead > tr > th {
border: none;
}
.torrent-info .name {
font-weight: bold;
overflow: hidden;
padding-bottom: 3px;
padding-top: 3px;
word-wrap: break-word;
}
.torrent-hash {
font-family: monospace;
}
.torrent-info .filesize {
white-space: nowrap;
}
.comment-row td:first-of-type {
vertical-align: top;
text-align: right;
}
/* Table style & fixes */
.table > tbody > tr > td {
/* fix bootstrap uglyness */
vertical-align: middle;
}
.table > tbody > tr > th, .table > tbody > tr > td {
padding: 4px;
}
tr.torrent-info td.date {
white-space: nowrap;
}
.custom-table-hover > tbody > tr:hover {
opacity: 0.82;
}
.comment-row {
border-top: 1px solid #ddd;
}
div.container div.blockBody:nth-of-type(2) table{table-layout:fixed;}
div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:first-of-type, div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:nth-of-type(5){width:10%;}
div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:nth-of-type(3){width:15%;}
div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:nth-of-type(4){width:19%;}
div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-type{width:6%;}
/* Mobile-friendly main table */
@media only screen and (max-width: 700px) {
table, thead, tbody, tr {
display: block;
}
th {
display: none;
}
td {
display: inline-block;
}
td:nth-of-type(1), td:nth-of-type(2) {
display: block;
}
.table > tbody > tr > td {
border: none;
}
}

Voir le fichier

@ -2,20 +2,17 @@ package db
import (
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/util/log"
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/util/log"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
// _ "github.com/go-sql-driver/mysql"
)
var ORM, Errs = GormInit()
var ORM *gorm.DB
// GormInit init gorm ORM.
func GormInit() (*gorm.DB, error) {
conf := config.GetInstance()
func GormInit(conf *config.Config) (*gorm.DB, error) {
db, err := gorm.Open(conf.DBType, conf.DBParams)
// db, err := gorm.Open("mysql", config.MysqlDSL())
//db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
@ -39,7 +36,6 @@ func GormInit() (*gorm.DB, error) {
}
log.CheckError(err)
log.Infof("lol", conf.DBParams)
// relation := gorm.Relationship{}
// relation.Kind = "many2many"
@ -58,4 +54,4 @@ func GormInit() (*gorm.DB, error) {
// handler.Setup(&relation, "users_followers", m1Type, m2Type)
return db, err
}
}

BIN
img/megumin.png Fichier normal

Fichier binaire non affiché.

Après

Largeur:  |  Hauteur:  |  Taille: 19 KiB

16
main.go Fichier exécutable → Fichier normal
Voir le fichier

@ -2,9 +2,11 @@ package main
import (
"bufio"
"flag"
"fmt"
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/router"
"github.com/ewhal/nyaa/util/log"
@ -28,13 +30,21 @@ func RunServer(conf *config.Config) {
}
func main() {
conf := config.GetInstance()
if *config.PrintDefaults {
conf := config.NewConfig()
process_flags := 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 {
err := process_flags()
if err != nil {
log.CheckError(err)
}
db.ORM, _ = db.GormInit(conf)
RunServer(conf)
}
}
}

Voir le fichier

@ -49,7 +49,7 @@ type Torrents struct {
Hash string `gorm:"column:torrent_hash"`
Date int64 `gorm:"column:date"`
Downloads int `gorm:"column:downloads"`
Filesize string `gorm:"column:filesize"`
Filesize int64 `gorm:"column:filesize"`
Description []byte `gorm:"column:description"`
Comments []byte `gorm:"column:comments"`
Statuses Statuses `gorm:"ForeignKey:status_id;AssociationForeignKey:status_id"`
@ -112,7 +112,7 @@ func (t *Torrents) ToJson() TorrentsJson {
Status: t.Status,
Hash: t.Hash,
Date: time.Unix(t.Date, 0).Format(time.RFC3339),
Filesize: t.Filesize,
Filesize: util.FormatFilesize(t.Filesize),
Description: template.HTML(util.UnZlib(t.Description)),
Comments: b,
Sub_Category: t.Sub_Categories.ToJson(),

Voir le fichier

@ -30,7 +30,7 @@
<h2>How are we recovering?</h2>
<p>The aforementioned databases are being hosted at nyaa.pantsu.cat and sukebei.pantsu.cat.
There is a search function, and (almost) full nyaa functionality should be coming soon.
Seeder/leecher statistics are possible via scraping and might be restored somewhen in the future,
Seeder/leecher statistics are possible via scraping and might be restored sometime in the future,
since other feature take priority right now.</p>
<h2>Are the torrents still working?</h2>
@ -38,7 +38,7 @@
As long as the file is listed on the DHT network, business should carry on as usual.</p>
<h2>How do I download the torrents?</h2>
<p>Just use the <b>magnet link</b>. The magnet link will used by your BitTorrent client to look up the file on the
<p>Just use the <b>magnet link</b>. The magnet link will be used by your BitTorrent client to look up the file on the
DHT network and it should download just fine.</p>
<p>The magnet link should look like this: <span style="font-family:monospace">
magnet:?xt=urn:btih:[hash]&amp;dn=[name]&amp;tr=[tracker]&amp;tr=[...]</span></p>
@ -51,7 +51,7 @@
<p><a href="https://github.com/ewhal/nyaa/issues">https://github.com/ewhal/nyaa/issues</a>.</p>
<h2>Why is your shit written in Go?</h2>
<p>It's the authors favorite programming language.</p>
<p>It's the author's favorite programming language.</p>
<br />
<h2>nyaa.pantsu.cat and sukebei.pantsu.cat do not host any files.</h2>

Voir le fichier

@ -46,6 +46,11 @@
</tr>
{{end}}
</table>
<nav class="torrentNav" aria-label="Page navigation">
<ul class="pagination">
{{ genNav .Navigation .URL 10 }}
</ul>
</nav>
</div>
</div>
{{end}}

24
util/format.go Fichier normal
Voir le fichier

@ -0,0 +1,24 @@
package util
import (
"fmt"
)
func FormatFilesize(bytes int64) string {
var unit string
var value float64
if bytes > 1024*1024*1024 {
unit = "GiB"
value = float64(bytes) / (1024*1024*1024)
} else if bytes > 1024*1024 {
unit = "MiB"
value = float64(bytes) / (1024*1024)
} else if bytes > 1024 {
unit = "KiB"
value = float64(bytes) / (1024)
} else {
unit = "B"
value = float64(bytes)
}
return fmt.Sprintf("%.1f %s", value, unit)
}