Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

go fmt all the code

Cette révision appartient à :
Eliot Whalan 2017-05-24 17:11:13 +10:00
Parent 58631c6bd4
révision b4b1b1c26a
Aucune clé n'a été trouvée pour cette signature dans la base de données
ID de la clé GPG: C0A42175139840D6
36 fichiers modifiés avec 283 ajouts et 298 suppressions

Voir le fichier

@ -5,7 +5,6 @@ import (
"strings"
)
type Status uint8
const (
@ -109,7 +108,6 @@ func (c *Category) Parse(s string) (ok bool) {
return
}
// deprecated for TorrentParam
type SearchParam struct {
Order bool // True means acsending

Voir le fichier

@ -32,4 +32,3 @@ func (p *TorrentParam) Clone() TorrentParam {
NameLike: p.NameLike,
}
}

Voir le fichier

@ -33,7 +33,6 @@ func IsSukebei() bool {
return TorrentsTableName == "sukebei_torrents"
}
type Config struct {
Host string `json:"host"`
Port int `json:"port"`

Voir le fichier

@ -26,4 +26,3 @@ var DefaultMetainfoFetcherConfig = MetainfoFetcherConfig{
DownloadRateLimiter: 1024,
FetchNewTorrentsOnly: true, // Only fetch torrents newer than config.LastOldTorrentID
}

Voir le fichier

@ -1,9 +1,9 @@
package config
var TorrentStatus = map[int]bool{
0:true,
1:true,
2:true,
3:true,
4:true,
0: true,
1: true,
2: true,
3: true,
4: true,
}

Voir le fichier

@ -1,6 +1,5 @@
package config
/*
* Here we config the notifications options
* Uses in user model for default setting
@ -8,7 +7,7 @@ package config
* in service/user/form/form_validator.go
*/
var DefaultUserSettings = map[string]bool {
var DefaultUserSettings = map[string]bool{
"new_torrent": true,
"new_torrent_email": false,
"new_comment": true,

Voir le fichier

@ -1,8 +1,8 @@
package model
import (
"time"
"html/template"
"time"
"github.com/NyaaPantsu/nyaa/util"
)

Voir le fichier

@ -19,7 +19,7 @@ func (f File) TableName() string {
// Returns the total size of memory allocated for this struct
func (f File) Size() int {
return (2 + len(f.BencodedPath) + 1) * 8;
return (2 + len(f.BencodedPath) + 1) * 8
}
func (f *File) Path() (out []string) {
@ -36,4 +36,3 @@ func (f *File) SetPath(path []string) error {
f.BencodedPath = encoded
return nil
}

Voir le fichier

@ -11,7 +11,7 @@ type Notification struct {
Identifier string
Url string
UserID uint
// User *User `gorm:"AssociationForeignKey:UserID;ForeignKey:user_id"` // Don't think that we need it here
// User *User `gorm:"AssociationForeignKey:UserID;ForeignKey:user_id"` // Don't think that we need it here
}
func NewNotification(identifier string, c string, url string) Notification {
@ -21,4 +21,3 @@ func NewNotification(identifier string, c string, url string) Notification {
func (n *Notification) TableName() string {
return config.NotificationTableName
}

Voir le fichier

@ -87,7 +87,7 @@ func (t Torrent) TableName() string {
}
func (t *Torrent) Identifier() string {
return "torrent_"+strconv.Itoa(int(t.ID))
return "torrent_" + strconv.Itoa(int(t.ID))
}
func (t Torrent) IsNormal() bool {

Voir le fichier

@ -2,8 +2,8 @@ package model
import (
"encoding/json"
"time"
"fmt"
"time"
"github.com/NyaaPantsu/nyaa/config"
)
@ -104,7 +104,7 @@ type UserUploadsOld struct {
}
type UserSettings struct {
Settings map[string]bool`json:"settings"`
Settings map[string]bool `json:"settings"`
}
func (c UserUploadsOld) TableName() string {
@ -126,8 +126,8 @@ func (u *User) ToJSON() UserJSON {
/* User Settings */
func(s *UserSettings) Get(key string) bool {
if val, ok:= s.Settings[key]; ok {
func (s *UserSettings) Get(key string) bool {
if val, ok := s.Settings[key]; ok {
return val
} else {
return config.DefaultUserSettings[key]
@ -156,7 +156,7 @@ func (s *UserSettings) Initialize() {
func (u *User) SaveSettings() {
byteArray, err := json.Marshal(u.Settings)
if (err != nil) {
if err != nil {
fmt.Print(err)
}
u.UserSettings = string(byteArray)

Voir le fichier

@ -1,10 +1,10 @@
package router
import (
"fmt"
"net/http"
"os"
"path/filepath"
"net/http"
"fmt"
"time"
"github.com/NyaaPantsu/nyaa/model"
@ -55,4 +55,3 @@ func DatabaseDumpHandler(w http.ResponseWriter, r *http.Request) {
log.Errorf("DatabaseDump(): %s", err)
}
}

Voir le fichier

@ -31,7 +31,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
maxPerPage = 50 // default Value maxPerPage
}
}
if (deleteVar != nil) {
if deleteVar != nil {
messages.AddInfoTf("infos", "torrent_deleted", "")
}
pagenum := 1

Voir le fichier

@ -146,7 +146,7 @@ func TorrentsListPanel(w http.ResponseWriter, r *http.Request) {
messages := msg.GetMessages(r)
common := NewCommonVariables(r)
common.Navigation = Navigation{ count, int(searchParam.Max), pagenum, "mod_tlist_page"}
common.Navigation = Navigation{count, int(searchParam.Max), pagenum, "mod_tlist_page"}
common.Search = searchForm
ptlv := PanelTorrentListVbs{common, torrents, messages.GetAllErrors(), messages.GetAllInfos()}
err = panelTorrentList.ExecuteTemplate(w, "admin_index.html", ptlv)
@ -234,7 +234,7 @@ func CommentsListPanel(w http.ResponseWriter, r *http.Request) {
func TorrentEditModPanel(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id)
messages:= msg.GetMessages(r)
messages := msg.GetMessages(r)
torrentJson := torrent.ToJSON()
uploadForm := NewUploadForm()
@ -341,8 +341,6 @@ func TorrentsPostListPanel(w http.ResponseWriter, r *http.Request) {
TorrentsListPanel(w, r)
}
/*
* Controller to modify multiple torrents and can be used by the owner of the torrent or admin
*/

Voir le fichier

@ -32,7 +32,6 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
}
}
searchParam, torrents, nbTorrents, err := search.SearchByQuery(r, pagenum)
if err != nil {
util.SendError(w, err, 400)

Voir le fichier

@ -175,7 +175,7 @@ var FuncMap = template.FuncMap{
}
},
"fileSize": func(filesize int64, T languages.TemplateTfunc) template.HTML {
if (filesize == 0) {
if filesize == 0 {
return T("unknown")
}
return template.HTML(util.FormatFilesize(filesize))
@ -183,7 +183,7 @@ var FuncMap = template.FuncMap{
"makeCaptchaData": func(captchaID string, T languages.TemplateTfunc) captchaData {
return captchaData{captchaID, T}
},
"DefaultUserSettings": func(s string) bool{
"DefaultUserSettings": func(s string) bool {
return config.DefaultUserSettings[s]
},
}

Voir le fichier

@ -201,4 +201,3 @@ func NewCommonVariables(r *http.Request) CommonTemplateVariables {
Route: mux.CurrentRoute(r),
}
}

Voir le fichier

@ -80,7 +80,7 @@ func UploadPostHandler(w http.ResponseWriter, r *http.Request) {
url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.ID), 10))
if (user.ID > 0 && config.DefaultUserSettings["new_torrent"]) { // If we are a member and notifications for new torrents are enabled
if user.ID > 0 && config.DefaultUserSettings["new_torrent"] { // If we are a member and notifications for new torrents are enabled
userService.GetLikings(user) // We populate the liked field for users
if len(user.Likings) > 0 { // If we are followed by at least someone
for _, follower := range user.Likings {

Voir le fichier

@ -147,7 +147,6 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
userForm := form.UserForm{}
userSettingsForm := form.UserSettingsForm{}
Ts, _ := languages.GetTfuncAndLanguageFromRequest(r)
if len(r.PostFormValue("email")) > 0 {
@ -277,7 +276,7 @@ func UserLoginPostHandler(w http.ResponseWriter, r *http.Request) {
}
}
if messages.HasErrors() {
UserLoginFormHandler(w,r)
UserLoginFormHandler(w, r)
}
}

Voir le fichier

@ -149,7 +149,7 @@ func ReportTorrentHandler(w http.ResponseWriter, r *http.Request) {
func TorrentEditUserPanel(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
torrent, _ := torrentService.GetTorrentById(id)
messages:= msg.GetMessages(r)
messages := msg.GetMessages(r)
currentUser := GetUser(r)
if userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
uploadForm := NewUploadForm()
@ -210,7 +210,7 @@ func TorrentDeleteUserPanel(w http.ResponseWriter, r *http.Request) {
torrent, _ := torrentService.GetTorrentById(id)
if userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
_, err := torrentService.DeleteTorrent(id)
if (err == nil) {
if err == nil {
//delete reports of torrent
whereParams := serviceBase.CreateWhereParams("torrent_id = ?", id)
reports, _, _ := reportService.GetTorrentReportsOrderBy(&whereParams, "", 0, 0)

Voir le fichier

@ -12,8 +12,8 @@ type wrappedResponseWriter struct {
}
func (wrw *wrappedResponseWriter) WriteHeader(status int) {
if status==404 {
wrw.Ignore=true
if status == 404 {
wrw.Ignore = true
} else {
wrw.Rw.WriteHeader(status)
}
@ -30,7 +30,6 @@ func (wrw *wrappedResponseWriter) Header() http.Header {
return wrw.Rw.Header()
}
type wrappedHandler struct {
h http.Handler
}
@ -38,7 +37,7 @@ type wrappedHandler struct {
func (wh *wrappedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
wrw := wrappedResponseWriter{w, false}
wh.h.ServeHTTP(&wrw, r)
if wrw.Ignore==true {
if wrw.Ignore == true {
wrw.Rw.Header().Del("Content-Encoding")
wrw.Rw.Header().Del("Vary")
wrw.Rw.Header().Set("Content-Type", "text/html; charset=utf-8")
@ -52,8 +51,8 @@ func wrapHandler(handler http.Handler) http.Handler {
// Make sure the user is a moderator, otherwise return forbidden
// TODO Clean this
func WrapModHandler(handler func (w http.ResponseWriter, r *http.Request)) (func (w http.ResponseWriter, r *http.Request)) {
return func (w http.ResponseWriter, r *http.Request) {
func WrapModHandler(handler func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
currentUser := GetUser(r)
if userPermission.HasAdmin(currentUser) {
handler(w, r)

Voir le fichier

@ -5,14 +5,13 @@ import (
"github.com/NyaaPantsu/nyaa/model"
)
func NotifyUser(user *model.User, name string, msg string, url string, email bool) {
if (user.ID > 0) {
if user.ID > 0 {
notification := model.NewNotification(name, msg, url)
notification.UserID = user.ID
db.ORM.Create(&notification)
// TODO: Email notification
/* if email {
/* if email {
}*/
}

Voir le fichier

@ -233,9 +233,9 @@ func (fetcher *MetainfoFetcher) fillQueue() {
tFiles := config.FilesTableName
tTorrents := config.TorrentsTableName
// Select the torrents with no filesize, or without any rows with torrent_id in the files table...
queryString := "((filesize IS NULL OR filesize = 0) OR ("+tTorrents+".torrent_id NOT "+
"IN (SELECT "+tFiles+".torrent_id FROM "+tFiles+" WHERE "+tFiles+
".torrent_id = "+tTorrents+".torrent_id)))"
queryString := "((filesize IS NULL OR filesize = 0) OR (" + tTorrents + ".torrent_id NOT " +
"IN (SELECT " + tFiles + ".torrent_id FROM " + tFiles + " WHERE " + tFiles +
".torrent_id = " + tTorrents + ".torrent_id)))"
var whereParamsArgs []interface{}
// that are newer than maxDays...

Voir le fichier

@ -11,7 +11,7 @@ import (
"github.com/NyaaPantsu/nyaa/model"
"github.com/NyaaPantsu/nyaa/service"
"github.com/NyaaPantsu/nyaa/util"
// "github.com/NyaaPantsu/nyaa/util/log"
// "github.com/NyaaPantsu/nyaa/util/log"
)
/* Function to interact with Models

Voir le fichier

@ -19,7 +19,7 @@ import (
const (
CookieName = "session"
UserContextKey = "user"
)
)
// If you want to keep login cookies between restarts you need to make these permanent
var cookieHandler = securecookie.New(

Voir le fichier

@ -31,6 +31,7 @@ var htmlFlags = 0 |
func init() {
HtmlMdRenderer = md.HtmlRenderer(htmlFlags, "", "")
}
var HtmlMdRenderer md.Renderer
// TODO: restrict certain types of markdown
@ -38,13 +39,12 @@ func MarkdownToHTML(markdown string) template.HTML {
if len(markdown) >= 3 && markdown[:3] == ">" {
markdown = ">" + markdown[3:]
}
markdown = strings.Replace(markdown,"\n>","\n>", -1)
markdown = strings.Replace(markdown, "\n>", "\n>", -1)
unsafe := md.MarkdownOptions([]byte(markdown), HtmlMdRenderer, md.Options{Extensions: mdOptions})
html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
return template.HTML(html)
}
/*
* Sanitize a message passed as a string according to a setted model or allowing a set of html tags and output a string
*/

Voir le fichier

@ -1,10 +1,11 @@
package Messages
import (
"github.com/gorilla/context"
"fmt"
"net/http"
"github.com/nicksnyder/go-i18n/i18n"
"github.com/NyaaPantsu/nyaa/util/languages"
"github.com/gorilla/context"
"github.com/nicksnyder/go-i18n/i18n"
"net/http"
)
const MessagesKey = "messages"
@ -26,24 +27,24 @@ func GetMessages(r *http.Request) *Messages {
} else {
context.Set(r, MessagesKey, &Messages{})
T, _ := languages.GetTfuncAndLanguageFromRequest(r)
return &Messages{make(map[string][]string),make(map[string][]string), r, T}
return &Messages{make(map[string][]string), make(map[string][]string), r, T}
}
}
func (mes *Messages) AddError(name string, msg string) {
if (mes.Errors == nil) {
if mes.Errors == nil {
mes.Errors = make(map[string][]string)
}
mes.Errors[name] = append(mes.Errors[name], msg)
mes.setMessagesInContext()
}
func (mes *Messages) AddErrorf( name string, msg string, args ...interface{}) {
func (mes *Messages) AddErrorf(name string, msg string, args ...interface{}) {
mes.AddError(name, fmt.Sprintf(msg, args...))
}
func (mes *Messages) AddErrorTf( name string, id string, args ...interface{}) {
func (mes *Messages) AddErrorTf(name string, id string, args ...interface{}) {
mes.AddErrorf(name, mes.T(id), args...)
}
func (mes *Messages) AddErrorT( name string, id string) {
func (mes *Messages) AddErrorT(name string, id string) {
mes.AddError(name, mes.T(id))
}
func (mes *Messages) ImportFromError(name string, err error) {
@ -51,7 +52,7 @@ func (mes *Messages) ImportFromError(name string, err error) {
}
func (mes *Messages) AddInfo(name string, msg string) {
if (mes.Infos == nil) {
if mes.Infos == nil {
mes.Infos = make(map[string][]string)
}
mes.Infos[name] = append(mes.Infos[name], msg)