Skip to content

Commit bdcad4b

Browse files
committed
Closes #13, Download Link should be sent as string in JSON
1 parent 5a59628 commit bdcad4b

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

cmd/api.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/json"
2020
"net/http"
2121
"strconv"
22-
"strings"
2322

2423
"github.com/bisoncorps/gophie/engine"
2524
log "github.com/sirupsen/logrus"
@@ -48,11 +47,11 @@ func Handler(w http.ResponseWriter, r *http.Request) {
4847
} else {
4948
site = engine.GetEngine(eng)
5049
}
51-
log.Info("Using Engine ", site)
50+
51+
log.Debug("Using Engine ", site)
5252
if search != "" {
5353
log.Debug("Searching for ", search)
54-
query := strings.ReplaceAll(search, "+", " ")
55-
result = site.Search(query)
54+
result = site.Search(search)
5655
} else if list != "" {
5756
log.Debug("listing page ", list)
5857
pagenum, _ := strconv.Atoi(list)

engine/engines.go

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package engine
22

33
import (
4+
"encoding/json"
45
"errors"
56
"fmt"
67
"net/url"
7-
// "path"
88
"strconv"
99
"strings"
1010

@@ -44,10 +44,34 @@ type Movie struct {
4444
Source string // The Engine From which it is gotten from
4545
}
4646

47+
// MovieJSON : JSON structure of all downloadable movies
48+
type MovieJSON struct {
49+
Movie
50+
DownloadLink string
51+
SDownloadLink []string
52+
}
53+
4754
func (m *Movie) String() string {
4855
return fmt.Sprintf("%s (%v)", m.Title, m.Year)
4956
}
5057

58+
// MarshalJSON Json structure to return from api
59+
func (m *Movie) MarshalJSON() ([]byte, error) {
60+
var sDownloadLink []string
61+
for _, link := range m.SDownloadLink {
62+
sDownloadLink = append(sDownloadLink, link.String())
63+
}
64+
65+
movie := MovieJSON{
66+
Movie: *m,
67+
DownloadLink: m.DownloadLink.String(),
68+
SDownloadLink: sDownloadLink,
69+
}
70+
71+
return json.Marshal(movie)
72+
73+
}
74+
5175
// SearchResult : the results of search from engine
5276
type SearchResult struct {
5377
Query string

0 commit comments

Comments
 (0)