41fb033d30
- Replace Axum with Chi router - Replace sqlx with pgx for PostgreSQL - Replace tonic/prost with grpc-go - Replace tracing with zerolog - Update flake.nix for Go build with protoc generation - Preserve all existing endpoints and functionality Stack: Chi, pgx, grpc-go, zerolog, yaml.v3
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package indexer
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
type MusicSearchCriteria struct {
|
|
Artist string
|
|
Album *string
|
|
Year *uint32
|
|
Limit int
|
|
Offset int
|
|
}
|
|
|
|
func (c *MusicSearchCriteria) CleanArtist() string {
|
|
return cleanSearchTerm(c.Artist)
|
|
}
|
|
|
|
func (c *MusicSearchCriteria) CleanAlbum() *string {
|
|
if c.Album == nil {
|
|
return nil
|
|
}
|
|
cleaned := cleanSearchTerm(*c.Album)
|
|
return &cleaned
|
|
}
|
|
|
|
var cleanRegex = regexp.MustCompile(`[^\w\s]`)
|
|
|
|
func cleanSearchTerm(s string) string {
|
|
s = cleanRegex.ReplaceAllString(s, " ")
|
|
fields := strings.Fields(s)
|
|
return strings.Join(fields, " ")
|
|
}
|
|
|
|
type SearchResult struct {
|
|
GUID string `json:"guid"`
|
|
Title string `json:"title"`
|
|
DownloadURL string `json:"download_url"`
|
|
InfoURL *string `json:"info_url,omitempty"`
|
|
Size uint64 `json:"size"`
|
|
PublishDate *string `json:"publish_date,omitempty"`
|
|
Artist *string `json:"artist,omitempty"`
|
|
Album *string `json:"album,omitempty"`
|
|
Year *uint32 `json:"year,omitempty"`
|
|
Label *string `json:"label,omitempty"`
|
|
Seeders *int `json:"seeders,omitempty"`
|
|
Leechers *int `json:"leechers,omitempty"`
|
|
Grabs *int `json:"grabs,omitempty"`
|
|
Infohash *string `json:"infohash,omitempty"`
|
|
MagnetURL *string `json:"magnet_url,omitempty"`
|
|
Indexer string `json:"indexer"`
|
|
Categories []uint32 `json:"categories"`
|
|
}
|