Clean slate initialization of Goondex - a fast, local-first media indexer. Features: - SQLite database with WAL mode and foreign keys - Full schema for performers, studios, scenes, and tags - Many-to-many relationships via junction tables - CRUD stores for all entities with search capabilities - CLI with performer/studio/scene search commands - Pluggable scraper architecture with registry - TPDB client stub (ready for implementation) - Configuration system via YAML files - Comprehensive .gitignore and documentation Architecture: - cmd/goondex: CLI application with Cobra - cmd/goondexd: Daemon placeholder for v0.2.0 - internal/db: Database layer with stores - internal/model: Clean data models - internal/scraper: Scraper interface and TPDB client - config/: YAML configuration templates Database schema includes indexes on common query fields and uses RFC3339 timestamps for consistency. Built and tested successfully with Go 1.25.4. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package tpdb
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
)
|
|
|
|
// Client represents a TPDB API client
|
|
type Client struct {
|
|
baseURL string
|
|
apiKey string
|
|
client *http.Client
|
|
}
|
|
|
|
// NewClient creates a new TPDB client
|
|
func NewClient(baseURL, apiKey string) *Client {
|
|
return &Client{
|
|
baseURL: baseURL,
|
|
apiKey: apiKey,
|
|
client: &http.Client{
|
|
Timeout: 15 * time.Second,
|
|
},
|
|
}
|
|
}
|
|
|
|
// get performs a GET request to the TPDB API
|
|
func (c *Client) get(ctx context.Context, path string, params url.Values) ([]byte, error) {
|
|
u, err := url.Parse(c.baseURL + path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to parse URL: %w", err)
|
|
}
|
|
|
|
if params != nil {
|
|
u.RawQuery = params.Encode()
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create request: %w", err)
|
|
}
|
|
|
|
req.Header.Set("Authorization", "Bearer "+c.apiKey)
|
|
req.Header.Set("Accept", "application/json")
|
|
|
|
resp, err := c.client.Do(req)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("request failed: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
return nil, fmt.Errorf("API returned status %d", resp.StatusCode)
|
|
}
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read response: %w", err)
|
|
}
|
|
|
|
return body, nil
|
|
}
|
|
|
|
// SearchResponse represents a generic TPDB search response
|
|
type SearchResponse struct {
|
|
Data []json.RawMessage `json:"data"`
|
|
}
|