ankiconnect

package
v0.0.0-...-58581c8 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionDenied  = "denied"
	PermissionGranted = "granted"
)

Variables

View Source
var ErrCollectionUnavailable = errors.New("collection is not available")

ErrCollectionUnavailable error indicating that action can not be processed, because anki is partially loaded (particular example is when user didn't login in profile).

View Source
var ErrInvalidAPIKey = errors.New("invalid API Key was provided")

ErrInvalidAPIKey error indicating that Anki-Connect protected by api key, and nor or invalid api key was provided

Functions

This section is empty.

Types

type AddNoteAsset

type AddNoteAsset struct {
	Asset MediaAssetRequest
	Type  MediaType
}

type AddNoteOptions

type AddNoteOptions struct {
	Deck           string
	Model          string
	DuplicateScope DuplicateScope
	DuplicateFlags DuplicateFlags
	DuplicateDeck  string
}

type AddNoteParams

type AddNoteParams struct {
	Tags   []string
	Fields map[string]string
	Assets []*AddNoteAsset
}

type Anki

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

func New

func New(o *Options) (*Anki, error)

func (*Anki) AddNote

func (a *Anki) AddNote(ctx context.Context, params *AddNoteParams, opts *AddNoteOptions) (int64, error)

AddNote creates new notes. Params specify note data and opts specifies where it belongs and how it should be added. So likely, that many notes can be added with different params and same opts.

func (*Anki) CreateDeck

func (a *Anki) CreateDeck(ctx context.Context, deckName string) (int64, error)

func (*Anki) CreateModel

func (a *Anki) CreateModel(ctx context.Context, parameters *CreateModelRequest) (int64, error)

func (*Anki) DeckNames

func (a *Anki) DeckNames(ctx context.Context) ([]string, error)

func (*Anki) DeleteDecks

func (a *Anki) DeleteDecks(ctx context.Context, deckNames []string) error

func (*Anki) DeleteNotes

func (a *Anki) DeleteNotes(ctx context.Context, ids []int64) error

func (*Anki) FindNotes

func (a *Anki) FindNotes(ctx context.Context, query string) ([]int64, error)

func (*Anki) LoadProfile

func (a *Anki) LoadProfile(ctx context.Context, name string) error

func (*Anki) ModelFieldNames

func (a *Anki) ModelFieldNames(ctx context.Context, modelName string) ([]string, error)

func (*Anki) ModelNames

func (a *Anki) ModelNames(ctx context.Context) ([]string, error)

func (*Anki) NotesInfo

func (a *Anki) NotesInfo(ctx context.Context, ids []int64) ([]*NoteInfo, error)

func (*Anki) RequestPermission

func (a *Anki) RequestPermission(ctx context.Context) (*RequestPermissionResponse, error)

RequestPermission need to authenticate client origin (it doesn't check api key!)

func (*Anki) Version

func (a *Anki) Version(ctx context.Context) (int, error)

type ConnectionError

type ConnectionError struct {
	Err error
}

ConnectionError represents error occured when we tried to connect to server.

func (*ConnectionError) Error

func (e *ConnectionError) Error() string

func (*ConnectionError) Unwrap

func (e *ConnectionError) Unwrap() error

type CreateModelCardTemplate

type CreateModelCardTemplate struct {
	Name  string `json:"Name,omitempty"`
	Front string `json:"Front,omitempty"`
	Back  string `json:"Back,omitempty"`
}

type CreateModelRequest

type CreateModelRequest struct {
	ModelName     string                    `json:"modelName,omitempty"`
	Fields        []string                  `json:"inOrderFields,omitempty"`
	CSS           string                    `json:"css,omitempty"`
	CardTemplates []CreateModelCardTemplate `json:"cardTemplates,omitempty"`
}

type DuplicateFlags

type DuplicateFlags int
const (
	DuplicateFlagsCheck DuplicateFlags = 1 << iota
	DuplicateFlagsWithChildren
	DuplicateFlagsWithModels
)

type DuplicateScope

type DuplicateScope int
const (
	DuplicateScopeDeck DuplicateScope = iota
	DuplicateScopeEverywhere
)

type MediaAssetOptions

type MediaAssetOptions struct {
	Filename       string
	DeleteExisting bool
	Fields         []string
	SkipHash       []byte
}

MediaAssetOptions represents common options about how asset should be saved.

type MediaAssetRequest

type MediaAssetRequest struct {
	Data           string   `json:"data,omitempty"`
	Path           string   `json:"path,omitempty"`
	URL            string   `json:"url,omitempty"`
	Filename       string   `json:"filename,omitempty"`
	Fields         []string `json:"fields,omitempty"`
	SkipHash       string   `json:"skipHash,omitempty"`
	DeleteExisting bool     `json:"deleteExisting,omitempty"`
}

MediaAssetRequest represents actual request that will go to anki-connect

func NewMediaBlob

func NewMediaBlob(data []byte, opts *MediaAssetOptions) *MediaAssetRequest

func NewMediaFile

func NewMediaFile(filename string, opts *MediaAssetOptions) *MediaAssetRequest

func NewMediaURL

func NewMediaURL(url string, opts *MediaAssetOptions) *MediaAssetRequest

type MediaType

type MediaType int
const (
	MediaTypeAudio MediaType = iota
	MediaTypePicture
	MediaTypeVideo
)

type NoteInfo

type NoteInfo struct {
	NoteID    int64
	ModelName string
	Tags      []string
	Fields    map[string]*NoteInfoField
}

type NoteInfoField

type NoteInfoField struct {
	Value string
	Order int
}

type Options

type Options struct {
	URL    string
	APIKey string
	// Transport is used for http client.
	// Please not that anki-connect can not properly reuse connections!
	Transport http.RoundTripper
}

type RequestPermissionResponse

type RequestPermissionResponse struct {
	// Permission also returned as error from method
	Permission    string `json:"permission,omitempty"`
	RequireAPIKey bool   `json:"requireApiKey,omitempty"`
	Version       int    `json:"version,omitempty"`
}

type ServerError

type ServerError struct {
	Message string
	Err     error
}

ServerError represent errors that we quite sure related to anki. Eiher it's message from field "error" from response or can be wrapper around ErrPermissionDenied

func (*ServerError) Error

func (e *ServerError) Error() string

func (*ServerError) Unwrap

func (e *ServerError) Unwrap() error

type UnexpectedResponseError

type UnexpectedResponseError struct {
	Status int
	Err    error
}

UnexpectedResponseError represent error that possibly ocured because we connected to some server but probably not to anki-connect. Either we received unxpected status code or we were unable to decode body.

func (*UnexpectedResponseError) Error

func (e *UnexpectedResponseError) Error() string

func (*UnexpectedResponseError) Unwrap

func (e *UnexpectedResponseError) Unwrap() error

Jump to

Keyboard shortcuts

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