Files
torrent-indexer/api/index.go

72 lines
1.8 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"
2023-10-01 20:27:44 +00:00
"github.com/felipemarinho97/torrent-indexer/schema"
2022-04-21 15:14:49 -03:00
)
type Indexer struct {
redis *cache.Redis
}
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 []IndexedTorrent `json:"results"`
Count int `json:"count"`
}
2023-10-01 20:27:44 +00:00
type IndexedTorrent struct {
Title string `json:"title"`
OriginalTitle string `json:"original_title"`
Details string `json:"details"`
Year string `json:"year"`
2024-02-12 17:04:12 +00:00
IMDB string `json:"imdb"`
2023-10-01 20:27:44 +00:00
Audio []schema.Audio `json:"audio"`
MagnetLink string `json:"magnet_link"`
Date time.Time `json:"date"`
InfoHash string `json:"info_hash"`
Trackers []string `json:"trackers"`
Size string `json:"size"`
LeechCount int `json:"leech_count"`
SeedCount int `json:"seed_count"`
}
func NewIndexers(redis *cache.Redis) *Indexer {
return &Indexer{
redis: redis,
}
}
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)
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",
},
},
2023-10-01 20:27:44 +00:00
"/indexers/bludv": map[string]interface{}{
"method": "GET",
"description": "Indexer for bludv",
"query_params": map[string]string{
"q": "search query",
},
},
},
})
2022-04-21 15:14:49 -03:00
}