2022-04-21 15:14:49 -03:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
2023-09-23 17:02:55 +00:00
|
|
|
"encoding/json"
|
2022-04-21 15:14:49 -03:00
|
|
|
"net/http"
|
|
|
|
|
"time"
|
2023-09-23 17:02:55 +00:00
|
|
|
|
|
|
|
|
"github.com/felipemarinho97/torrent-indexer/cache"
|
2024-03-10 14:00:07 +00:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/monitoring"
|
2024-09-24 18:31:58 -03:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/requester"
|
2023-10-01 20:27:44 +00:00
|
|
|
"github.com/felipemarinho97/torrent-indexer/schema"
|
2024-12-13 11:54:55 -03:00
|
|
|
meilisearch "github.com/felipemarinho97/torrent-indexer/search"
|
2022-04-21 15:14:49 -03:00
|
|
|
)
|
|
|
|
|
|
2023-09-23 17:02:55 +00:00
|
|
|
type Indexer struct {
|
2024-09-24 18:31:58 -03:00
|
|
|
redis *cache.Redis
|
|
|
|
|
metrics *monitoring.Metrics
|
|
|
|
|
requester *requester.Requster
|
2024-12-13 11:54:55 -03:00
|
|
|
search *meilisearch.SearchIndexer
|
2023-09-23 17:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
2023-10-01 20:27:44 +00:00
|
|
|
type IndexerMeta struct {
|
|
|
|
|
URL string
|
|
|
|
|
SearchURL string
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-12 17:04:12 +00:00
|
|
|
type Response struct {
|
2024-12-13 11:54:55 -03:00
|
|
|
Results []schema.IndexedTorrent `json:"results"`
|
|
|
|
|
Count int `json:"count"`
|
2024-02-12 17:04:12 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-13 11:54:55 -03:00
|
|
|
func NewIndexers(redis *cache.Redis, metrics *monitoring.Metrics, req *requester.Requster, si *meilisearch.SearchIndexer) *Indexer {
|
2023-09-23 17:02:55 +00:00
|
|
|
return &Indexer{
|
2024-09-24 18:31:58 -03:00
|
|
|
redis: redis,
|
|
|
|
|
metrics: metrics,
|
|
|
|
|
requester: req,
|
2024-12-13 11:54:55 -03:00
|
|
|
search: si,
|
2023-09-23 17:02:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-21 15:14:49 -03:00
|
|
|
func HandlerIndex(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
currentTime := time.Now().Format(time.RFC850)
|
2023-09-23 17:02:55 +00:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
2024-04-28 11:52:01 -03:00
|
|
|
err := json.NewEncoder(w).Encode(map[string]interface{}{
|
2023-09-23 17:02:55 +00:00
|
|
|
"time": currentTime,
|
|
|
|
|
"endpoints": map[string]interface{}{
|
2024-06-18 12:38:08 -03:00
|
|
|
"/indexers/comando_torrents": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Indexer for comando torrents",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
2024-12-11 16:04:48 -03:00
|
|
|
"page": "page number",
|
2024-06-18 12:38:08 -03:00
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
},
|
2023-09-23 17:02:55 +00:00
|
|
|
},
|
|
|
|
|
},
|
2024-06-18 12:38:08 -03:00
|
|
|
"/indexers/bludv": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Indexer for bludv",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
2024-12-11 16:04:48 -03:00
|
|
|
"page": "page number",
|
2024-06-18 12:38:08 -03:00
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
}},
|
|
|
|
|
},
|
2024-11-18 18:54:30 -03:00
|
|
|
"/indexers/torrent-dos-filmes": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
2024-12-11 16:04:48 -03:00
|
|
|
"page": "page number",
|
2024-11-18 18:54:30 -03:00
|
|
|
"description": "Indexer for Torrent dos Filmes",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
|
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-16 15:32:27 -03:00
|
|
|
"/indexers/comandohds": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"page": "page number",
|
|
|
|
|
"description": "Indexer for Comando HDs",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
|
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-07-16 15:25:17 -03:00
|
|
|
"/indexers/starck-filmes": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"page": "page number",
|
|
|
|
|
"description": "Indexer for Starck Filmes",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
|
|
|
|
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-06-18 12:38:08 -03:00
|
|
|
"/indexers/manual": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "POST",
|
|
|
|
|
"description": "Add a manual torrent entry to the indexer for 12 hours",
|
|
|
|
|
"body": map[string]interface{}{
|
|
|
|
|
"magnetLink": "magnet link",
|
|
|
|
|
}},
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Get all manual torrents",
|
2023-10-01 20:27:44 +00:00
|
|
|
},
|
|
|
|
|
},
|
2024-12-13 11:54:55 -03:00
|
|
|
"/search": []map[string]interface{}{
|
|
|
|
|
{
|
|
|
|
|
"method": "GET",
|
|
|
|
|
"description": "Search for cached torrents across all indexers",
|
|
|
|
|
"query_params": map[string]string{
|
|
|
|
|
"q": "search query",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-09-23 17:02:55 +00:00
|
|
|
},
|
|
|
|
|
})
|
2024-04-28 11:52:01 -03:00
|
|
|
if err != nil {
|
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
|
}
|
2022-04-21 15:14:49 -03:00
|
|
|
}
|