fix magnet urls
This commit is contained in:
parent
31460ee6be
commit
5a66f61a4c
3 changed files with 41 additions and 18 deletions
23
files.go
23
files.go
|
@ -5,7 +5,9 @@ import (
|
|||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -63,10 +65,13 @@ func handleFileSearch(w http.ResponseWriter, query, safe, lang string, page int)
|
|||
if len(res) > 0 {
|
||||
allErrors = false
|
||||
}
|
||||
results = append(results, res...)
|
||||
for _, r := range res {
|
||||
r.Magnet = url.QueryEscape(removeMagnetLink(r.Magnet)) // Remove "magnet:" and encode url
|
||||
results = append(results, r)
|
||||
}
|
||||
}
|
||||
|
||||
if allErrors {
|
||||
if allErrors || len(results) == 0 || results[len(results)-1].Title == "" || results[len(results)-1].Title == " " {
|
||||
results = []TorrentResult{
|
||||
{Error: "Results are currently unavailable, sorry. Please try again later."},
|
||||
}
|
||||
|
@ -108,12 +113,26 @@ func handleFileSearch(w http.ResponseWriter, query, safe, lang string, page int)
|
|||
Settings: settings,
|
||||
}
|
||||
|
||||
// Debugging: Print results before rendering template
|
||||
for _, result := range results {
|
||||
fmt.Printf("Title: %s, Magnet: %s\n", result.Title, result.Magnet)
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(w, data); err != nil {
|
||||
log.Printf("Failed to render template: %v", err)
|
||||
http.Error(w, "Failed to render template", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
//this is so fucking stupid, but it does not work otherwise
|
||||
func removeMagnetLink(magnet string) string {
|
||||
// Remove the magnet: prefix if it exists
|
||||
if strings.HasPrefix(magnet, "magnet:?") {
|
||||
magnet = strings.TrimPrefix(magnet, "magnet:?")
|
||||
}
|
||||
return magnet
|
||||
}
|
||||
|
||||
func subtract(a, b int) int {
|
||||
return a - b
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue