go fmt all the code
Cette révision appartient à :
Parent
58631c6bd4
révision
b4b1b1c26a
36 fichiers modifiés avec 283 ajouts et 298 suppressions
|
@ -5,7 +5,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type Status uint8
|
type Status uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -109,7 +108,6 @@ func (c *Category) Parse(s string) (ok bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// deprecated for TorrentParam
|
// deprecated for TorrentParam
|
||||||
type SearchParam struct {
|
type SearchParam struct {
|
||||||
Order bool // True means acsending
|
Order bool // True means acsending
|
||||||
|
|
|
@ -32,4 +32,3 @@ func (p *TorrentParam) Clone() TorrentParam {
|
||||||
NameLike: p.NameLike,
|
NameLike: p.NameLike,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ func IsSukebei() bool {
|
||||||
return TorrentsTableName == "sukebei_torrents"
|
return TorrentsTableName == "sukebei_torrents"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
|
|
|
@ -26,4 +26,3 @@ var DefaultMetainfoFetcherConfig = MetainfoFetcherConfig{
|
||||||
DownloadRateLimiter: 1024,
|
DownloadRateLimiter: 1024,
|
||||||
FetchNewTorrentsOnly: true, // Only fetch torrents newer than config.LastOldTorrentID
|
FetchNewTorrentsOnly: true, // Only fetch torrents newer than config.LastOldTorrentID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Here we config the notifications options
|
* Here we config the notifications options
|
||||||
* Uses in user model for default setting
|
* Uses in user model for default setting
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/util"
|
"github.com/NyaaPantsu/nyaa/util"
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (f File) TableName() string {
|
||||||
|
|
||||||
// Returns the total size of memory allocated for this struct
|
// Returns the total size of memory allocated for this struct
|
||||||
func (f File) Size() int {
|
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) {
|
func (f *File) Path() (out []string) {
|
||||||
|
@ -36,4 +36,3 @@ func (f *File) SetPath(path []string) error {
|
||||||
f.BencodedPath = encoded
|
f.BencodedPath = encoded
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,4 +21,3 @@ func NewNotification(identifier string, c string, url string) Notification {
|
||||||
func (n *Notification) TableName() string {
|
func (n *Notification) TableName() string {
|
||||||
return config.NotificationTableName
|
return config.NotificationTableName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/config"
|
"github.com/NyaaPantsu/nyaa/config"
|
||||||
)
|
)
|
||||||
|
@ -156,7 +156,7 @@ func (s *UserSettings) Initialize() {
|
||||||
func (u *User) SaveSettings() {
|
func (u *User) SaveSettings() {
|
||||||
byteArray, err := json.Marshal(u.Settings)
|
byteArray, err := json.Marshal(u.Settings)
|
||||||
|
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
fmt.Print(err)
|
fmt.Print(err)
|
||||||
}
|
}
|
||||||
u.UserSettings = string(byteArray)
|
u.UserSettings = string(byteArray)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package router
|
package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"net/http"
|
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/NyaaPantsu/nyaa/model"
|
"github.com/NyaaPantsu/nyaa/model"
|
||||||
|
@ -55,4 +55,3 @@ func DatabaseDumpHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Errorf("DatabaseDump(): %s", err)
|
log.Errorf("DatabaseDump(): %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
maxPerPage = 50 // default Value maxPerPage
|
maxPerPage = 50 // default Value maxPerPage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (deleteVar != nil) {
|
if deleteVar != nil {
|
||||||
messages.AddInfoTf("infos", "torrent_deleted", "")
|
messages.AddInfoTf("infos", "torrent_deleted", "")
|
||||||
}
|
}
|
||||||
pagenum := 1
|
pagenum := 1
|
||||||
|
|
|
@ -341,8 +341,6 @@ func TorrentsPostListPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
TorrentsListPanel(w, r)
|
TorrentsListPanel(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Controller to modify multiple torrents and can be used by the owner of the torrent or admin
|
* Controller to modify multiple torrents and can be used by the owner of the torrent or admin
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,7 +32,6 @@ func SearchHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
searchParam, torrents, nbTorrents, err := search.SearchByQuery(r, pagenum)
|
searchParam, torrents, nbTorrents, err := search.SearchByQuery(r, pagenum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.SendError(w, err, 400)
|
util.SendError(w, err, 400)
|
||||||
|
|
|
@ -175,7 +175,7 @@ var FuncMap = template.FuncMap{
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"fileSize": func(filesize int64, T languages.TemplateTfunc) template.HTML {
|
"fileSize": func(filesize int64, T languages.TemplateTfunc) template.HTML {
|
||||||
if (filesize == 0) {
|
if filesize == 0 {
|
||||||
return T("unknown")
|
return T("unknown")
|
||||||
}
|
}
|
||||||
return template.HTML(util.FormatFilesize(filesize))
|
return template.HTML(util.FormatFilesize(filesize))
|
||||||
|
|
|
@ -201,4 +201,3 @@ func NewCommonVariables(r *http.Request) CommonTemplateVariables {
|
||||||
Route: mux.CurrentRoute(r),
|
Route: mux.CurrentRoute(r),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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))
|
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
|
userService.GetLikings(user) // We populate the liked field for users
|
||||||
if len(user.Likings) > 0 { // If we are followed by at least someone
|
if len(user.Likings) > 0 { // If we are followed by at least someone
|
||||||
for _, follower := range user.Likings {
|
for _, follower := range user.Likings {
|
||||||
|
|
|
@ -147,7 +147,6 @@ func UserProfileFormHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
userForm := form.UserForm{}
|
userForm := form.UserForm{}
|
||||||
userSettingsForm := form.UserSettingsForm{}
|
userSettingsForm := form.UserSettingsForm{}
|
||||||
|
|
||||||
|
|
||||||
Ts, _ := languages.GetTfuncAndLanguageFromRequest(r)
|
Ts, _ := languages.GetTfuncAndLanguageFromRequest(r)
|
||||||
|
|
||||||
if len(r.PostFormValue("email")) > 0 {
|
if len(r.PostFormValue("email")) > 0 {
|
||||||
|
|
|
@ -210,7 +210,7 @@ func TorrentDeleteUserPanel(w http.ResponseWriter, r *http.Request) {
|
||||||
torrent, _ := torrentService.GetTorrentById(id)
|
torrent, _ := torrentService.GetTorrentById(id)
|
||||||
if userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
|
if userPermission.CurrentOrAdmin(currentUser, torrent.UploaderID) {
|
||||||
_, err := torrentService.DeleteTorrent(id)
|
_, err := torrentService.DeleteTorrent(id)
|
||||||
if (err == nil) {
|
if err == nil {
|
||||||
//delete reports of torrent
|
//delete reports of torrent
|
||||||
whereParams := serviceBase.CreateWhereParams("torrent_id = ?", id)
|
whereParams := serviceBase.CreateWhereParams("torrent_id = ?", id)
|
||||||
reports, _, _ := reportService.GetTorrentReportsOrderBy(&whereParams, "", 0, 0)
|
reports, _, _ := reportService.GetTorrentReportsOrderBy(&whereParams, "", 0, 0)
|
||||||
|
|
|
@ -30,7 +30,6 @@ func (wrw *wrappedResponseWriter) Header() http.Header {
|
||||||
return wrw.Rw.Header()
|
return wrw.Rw.Header()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type wrappedHandler struct {
|
type wrappedHandler struct {
|
||||||
h http.Handler
|
h http.Handler
|
||||||
}
|
}
|
||||||
|
@ -52,7 +51,7 @@ func wrapHandler(handler http.Handler) http.Handler {
|
||||||
|
|
||||||
// Make sure the user is a moderator, otherwise return forbidden
|
// Make sure the user is a moderator, otherwise return forbidden
|
||||||
// TODO Clean this
|
// TODO Clean this
|
||||||
func WrapModHandler(handler func (w http.ResponseWriter, r *http.Request)) (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) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
currentUser := GetUser(r)
|
currentUser := GetUser(r)
|
||||||
if userPermission.HasAdmin(currentUser) {
|
if userPermission.HasAdmin(currentUser) {
|
||||||
|
|
|
@ -5,9 +5,8 @@ import (
|
||||||
"github.com/NyaaPantsu/nyaa/model"
|
"github.com/NyaaPantsu/nyaa/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func NotifyUser(user *model.User, name string, msg string, url string, email bool) {
|
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 := model.NewNotification(name, msg, url)
|
||||||
notification.UserID = user.ID
|
notification.UserID = user.ID
|
||||||
db.ORM.Create(¬ification)
|
db.ORM.Create(¬ification)
|
||||||
|
|
|
@ -31,6 +31,7 @@ var htmlFlags = 0 |
|
||||||
func init() {
|
func init() {
|
||||||
HtmlMdRenderer = md.HtmlRenderer(htmlFlags, "", "")
|
HtmlMdRenderer = md.HtmlRenderer(htmlFlags, "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
var HtmlMdRenderer md.Renderer
|
var HtmlMdRenderer md.Renderer
|
||||||
|
|
||||||
// TODO: restrict certain types of markdown
|
// TODO: restrict certain types of markdown
|
||||||
|
@ -44,7 +45,6 @@ func MarkdownToHTML(markdown string) template.HTML {
|
||||||
return template.HTML(html)
|
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
|
* Sanitize a message passed as a string according to a setted model or allowing a set of html tags and output a string
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package Messages
|
package Messages
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"github.com/nicksnyder/go-i18n/i18n"
|
|
||||||
"github.com/NyaaPantsu/nyaa/util/languages"
|
"github.com/NyaaPantsu/nyaa/util/languages"
|
||||||
|
"github.com/gorilla/context"
|
||||||
|
"github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MessagesKey = "messages"
|
const MessagesKey = "messages"
|
||||||
|
@ -31,7 +32,7 @@ func GetMessages(r *http.Request) *Messages {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mes *Messages) AddError(name string, msg string) {
|
func (mes *Messages) AddError(name string, msg string) {
|
||||||
if (mes.Errors == nil) {
|
if mes.Errors == nil {
|
||||||
mes.Errors = make(map[string][]string)
|
mes.Errors = make(map[string][]string)
|
||||||
}
|
}
|
||||||
mes.Errors[name] = append(mes.Errors[name], msg)
|
mes.Errors[name] = append(mes.Errors[name], msg)
|
||||||
|
@ -51,7 +52,7 @@ func (mes *Messages) ImportFromError(name string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mes *Messages) AddInfo(name string, msg string) {
|
func (mes *Messages) AddInfo(name string, msg string) {
|
||||||
if (mes.Infos == nil) {
|
if mes.Infos == nil {
|
||||||
mes.Infos = make(map[string][]string)
|
mes.Infos = make(map[string][]string)
|
||||||
}
|
}
|
||||||
mes.Infos[name] = append(mes.Infos[name], msg)
|
mes.Infos[name] = append(mes.Infos[name], msg)
|
||||||
|
|
Référencer dans un nouveau ticket