111 lines
3.9 KiB
Go
111 lines
3.9 KiB
Go
package store
|
|
|
|
import "context"
|
|
|
|
type Endpoint struct {
|
|
ID string `json:"id"`
|
|
URL string `json:"url"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
type Request struct {
|
|
ID string `json:"id"`
|
|
EndpointID string `json:"endpoint_id"`
|
|
Method string `json:"method"`
|
|
Path string `json:"path"`
|
|
Headers string `json:"headers"`
|
|
Query string `json:"query"`
|
|
Body []byte `json:"body"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// MockConfig holds the mock response configuration for an endpoint.
|
|
type MockConfig struct {
|
|
EndpointID string `json:"endpoint_id"`
|
|
Status int `json:"status"`
|
|
Headers map[string]string `json:"headers"`
|
|
Body []byte `json:"body"`
|
|
}
|
|
|
|
// Space represents a public or private demo space
|
|
type Space struct {
|
|
ID string `json:"id"`
|
|
Slug string `json:"slug"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
IsPublic bool `json:"isPublic"`
|
|
CreatedAt string `json:"createdAt"`
|
|
UpdatedAt string `json:"updatedAt"`
|
|
}
|
|
|
|
// Photo represents a photo in a space gallery
|
|
type Photo struct {
|
|
ID string `json:"id"`
|
|
SpaceID string `json:"spaceId"`
|
|
URL string `json:"url"`
|
|
ThumbnailURL string `json:"thumbnailUrl"`
|
|
FaceCount int `json:"faceCount"`
|
|
Metadata string `json:"metadata"`
|
|
CreatedAt string `json:"createdAt"`
|
|
}
|
|
|
|
// FaceEmbedding stores face embeddings for search
|
|
type FaceEmbedding struct {
|
|
ID string `json:"id"`
|
|
PhotoID string `json:"photoId"`
|
|
SpaceID string `json:"spaceId"`
|
|
Embedding []float32 `json:"embedding"`
|
|
BoundingBox string `json:"boundingBox"`
|
|
CreatedAt string `json:"createdAt"`
|
|
}
|
|
|
|
// RateLimit tracks rate limiting for guest face search
|
|
type RateLimit struct {
|
|
ID string `json:"id"`
|
|
IPAddress string `json:"ipAddress"`
|
|
SpaceID string `json:"spaceId"`
|
|
RequestCount int `json:"requestCount"`
|
|
WindowStart string `json:"windowStart"`
|
|
CreatedAt string `json:"createdAt"`
|
|
}
|
|
|
|
type Repository interface {
|
|
// Endpoint operations
|
|
CreateEndpoint(ctx context.Context, url string) (*Endpoint, error)
|
|
GetEndpoint(ctx context.Context, id string) (*Endpoint, error)
|
|
AppendRequest(ctx context.Context, endpointID string, req *Request) error
|
|
GetRequest(ctx context.Context, id string) (*Request, error)
|
|
ListRequests(ctx context.Context, endpointID string, limit int) ([]*Request, error)
|
|
SearchRequests(ctx context.Context, endpointID string, query string, limit int) ([]*Request, error)
|
|
GetMock(ctx context.Context, endpointID string) (*MockConfig, error)
|
|
SetMock(ctx context.Context, mock *MockConfig) error
|
|
|
|
// Space operations
|
|
CreateSpace(ctx context.Context, space *Space) (*Space, error)
|
|
GetSpaceBySlug(ctx context.Context, slug string) (*Space, error)
|
|
UpdateSpace(ctx context.Context, space *Space) (*Space, error)
|
|
DeleteSpace(ctx context.Context, id string) error
|
|
ListPublicSpaces(ctx context.Context) ([]*Space, error)
|
|
|
|
// Photo operations
|
|
CreatePhoto(ctx context.Context, photo *Photo) (*Photo, error)
|
|
GetPhoto(ctx context.Context, id string) (*Photo, error)
|
|
ListPhotosBySpace(ctx context.Context, spaceID string, limit int) ([]*Photo, error)
|
|
DeletePhoto(ctx context.Context, id string) error
|
|
|
|
// Face embedding operations
|
|
CreateFaceEmbedding(ctx context.Context, embedding *FaceEmbedding) (*FaceEmbedding, error)
|
|
ListFaceEmbeddingsBySpace(ctx context.Context, spaceID string) ([]*FaceEmbedding, error)
|
|
SearchFaceEmbeddings(ctx context.Context, spaceID string, embedding []float32, limit int) ([]*FaceEmbedding, error)
|
|
|
|
// Rate limiting operations
|
|
CheckRateLimit(ctx context.Context, ipAddress, spaceID string, limit, windowMinutes int) (bool, error)
|
|
IncrementRateLimit(ctx context.Context, ipAddress, spaceID string, windowMinutes int) error
|
|
|
|
Close() error
|
|
Ping(ctx context.Context) error
|
|
}
|
|
|
|
var _ Repository = (*sqliteRepo)(nil)
|