Merge branch 'master' of https://github.com/ewhal/nyaa
Conflicts: router/userHandler.go
Cette révision appartient à :
révision
ab59d8d04a
16 fichiers modifiés avec 125 ajouts et 26 suppressions
6
config/upload.go
Fichier normal
6
config/upload.go
Fichier normal
|
@ -0,0 +1,6 @@
|
|||
package config
|
||||
|
||||
const (
|
||||
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
|
||||
TorrentFileStorage = ""
|
||||
)
|
3
main.go
3
main.go
|
@ -56,6 +56,9 @@ func main() {
|
|||
db.ORM, _ = db.GormInit(conf)
|
||||
initI18N()
|
||||
go signals.Handle()
|
||||
if len(config.TorrentFileStorage) > 0 {
|
||||
os.MkdirAll(config.TorrentFileStorage, 0755)
|
||||
}
|
||||
RunServer(conf)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
/* Night mode image */
|
||||
#sunmoon {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
height: 30px;
|
||||
|
||||
}
|
||||
/* Torrent status colors */
|
||||
.remake {
|
||||
background-color: #795c46;
|
||||
|
@ -25,6 +32,7 @@
|
|||
|
||||
#container {
|
||||
padding-top: 1.25em;
|
||||
background-color: #29363d;
|
||||
}
|
||||
|
||||
#container.cont-home {
|
||||
|
@ -64,7 +72,7 @@ a {
|
|||
}
|
||||
|
||||
.download-btn {
|
||||
font-size: 20px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.table-borderless > tbody > tr > td,
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
/* Night mode image */
|
||||
#sunmoon {
|
||||
position: fixed;
|
||||
top: 10px;
|
||||
height: 30px;
|
||||
}
|
||||
/* Torrent status colors */
|
||||
.remake {
|
||||
background-color: rgb(240, 176, 128);
|
||||
|
@ -10,29 +16,30 @@
|
|||
}
|
||||
|
||||
/* modified copy of NyaaTorrent theme */
|
||||
nav#mainmenu {
|
||||
#mainmenu {
|
||||
background: #263238;
|
||||
position: fixed;
|
||||
color: white;
|
||||
width: 100%;
|
||||
z-index: 4;
|
||||
border: 0px solid white;
|
||||
}
|
||||
|
||||
nav#mainmenu a {
|
||||
#mainmenu a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
div#container {
|
||||
#container {
|
||||
padding-top: 1.25em;
|
||||
background: white;
|
||||
}
|
||||
|
||||
div#container.cont-home {
|
||||
#container.cont-home {
|
||||
background: white url(/img/renchon.png) no-repeat;
|
||||
}
|
||||
div#container.cont-view {
|
||||
#container.cont-view {
|
||||
background: white url(/img/renchon.png) no-repeat;
|
||||
background-size: 61px;
|
||||
background-size: 75px, 100px;
|
||||
}
|
||||
|
||||
body {
|
||||
|
@ -42,9 +49,6 @@ body {
|
|||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.blockBody {
|
||||
padding-bottom: 2rem;
|
||||
}
|
||||
|
||||
.torrentNav {
|
||||
text-align: center;
|
||||
|
@ -63,7 +67,7 @@ a {
|
|||
}
|
||||
|
||||
.download-btn {
|
||||
font-size: 20px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.table-borderless > tbody > tr > td,
|
||||
|
@ -163,4 +167,9 @@ div.container div.blockBody:nth-of-type(2) table tr:first-of-type th:last-of-typ
|
|||
background-image: -moz-linear-gradient(left, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
|
||||
background-image: -o-linear-gradient(left, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
|
||||
background-image: linear-gradient(to right, #c4e17f, #c4e17f 12.5%, #f7fdca 12.5%, #f7fdca 25%, #fecf71 25%, #fecf71 37.5%, #f0776c 37.5%, #f0776c 50%, #db9dbe 50%, #db9dbe 62.5%, #c49cde 62.5%, #c49cde 75%, #669ae1 75%, #669ae1 87.5%, #62c2e4 87.5%, #62c2e4);
|
||||
}
|
||||
}
|
||||
|
||||
.center-image {
|
||||
max-width: 100%;
|
||||
max-height: 80vh;
|
||||
}
|
||||
|
|
BIN
public/img/moon.png
Fichier normal
BIN
public/img/moon.png
Fichier normal
Fichier binaire non affiché.
Après Largeur: | Hauteur: | Taille: 4,7 Kio |
BIN
public/img/sun.png
Fichier normal
BIN
public/img/sun.png
Fichier normal
Fichier binaire non affiché.
Après Largeur: | Hauteur: | Taille: 5,5 Kio |
|
@ -1,3 +1,27 @@
|
|||
// Night mode
|
||||
// also sorry that this code is soo bad, literally nothing else worked.. ima remake it in a near future
|
||||
var night = localStorage.getItem("night");
|
||||
if (night=="true") {
|
||||
document.getElementById("style").href = "/css/style-night.css";
|
||||
document.getElementById("nightbutton").innerHTML = "<img id='sunmoon' src='/img/sun.png' alt='Day!'>";
|
||||
}
|
||||
|
||||
function toggleNightMode() {
|
||||
var styleshieeet = document.getElementById("style").href;
|
||||
var styleshieet = new RegExp("style.css");
|
||||
var stylesheet = styleshieet.test(styleshieeet);
|
||||
if (stylesheet==true) {
|
||||
document.getElementById("style").href = "/css/style-night.css";
|
||||
document.getElementById("nightbutton").innerHTML = "<img id='sunmoon' src='/img/sun.png' alt='Day!'>";
|
||||
localStorage.setItem("night", "true");
|
||||
}
|
||||
else {
|
||||
document.getElementById("style").href = "/css/style.css";
|
||||
document.getElementById("nightbutton").innerHTML = "<img id='sunmoon' src='/img/moon.png' alt='Night!'>";
|
||||
localStorage.setItem("night", "false");
|
||||
}
|
||||
}
|
||||
|
||||
// Used by spoiler tags
|
||||
function toggleLayer(elem) {
|
||||
if (elem.classList.contains("hide"))
|
||||
|
|
|
@ -15,6 +15,8 @@ func init() {
|
|||
}
|
||||
|
||||
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
||||
searchForm := NewSearchForm()
|
||||
searchForm.HideAdvancedSearch = true
|
||||
err := notFoundTemplate.ExecuteTemplate(w, "index.html", NotFoundTemplateVariables{Navigation{}, searchForm, r.URL, mux.CurrentRoute(r)})
|
||||
|
|
|
@ -4,6 +4,7 @@ import(
|
|||
"time"
|
||||
"net/http"
|
||||
"github.com/gorilla/feeds"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/util/search"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -18,7 +19,7 @@ func RssHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
feed := &feeds.Feed{
|
||||
Title: "Nyaa Pantsu",
|
||||
Link: &feeds.Link{Href: "https://nyaa.pantsu.cat/"},
|
||||
Link: &feeds.Link{Href: "https://" + config.WebAddress + "/"},
|
||||
Created: created_as_time,
|
||||
}
|
||||
feed.Items = []*feeds.Item{}
|
||||
|
@ -44,4 +45,4 @@ func RssHandler(w http.ResponseWriter, r *http.Request) {
|
|||
} else {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,12 +3,18 @@ package router
|
|||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"regexp"
|
||||
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/service/captcha"
|
||||
"github.com/ewhal/nyaa/util"
|
||||
"github.com/ewhal/nyaa/util/metainfo"
|
||||
|
@ -20,14 +26,15 @@ import (
|
|||
type UploadForm struct {
|
||||
Name string
|
||||
Magnet string
|
||||
Infohash string
|
||||
Category string
|
||||
Description string
|
||||
captcha.Captcha
|
||||
|
||||
Infohash string
|
||||
CategoryId int
|
||||
SubCategoryId int
|
||||
Filesize int64
|
||||
Filepath string
|
||||
}
|
||||
|
||||
// TODO: these should be in another package (?)
|
||||
|
@ -55,8 +62,7 @@ var ErrTorrentPlusMagnet = errors.New("upload either a torrent file or magnet li
|
|||
var ErrPrivateTorrent = errors.New("torrent is private")
|
||||
|
||||
// error indicating a problem with its trackers
|
||||
// FIXME: hardcoded link
|
||||
var ErrTrackerProblem = errors.New("torrent does not have any (working) trackers: https://nyaa.pantsu.cat/faq#trackers")
|
||||
var ErrTrackerProblem = errors.New("torrent does not have any (working) trackers: https://" + config.WebAddress + "/faq#trackers")
|
||||
|
||||
// error indicating a torrent's name is invalid
|
||||
var ErrInvalidTorrentName = errors.New("torrent name is invalid")
|
||||
|
@ -108,7 +114,9 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
tfile, _, err := r.FormFile(UploadFormTorrent)
|
||||
if err == nil {
|
||||
var torrent metainfo.TorrentFile
|
||||
|
||||
// decode torrent
|
||||
tfile.Seek(0, io.SeekStart)
|
||||
err = bencode.NewDecoder(tfile).Decode(&torrent)
|
||||
if err != nil {
|
||||
return metainfo.ErrInvalidTorrentFile
|
||||
|
@ -155,6 +163,7 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
}
|
||||
|
||||
f.Filesize = 0
|
||||
f.Filepath = ""
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,9 +176,30 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
// return ErrInvalidTorrentDescription
|
||||
//}
|
||||
|
||||
|
||||
// after data has been checked & extracted, write it to disk
|
||||
if len(config.TorrentFileStorage) > 0 {
|
||||
err := WriteTorrentToDisk(tfile, f.Infohash + ".torrent", &f.Filepath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
f.Filepath = ""
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func WriteTorrentToDisk(file multipart.File, name string, fullpath *string) error {
|
||||
file.Seek(0, io.SeekStart)
|
||||
b, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*fullpath = fmt.Sprintf("%s%c%s", config.TorrentFileStorage, os.PathSeparator, name)
|
||||
return ioutil.WriteFile(*fullpath, b, 0644)
|
||||
}
|
||||
|
||||
var dead_trackers = []string{ // substring matches!
|
||||
"://open.nyaatorrents.info:6544",
|
||||
"://tracker.openbittorrent.com:80",
|
||||
|
|
|
@ -3,6 +3,7 @@ package router
|
|||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -23,6 +24,9 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if !captcha.Authenticate(uploadForm.Captcha) {
|
||||
// TODO: Prettier passing of mistyoed captcha errors
|
||||
http.Error(w, captcha.ErrInvalidCaptcha.Error(), 403)
|
||||
if len(uploadForm.Filepath) > 0 {
|
||||
os.Remove(uploadForm.Filepath)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,7 +41,6 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
Filesize: uploadForm.Filesize, // FIXME: should set to NULL instead of 0
|
||||
Description: uploadForm.Description,
|
||||
Comments: []byte{}}
|
||||
//fmt.Printf("%+v\n", torrent)
|
||||
db.ORM.Create(&torrent)
|
||||
fmt.Printf("%+v\n", torrent)
|
||||
url, err := Router.Get("view_torrent").URL("id", strconv.Itoa(torrent.Id))
|
||||
|
|
|
@ -38,6 +38,12 @@ func NewErrors() map[string][]string {
|
|||
err := make(map[string][]string)
|
||||
return err
|
||||
}
|
||||
func IsAgreed(t_and_c string) bool {
|
||||
if t_and_c == "1" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RegistrationForm is used when creating a user.
|
||||
type RegistrationForm struct {
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
<div>
|
||||
<h1>404 Not Found</h1>
|
||||
<br />
|
||||
<img class="center-block" src="/img/404.svg"></img>
|
||||
<img class="center-block center-image" src="/img/404.svg"></img>
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
@ -39,9 +39,9 @@
|
|||
<a href="{{.Magnet}}" title="Magnet link">
|
||||
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span>
|
||||
</a>
|
||||
<!-- <a href="https://itorrents.org/torrent/{{.Hash}}.torrent" title="Torrent file">
|
||||
<a href="http://anicache.com/torrent/{{.Hash}}.torrent" title="Torrent file">
|
||||
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span>
|
||||
</a> -->
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<![endif]-->
|
||||
|
||||
<!-- Website CSS -->
|
||||
<link rel="stylesheet" href="{{.URL.Parse "/css/style.css"}}">
|
||||
<link rel="stylesheet" id="style" href="{{.URL.Parse "/css/style.css"}}">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-default" id="mainmenu">
|
||||
|
@ -47,6 +47,8 @@
|
|||
<li><a href="irc://irc.rizon.net/nyaapantsu">IRC</a></li>
|
||||
<li><a href="{{ genRouteWithQuery "feed" .URL }}">RSS</a></li>
|
||||
<li><a href="https://sukebei.pantsu.cat">Fap</a></li>
|
||||
<li><a href="javascript:void(0);" id="nightbutton" onclick='toggleNightMode();'><img id="sunmoon" src="/img/moon.png" alt="Night!"></a></li>
|
||||
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" action="/search" method="get">
|
||||
<div class="form-group">
|
||||
|
@ -54,7 +56,7 @@
|
|||
{{block "search_button" .}}{{end}}
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
|
|
@ -28,9 +28,14 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td>Links</td>
|
||||
<td><a aria-label="Magnet Button" href="{{.Magnet}}" type="button" class="btn btn-success download-btn"><span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!</button>
|
||||
<!-- <a
|
||||
href="https://itorrents.org/torrent/{{.Hash}}.torrent" title="Torrent file"><span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span></a>-->
|
||||
<td>
|
||||
<a aria-label="Magnet Button" href="{{.Magnet}}" type="button" class="btn btn-success download-btn">
|
||||
<span class="glyphicon glyphicon-magnet" aria-hidden="true"></span> Download!</button>
|
||||
</a>
|
||||
<a style="padding-left: 0.5em"></a>
|
||||
<a aria-label="Torrent file" href="http://anicache.com/torrent/{{.Hash}}.torrent" type="button" class="btn btn-success">
|
||||
<span class="glyphicon glyphicon-floppy-save" aria-hidden="true"></span> Torrent file
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
Référencer dans un nouveau ticket