Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge pull request #189 from sfan5/implying

changes
Cette révision appartient à :
PantsuDev 2017-05-09 08:45:46 +10:00 révisé par GitHub
révision 17186a070e
4 fichiers modifiés avec 23 ajouts et 6 suppressions

Voir le fichier

@ -10,6 +10,11 @@ import (
"os"
)
const (
// Highest torrent ID that was copied from nyaa
LastOldTorrentId = 923000
)
type Config struct {
Host string `json: "host"`
Port int `json: "port"`

Voir le fichier

@ -4,5 +4,5 @@ const (
// TorrentFileStorage = "/var/tmp/torrent_outgoing"
TorrentFileStorage = ""
//disable uploads by default
UploadsDisabled = 1
UploadsDisabled = 0
)

Voir le fichier

@ -10,6 +10,7 @@ import (
"github.com/ewhal/nyaa/db"
"github.com/ewhal/nyaa/model"
"github.com/ewhal/nyaa/service/captcha"
"github.com/ewhal/nyaa/service/user"
"github.com/ewhal/nyaa/util/languages"
"github.com/gorilla/mux"
)
@ -26,7 +27,10 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
// validation is done in ExtractInfo()
err = uploadForm.ExtractInfo(r)
if err == nil {
user, _, err := userService.RetrieveCurrentUser(r)
if err != nil {
fmt.Printf("error %+v\n", err)
}
//add to db and redirect depending on result
torrent := model.Torrents{
Name: uploadForm.Name,
@ -36,7 +40,8 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
Hash: uploadForm.Infohash,
Date: time.Now(),
Filesize: uploadForm.Filesize, // FIXME: should set to NULL instead of 0
Description: uploadForm.Description}
Description: uploadForm.Description,
UploaderId: user.Id}
db.ORM.Create(&torrent)
fmt.Printf("%+v\n", torrent)
url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.Id), 10))

Voir le fichier

@ -44,10 +44,17 @@ func GetFeeds() []model.Feed {
func GetTorrentById(id string) (model.Torrents, error) {
var torrent model.Torrents
id_int, err := strconv.Atoi(id)
if err != nil {
return torrent, err
}
if db.ORM.Where("torrent_id = ?", id).
Preload("Comments").Preload("OldComments").
Find(&torrent).RecordNotFound() {
tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments")
if id_int <= config.LastOldTorrentId {
// only preload old comments if they could actually exist
tmp = tmp.Preload("OldComments")
}
if tmp.Find(&torrent).RecordNotFound() {
return torrent, errors.New("Article is not found.")
}
// .Preload("Comments.User") doesn't work