Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

throw in the description with some sanitizatoin

Cette révision appartient à :
Andrew Zhao 2017-05-06 22:18:41 -07:00
Parent e04b5fc01b
révision f5a28e47fe
3 fichiers modifiés avec 6 ajouts et 3 suppressions

Voir le fichier

@ -30,7 +30,7 @@ type Torrents struct {
Date int64 `gorm:"column:date"`
Downloads int `gorm:"column:downloads"`
Filesize int64 `gorm:"column:filesize"`
Description []byte `gorm:"column:description"`
Description string `gorm:"column:description"`
Comments []byte `gorm:"column:comments"`
}

Voir le fichier

@ -5,6 +5,7 @@ import (
"errors"
"github.com/ewhal/nyaa/util"
"github.com/ewhal/nyaa/util/metainfo"
"github.com/microcosm-cc/bluemonday"
"github.com/zeebo/bencode"
"net/http"
"net/url"
@ -52,6 +53,8 @@ var ErrInvalidTorrentDescription = errors.New("torrent description is invalid")
// error indicating a torrent's category is invalid
var ErrInvalidTorrentCategory = errors.New("torrent category is invalid")
var p = bluemonday.UGCPolicy()
/**
UploadForm.ExtractInfo takes an http request and computes all fields for this form
*/
@ -64,7 +67,7 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
// trim whitespaces
f.Name = util.TrimWhitespaces(f.Name)
f.Description = util.TrimWhitespaces(f.Description)
f.Description = p.Sanitize(util.TrimWhitespaces(f.Description))
f.Magnet = util.TrimWhitespaces(f.Magnet)
if len(f.Name) == 0 {

Voir le fichier

@ -33,7 +33,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
Status: 1,
Hash: uploadForm.Infohash,
Date: time.Now().Unix(),
Description: []byte{},
Description: uploadForm.Description,
Comments: []byte{}}
fmt.Printf("%+v\n", torrent)
db.ORM.Create(&torrent)