Files
torrent-indexer/api/index.go

107 lines
2.9 KiB
Go
Raw Permalink Normal View History

2022-04-21 15:14:49 -03:00
package handler
import (
"encoding/json"
2022-04-21 15:14:49 -03:00
"net/http"
"time"
"github.com/felipemarinho97/torrent-indexer/cache"
"github.com/felipemarinho97/torrent-indexer/monitoring"
"github.com/felipemarinho97/torrent-indexer/requester"
2023-10-01 20:27:44 +00:00
"github.com/felipemarinho97/torrent-indexer/schema"
meilisearch "github.com/felipemarinho97/torrent-indexer/search"
2022-04-21 15:14:49 -03:00
)
type Indexer struct {
redis *cache.Redis
metrics *monitoring.Metrics
requester *requester.Requster
search *meilisearch.SearchIndexer
}
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 {
Results []schema.IndexedTorrent `json:"results"`
Count int `json:"count"`
2024-02-12 17:04:12 +00:00
}
func NewIndexers(redis *cache.Redis, metrics *monitoring.Metrics, req *requester.Requster, si *meilisearch.SearchIndexer) *Indexer {
return &Indexer{
redis: redis,
metrics: metrics,
requester: req,
search: si,
}
}
2022-04-21 15:14:49 -03:00
func HandlerIndex(w http.ResponseWriter, r *http.Request) {
currentTime := time.Now().Format(time.RFC850)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
err := json.NewEncoder(w).Encode(map[string]interface{}{
"time": currentTime,
"endpoints": map[string]interface{}{
"/indexers/comando_torrents": []map[string]interface{}{
{
"method": "GET",
"description": "Indexer for comando torrents",
"query_params": map[string]string{
"q": "search query",
"page": "page number",
"filter_results": "if results with similarity equals to zero should be filtered (true/false)",
},
},
},
"/indexers/bludv": []map[string]interface{}{
{
"method": "GET",
"description": "Indexer for bludv",
"query_params": map[string]string{
"q": "search query",
"page": "page number",
"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",
"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)",
},
},
},
"/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
},
},
"/search": []map[string]interface{}{
{
"method": "GET",
"description": "Search for cached torrents across all indexers",
"query_params": map[string]string{
"q": "search query",
},
},
},
},
})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
2022-04-21 15:14:49 -03:00
}