-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* new: feat: add search support with meilisearch * new: feat: add search interface * new: feat: add new audio mappings * chg: fix: add meilisearch docs * chg: fix: lint issues * chg: feat: add br flag * chg: fix: use the same user agent * chg: fix: bludv (again) * chg: fix: lint issue
- Loading branch information
1 parent
0a702d1
commit 88d6d50
Showing
16 changed files
with
478 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package handler | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strconv" | ||
|
||
meilisearch "github.com/felipemarinho97/torrent-indexer/search" | ||
) | ||
|
||
// MeilisearchHandler handles HTTP requests for Meilisearch integration. | ||
type MeilisearchHandler struct { | ||
Module *meilisearch.SearchIndexer | ||
} | ||
|
||
// NewMeilisearchHandler creates a new instance of MeilisearchHandler. | ||
func NewMeilisearchHandler(module *meilisearch.SearchIndexer) *MeilisearchHandler { | ||
return &MeilisearchHandler{Module: module} | ||
} | ||
|
||
// SearchTorrentHandler handles the searching of torrent items. | ||
func (h *MeilisearchHandler) SearchTorrentHandler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method != http.MethodGet { | ||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) | ||
return | ||
} | ||
|
||
query := r.URL.Query().Get("q") | ||
if query == "" { | ||
http.Error(w, "Query parameter 'q' is required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
limitStr := r.URL.Query().Get("limit") | ||
limit := 10 // Default limit | ||
if limitStr != "" { | ||
var err error | ||
limit, err = strconv.Atoi(limitStr) | ||
if err != nil || limit <= 0 { | ||
http.Error(w, "Invalid limit parameter", http.StatusBadRequest) | ||
return | ||
} | ||
} | ||
|
||
results, err := h.Module.SearchTorrent(query, limit) | ||
if err != nil { | ||
http.Error(w, "Failed to search torrents", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
if err := json.NewEncoder(w).Encode(results); err != nil { | ||
http.Error(w, "Failed to encode response", http.StatusInternalServerError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.