server

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package server implements an ATproto labeler, using SQLite as storage.

Example usage:

    server, err := server.New(ctx, config.DBFile, config.DID, key)
    if err != nil {
	       return fmt.Errorf("instantiating a server: %w", err)
    }
    http.Handle("/xrpc/com.atproto.label.subscribeLabels", server.Subscribe())
    http.Handle("/xrpc/com.atproto.label.queryLabels", server.Query())
    http.ListenAndServe(":8080", nil)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Seq int64  `gorm:"type:INTEGER PRIMARY KEY;primaryKey"`
	Cts string `gorm:"not null"`

	Uri string `gorm:"not null;index:idx_lookups,priority:1"`
	Val string `gorm:"not null;index:idx_lookups,priority:2"`
	Src string `gorm:"not null;index:idx_lookups,priority:3"`
	Cid string `gorm:"index:idx_lookups,priority:4"`

	Exp string
	Neg bool `gorm:"default:false"`
}

func (*Entry) FromLabel added in v0.3.0

func (e *Entry) FromLabel(seq int64, other comatproto.LabelDefs_Label) *Entry

func (Entry) TableName added in v0.3.0

func (Entry) TableName() string

func (*Entry) ToLabel added in v0.3.0

func (e *Entry) ToLabel() comatproto.LabelDefs_Label

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewWithConfig added in v0.3.0

func NewWithConfig(ctx context.Context, cfg *config.Config) (*Server, error)

NewWithConfig creates a new server instance using parameters provided in the config.

func (*Server) AddLabel

func (s *Server) AddLabel(ctx context.Context, label comatproto.LabelDefs_Label) (bool, error)

AddLabel updates the internal state and writes the label to the database.

Note that it will ignore values that have no effect (e.g., if the label already exists, or trying to negate a label that doesn't exist). Return value indicates if there was a change or not.

func (*Server) ImportEntries added in v0.2.0

func (s *Server) ImportEntries(entries map[int64]comatproto.LabelDefs_Label) error

ImportEntries populates an empty server with the given entries. Each entry is written at a sequence number equal to the map key.

func (*Server) IsEmpty added in v0.2.0

func (s *Server) IsEmpty() (bool, error)

IsEmpty returns true if there are no labels in the database.

func (*Server) LabelEntries

func (s *Server) LabelEntries(ctx context.Context, labelName string) ([]comatproto.LabelDefs_Label, error)

LabelEntries returns all non-negated label entries for the provided label name. Does not filter out expired entries.

func (*Server) Query

func (s *Server) Query() http.Handler

Query returns HTTP handler that implements [com.atproto.label.queryLabels](https://docs.bsky.app/docs/api/com-atproto-label-query-labels) XRPC method.

func (*Server) SetAllowedLabels

func (s *Server) SetAllowedLabels(labels []string)

SetAllowedLabels limits what label values can be used for new labels. Old existing labels are not affected, and label negations are also always allowed. By default all labels are allowed.

func (*Server) Subscribe

func (s *Server) Subscribe() http.Handler

Subscribe returns HTTP handler that implements [com.atproto.label.subscribeLabels](https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/label/subscribeLabels.json) XRPC method.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL