Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
ayame-git 2017-05-06 11:36:37 +03:00
Parent ccbf731cf3
révision d6ef924fa3
7 fichiers modifiés avec 164 ajouts et 31 suppressions

Voir le fichier

@ -29,7 +29,6 @@ func RunServer(conf *config.Config) {
}
func main() {
conf := config.NewConfig()
conf_bind := conf.BindFlags()
defaults := flag.Bool("print-defaults", false, "print the default configuration file on stdout")

Voir le fichier

@ -28,4 +28,5 @@ func init() {
Router.HandleFunc("/faq", FaqHandler).Name("faq")
Router.HandleFunc("/feed", RssHandler).Name("feed")
Router.HandleFunc("/view/{id}", ViewHandler).Name("view_torrent")
Router.HandleFunc("/upload", UploadHandler).Name("upload")
}

Voir le fichier

@ -1,8 +1,8 @@
package router
import (
"github.com/gorilla/mux"
"github.com/ewhal/nyaa/model"
"github.com/gorilla/mux"
"net/url"
)
@ -14,28 +14,35 @@ import (
type FaqTemplateVariables struct {
Navigation Navigation
Search SearchForm
Search SearchForm
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type ViewTemplateVariables struct {
Torrent model.TorrentsJson
Search SearchForm
Navigation Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
Torrent model.TorrentsJson
Search SearchForm
Navigation Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type HomeTemplateVariables struct {
ListTorrents []model.TorrentsJson
ListCategories []model.Categories
Search SearchForm
Search SearchForm
Navigation Navigation
URL *url.URL // For parsing Url in templates
Route *mux.Route // For getting current route in templates
}
type UploadTemplateVariables struct {
Upload UploadForm
Search SearchForm
Navigation Navigation
URL *url.URL
Route *mux.Route
}
/*
* Variables used by the upper ones
@ -48,31 +55,52 @@ type Navigation struct {
}
type SearchForm struct {
Query string
Status string
Category string
Sort string
Order string
Query string
Status string
Category string
Sort string
Order string
HideAdvancedSearch bool
}
type UploadForm struct {
Name string
Magnet string
Category string
Description string
}
// Some Default Values to ease things out
func NewSearchForm(params ...string) SearchForm {
searchForm := SearchForm{}
if (len(params) > 1) {
if len(params) > 1 {
searchForm.Category = params[0]
} else {
searchForm.Category = "_"
} else {
searchForm.Category = "_"
}
if (len(params) > 2) {
searchForm.Sort = params[0]
} else {
searchForm.Sort = "torrent_id"
if len(params) > 2 {
searchForm.Sort = params[1]
} else {
searchForm.Sort = "torrent_id"
}
if (len(params) > 3) {
searchForm.Order = params[0]
} else {
searchForm.Order = "DESC"
if len(params) > 3 {
searchForm.Order = params[2]
} else {
searchForm.Order = "DESC"
}
return searchForm
}
func NewUploadForm(params ...string) UploadForm {
uploadForm := UploadForm{}
if len(params) > 1 {
uploadForm.Category = params[0]
} else {
uploadForm.Category = "3_12"
}
if len(params) > 2 {
uploadForm.Description = params[1]
} else {
uploadForm.Description = "Description"
}
return uploadForm
}

35
router/uploadHandler.go Fichier normal
Voir le fichier

@ -0,0 +1,35 @@
package router
import (
"github.com/gorilla/mux"
"html/template"
"net/http"
)
func UploadHandler(w http.ResponseWriter, r *http.Request) {
var templates = template.Must(template.New("upload").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/upload.html"))
templates.ParseGlob("templates/_*.html") // common
var uploadForm UploadForm
if r.Method == "POST" {
err := r.ParseForm()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
uploadForm = UploadForm{
r.Form.Get("name"),
r.Form.Get("magnet"),
r.Form.Get("c"),
r.Form.Get("desc"),
}
//validate name + hash
//add to db and redirect depending on result
}
htv := UploadTemplateVariables{uploadForm, NewSearchForm(), Navigation{}, r.URL, mux.CurrentRoute(r)}
err := templates.ExecuteTemplate(w, "index.html", htv)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

Voir le fichier

@ -1,15 +1,15 @@
package router
import(
"net/http"
"html/template"
"github.com/gorilla/mux"
import (
"github.com/ewhal/nyaa/service/torrent"
"github.com/gorilla/mux"
"html/template"
"net/http"
)
func ViewHandler(w http.ResponseWriter, r *http.Request) {
var templates = template.Must(template.New("view").Funcs(FuncMap).ParseFiles("templates/index.html", "templates/view.html"))
templates.ParseGlob("templates/_*.html") // common
templates.ParseGlob("templates/_*.html") // common
vars := mux.Vars(r)
id := vars["id"]
@ -22,4 +22,4 @@ func ViewHandler(w http.ResponseWriter, r *http.Request) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
}

Voir le fichier

@ -41,6 +41,7 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="https://sukebei.pantsu.cat">Fap</a></li>
<li><a href="{{.URL.Parse "/upload"}}">Upload</a/></li>
<li><a href="{{.URL.Parse "/faq"}}">FAQ</a></li>
<li><a href="irc://irc.rizon.net/nyaapantsu">IRC</a></li>
<li><a href="{{ genRouteWithQuery "feed" .URL }}">RSS</a></li>

69
templates/upload.html Fichier normal
Voir le fichier

@ -0,0 +1,69 @@
{{define "title"}}Upload magnet{{end}}
{{define "content"}}
<div class="blockBody">
{{with .Upload}}
<hr>
<form role="upload" method="POST">
<table class="table table-borderless">
<tr>
<td>
<div class="col-xs-6">
<input type="text" name="name" class="form-control"placeholder="File Name" value="{{.Name}}" required>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-xs-8">
<input type="text" name="magnet" class="form-control"
style="width:60rem" placeholder="Magnet Link" value="{{.Magnet}}" required>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-xs-4">
<select name="c" class="form-control input-sm">
<option value="3_" {{if eq .Category "3_"}}selected{{end}}>Anime</option>
<option value="3_12" {{if eq .Category "3_12"}}selected{{end}}>Anime - Anime Music Video</option>
<option value="3_5" {{if eq .Category "3_5"}}selected{{end}}>Anime - English-translated</option>
<option value="3_13" {{if eq .Category "3_13"}}selected{{end}}>Anime - Non-English-translated</option>
<option value="3_6" {{if eq .Category "3_6"}}selected{{end}}>Anime - Raw</option>
<option value="2_" {{if eq .Category "2_"}}selected{{end}}>Audio</option>
<option value="2_3" {{if eq .Category "2_3"}}selected{{end}}>Audio - Lossless</option>
<option value="2_4" {{if eq .Category "2_4"}}selected{{end}}>Audio - Lossy</option>
<option value="4_" {{if eq .Category "4_"}}selected{{end}}>Literature</option>
<option value="4_7" {{if eq .Category "4_7"}}selected{{end}}>Literature - English-translated</option>
<option value="4_8" {{if eq .Category "4_8"}}selected{{end}}>Literature - Raw</option>
<option value="4_14" {{if eq .Category "4_14"}}selected{{end}}>Literature - Non-English-translated</option>
<option value="5_" {{if eq .Category "5_"}}selected{{end}}>Live Action</option>
<option value="5_9" {{if eq .Category "5_9"}}selected{{end}}>Live Action - English-translated</option>
<option value="5_10" {{if eq .Category "5_10"}}selected{{end}}>Live Action - Idol/Promotional Video</option>
<option value="5_18" {{if eq .Category "5_18"}}selected{{end}}>Live Action - Non-English-translated</option>
<option value="5_11" {{if eq .Category "5_11"}}selected{{end}}>Live Action - Raw</option>
<option value="6_" {{if eq .Category "6_"}}selected{{end}}>Pictures</option>
<option value="6_15" {{if eq .Category "6_15"}}selected{{end}}>Pictures - Graphics</option>
<option value="6_16" {{if eq .Category "6_16"}}selected{{end}}>Pictures - Photos</option>
<option value="1_" {{if eq .Category "1_"}}selected{{end}}>Software</option>
<option value="1_1" {{if eq .Category "1_1"}}selected{{end}}>Software - Applications</option>
<option value="1_2" {{if eq .Category "1_2"}}selected{{end}}>Software - Games</option>
</select>
</div>
</td>
</tr>
<tr>
<td>
<div class="col-xs-7">
<textarea name="desc" class="form-control" rows="10">{{.Description}}</textarea>
</div>
</td>
</tr>
<tr>
<td>
<button type="submit" class="btn">Upload!</button>
</td>
</tr>
</table>
{{end}}
</div>
{{end}}