From defb8a6003e9b45cac3241aa366f11ea68547340 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Thu, 11 May 2017 04:07:39 +0200 Subject: [PATCH 1/3] Possible Fixes for dup torrent --- router/uploadHandler.go | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/router/uploadHandler.go b/router/uploadHandler.go index 5d964dd7..dafb7c0b 100644 --- a/router/uploadHandler.go +++ b/router/uploadHandler.go @@ -39,25 +39,32 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) { } else if user.Status == 1 { status = 3 // mark as trusted if user is trusted } - //add to db and redirect depending on result - torrent := model.Torrent{ - Name: uploadForm.Name, - Category: uploadForm.CategoryID, - SubCategory: uploadForm.SubCategoryID, - Status: status, - Hash: uploadForm.Infohash, - Date: time.Now(), - Filesize: uploadForm.Filesize, - 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)) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) + var sameTorrents int + db.ORM.Model(&model.Torrent{}).Where("torrent_hash = ?", uploadForm.Infohash).Count(&sameTorrents) + if (sameTorrents > 0) { + //add to db and redirect depending on result + torrent := model.Torrent{ + Name: uploadForm.Name, + Category: uploadForm.CategoryID, + SubCategory: uploadForm.SubCategoryID, + Status: status, + Hash: uploadForm.Infohash, + Date: time.Now(), + Filesize: uploadForm.Filesize, + 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)) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + http.Redirect(w, r, url.String(), 302) + } else { + http.Error(w, fmt.Errorf("Torrent already in database!").Error(), http.StatusInternalServerError) return } - http.Redirect(w, r, url.String(), 302) } else if r.Method == "GET" { uploadForm.CaptchaID = captcha.GetID() htv := UploadTemplateVariables{uploadForm, NewSearchForm(), Navigation{}, GetUser(r), r.URL, mux.CurrentRoute(r)} From a94c4c08b0fbbf4fe19d33c6d62e34d4928a4e08 Mon Sep 17 00:00:00 2001 From: akuma06 Date: Thu, 11 May 2017 04:16:37 +0200 Subject: [PATCH 2/3] Fix typo --- router/uploadHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/uploadHandler.go b/router/uploadHandler.go index dafb7c0b..8706ebe5 100644 --- a/router/uploadHandler.go +++ b/router/uploadHandler.go @@ -41,7 +41,7 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) { } var sameTorrents int db.ORM.Model(&model.Torrent{}).Where("torrent_hash = ?", uploadForm.Infohash).Count(&sameTorrents) - if (sameTorrents > 0) { + if (sameTorrents == 0) { //add to db and redirect depending on result torrent := model.Torrent{ Name: uploadForm.Name, From f22b7e5333cdddd8cd2048d8bfec8961a86a470f Mon Sep 17 00:00:00 2001 From: akuma06 Date: Thu, 11 May 2017 04:20:16 +0200 Subject: [PATCH 3/3] Update view.html --- templates/view.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/view.html b/templates/view.html index a8467a70..6de44deb 100644 --- a/templates/view.html +++ b/templates/view.html @@ -94,7 +94,7 @@ {{end}}
- {{.CreatedAt.Year}}/{{.CreatedAt.Month}}/{{.CreatedAt.Day}} + {{.Date.Year}}/{{.Date.Month}}/{{.Date.Day}}
{{.Content}}