server

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MainService

func MainService(confPath string) error

func ValidateSecurityForListenAddr added in v0.2.0

func ValidateSecurityForListenAddr(conf *SecurityConf, listenAddr string) error

Types

type App

type App struct {
	logutil.Logger
	// contains filtered or unexported fields
}

func NewApp

func NewApp(conf *AppConf) (*App, error)

func (*App) AddShelf added in v0.6.0

func (app *App) AddShelf(conf shelf.ShelfConfWithID) error

func (*App) Close

func (app *App) Close() error

func (*App) HandleAPIClearReadHistory

func (app *App) HandleAPIClearReadHistory(w http.ResponseWriter, r *http.Request)

DELETE /api/shelves/{shelf_id}/read_history

func (*App) HandleAPICreateBook added in v0.5.0

func (app *App) HandleAPICreateBook(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/books

func (*App) HandleAPICreateBookSource added in v0.5.0

func (app *App) HandleAPICreateBookSource(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/books/{book_id}/sources

func (*App) HandleAPICreateLayer

func (app *App) HandleAPICreateLayer(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/layers/{layer_path}

func (*App) HandleAPIDeleteBook

func (app *App) HandleAPIDeleteBook(w http.ResponseWriter, r *http.Request)

DELETE /api/shelves/{shelf_id}/books/{book_id}

func (*App) HandleAPIDeleteBookCover

func (app *App) HandleAPIDeleteBookCover(w http.ResponseWriter, r *http.Request)

DELETE /api/shelves/{shelf_id}/books/{book_id}/cover

func (*App) HandleAPIDeleteBookSource added in v0.5.0

func (app *App) HandleAPIDeleteBookSource(w http.ResponseWriter, r *http.Request)

DELETE /api/shelves/{shelf_id}/books/{book_id}/sources/{source_id}

func (*App) HandleAPIDeleteLayer

func (app *App) HandleAPIDeleteLayer(w http.ResponseWriter, r *http.Request)

DELETE /api/shelves/{shelf_id}/layers/{layer_path}

func (*App) HandleAPIDeleteTrashedBook added in v0.5.0

func (app *App) HandleAPIDeleteTrashedBook(w http.ResponseWriter, r *http.Request)

DELETE /api/shelves/{shelf_id}/trash/books/{book_id}

func (*App) HandleAPIFindDuplicateBooks

func (app *App) HandleAPIFindDuplicateBooks(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/duplicate

func (*App) HandleAPIGetBook

func (app *App) HandleAPIGetBook(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}

func (*App) HandleAPIGetBookContent

func (app *App) HandleAPIGetBookContent(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}/content

func (*App) HandleAPIGetBookCover

func (app *App) HandleAPIGetBookCover(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}/cover

func (*App) HandleAPIGetBookSource added in v0.3.0

func (app *App) HandleAPIGetBookSource(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}/sources/{source_id}

func (*App) HandleAPIGetBookSourceContent added in v0.3.0

func (app *App) HandleAPIGetBookSourceContent(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}/sources/{source_id}/content

func (*App) HandleAPIGetBookSources added in v0.3.0

func (app *App) HandleAPIGetBookSources(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}/sources

func (*App) HandleAPIGetBookSplitConfig

func (app *App) HandleAPIGetBookSplitConfig(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books/{book_id}/split_config

func (*App) HandleAPIGetBooks

func (app *App) HandleAPIGetBooks(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/books

func (*App) HandleAPIGetLayers

func (app *App) HandleAPIGetLayers(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/layers

func (*App) HandleAPIGetLogContent added in v0.6.0

func (app *App) HandleAPIGetLogContent(w http.ResponseWriter, r *http.Request)

GET /api/logs/{log_id}/content

func (*App) HandleAPIGetLogs added in v0.6.0

func (app *App) HandleAPIGetLogs(w http.ResponseWriter, r *http.Request)

GET /api/logs

func (*App) HandleAPIGetMarks

func (app *App) HandleAPIGetMarks(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/marks/{book_id}

func (*App) HandleAPIGetReadHistory

func (app *App) HandleAPIGetReadHistory(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/read_history

func (*App) HandleAPIGetTrashedBooks added in v0.5.0

func (app *App) HandleAPIGetTrashedBooks(w http.ResponseWriter, r *http.Request)

GET /api/shelves/{shelf_id}/trash/books

func (*App) HandleAPIImportBook

func (app *App) HandleAPIImportBook(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/books/import

func (*App) HandleAPIMoveLayer added in v0.6.0

func (app *App) HandleAPIMoveLayer(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/layer-moves

func (*App) HandleAPIRenameLayer added in v0.6.0

func (app *App) HandleAPIRenameLayer(w http.ResponseWriter, r *http.Request)

PATCH /api/shelves/{shelf_id}/layers/{layer_path}

func (*App) HandleAPIRestoreTrashedBook added in v0.5.0

func (app *App) HandleAPIRestoreTrashedBook(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/trash/books/{book_id}/restore

func (*App) HandleAPISetCurrentBookSource added in v0.6.0

func (app *App) HandleAPISetCurrentBookSource(w http.ResponseWriter, r *http.Request)

PUT /api/shelves/{shelf_id}/books/{book_id}/sources/{source_id}/current

func (*App) HandleAPITrashBook added in v0.5.0

func (app *App) HandleAPITrashBook(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/books/{book_id}/trash

func (*App) HandleAPIUpdateBook

func (app *App) HandleAPIUpdateBook(w http.ResponseWriter, r *http.Request)

PATCH /api/shelves/{shelf_id}/books/{book_id}

func (*App) HandleAPIUpdateBookCover

func (app *App) HandleAPIUpdateBookCover(w http.ResponseWriter, r *http.Request)

PUT /api/shelves/{shelf_id}/books/{book_id}/cover

func (*App) HandleAPIUpdateBookSourceContent added in v0.3.0

func (app *App) HandleAPIUpdateBookSourceContent(w http.ResponseWriter, r *http.Request)

PATCH /api/shelves/{shelf_id}/books/{book_id}/sources/{source_id}/content

func (*App) HandleAPIUpdateBookSplitConfig

func (app *App) HandleAPIUpdateBookSplitConfig(w http.ResponseWriter, r *http.Request)

PATCH /api/shelves/{shelf_id}/books/{book_id}/split_config

func (*App) HandleAPIUpdateMarks

func (app *App) HandleAPIUpdateMarks(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/marks/{book_id}

func (*App) HandleAPIUpdateReadHistory

func (app *App) HandleAPIUpdateReadHistory(w http.ResponseWriter, r *http.Request)

POST /api/shelves/{shelf_id}/read_history?book_id={book_id}

func (*App) HandleDeleteSettingCoverToJPG added in v0.6.0

func (app *App) HandleDeleteSettingCoverToJPG(w http.ResponseWriter, r *http.Request)

DELETE /api/setting/cover_to_jpg

func (*App) HandleDeleteSettingReadHistoryLimit added in v0.6.0

func (app *App) HandleDeleteSettingReadHistoryLimit(w http.ResponseWriter, r *http.Request)

DELETE /api/setting/read_history_limit

func (*App) HandleGetMode added in v0.6.0

func (app *App) HandleGetMode(w http.ResponseWriter, r *http.Request)

HandleGetMode returns server runtime mode flags.

func (*App) HandleGetSettingCoverToJPG added in v0.6.0

func (app *App) HandleGetSettingCoverToJPG(w http.ResponseWriter, r *http.Request)

GET /api/setting/cover_to_jpg

func (*App) HandleGetSettingReadHistoryLimit added in v0.6.0

func (app *App) HandleGetSettingReadHistoryLimit(w http.ResponseWriter, r *http.Request)

GET /api/setting/read_history_limit

func (*App) HandleGetShelves added in v0.6.0

func (app *App) HandleGetShelves(w http.ResponseWriter, _ *http.Request)

GET /api/shelves

func (*App) HandleSPAFallback

func (app *App) HandleSPAFallback(w http.ResponseWriter, r *http.Request)

Handle SPA fallback for all non-API GET requests

func (*App) HandleSetSettingCoverToJPG added in v0.6.0

func (app *App) HandleSetSettingCoverToJPG(w http.ResponseWriter, r *http.Request)

POST /api/setting/cover_to_jpg

func (*App) HandleSetSettingReadHistoryLimit added in v0.6.0

func (app *App) HandleSetSettingReadHistoryLimit(w http.ResponseWriter, r *http.Request)

POST /api/setting/read_history_limit

func (*App) Handler added in v0.2.0

func (app *App) Handler() http.Handler

func (*App) Health

func (app *App) Health(w http.ResponseWriter, r *http.Request)

func (*App) ImportFromLocalPath added in v0.5.0

func (app *App) ImportFromLocalPath(shelfID string, localPath string, layerParts shelf.Layers) (*shelf.Book, error)

ImportFromLocalPath imports a book from a local file path on the server. This is intended for desktop application use, where the client can specify a local file path and the server can access it directly.

func (*App) RemoveShelf added in v0.6.0

func (app *App) RemoveShelf(id string) error

func (*App) SecurityToken added in v0.2.0

func (app *App) SecurityToken() string

func (*App) SecurityTokenHeader added in v0.2.0

func (app *App) SecurityTokenHeader() string

func (*App) Serve

func (app *App) Serve(mux *http.ServeMux)

func (*App) Start

func (app *App) Start() error

type AppConf

type AppConf struct {
	Logger           logutil.LogConf          `yaml:"logger"`
	Shelves          []*shelf.ShelfConfWithID `yaml:"shelves"`
	StorePath        string                   `yaml:"store_path"`
	CoverToJPG       bool                     `yaml:"cover_to_jpg"`
	ReadHistoryLimit int                      `yaml:"read_history_limit"`
	ReadOnly         bool                     `yaml:"read_only"`
	Security         *SecurityConf            `yaml:"security"`
}

type Book

type Book struct {
	Meta  *shelf.BookMeta `json:"meta"`
	Layer shelf.Layers    `json:"layer"`
}

type LogFileEntry added in v0.6.0

type LogFileEntry = logutil.Entry

type Security added in v0.2.0

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

func NewSecurity added in v0.2.0

func NewSecurity(conf *SecurityConf) (*Security, error)

func (*Security) IsEnabled added in v0.2.0

func (sec *Security) IsEnabled() bool

func (*Security) LogStartup added in v0.2.0

func (sec *Security) LogStartup(logger *logutil.Logger)

func (*Security) Middleware added in v0.2.0

func (sec *Security) Middleware(next http.Handler) http.Handler

func (*Security) Token added in v0.2.0

func (sec *Security) Token() string

func (*Security) TokenHeader added in v0.2.0

func (sec *Security) TokenHeader() string

type SecurityConf added in v0.2.0

type SecurityConf struct {
	Mode                        SecurityMode `yaml:"mode"`
	ProtectRead                 bool         `yaml:"protect_read"`
	TokenHeader                 string       `yaml:"token_header"`
	AllowMissingOriginWithToken *bool        `yaml:"allow_missing_origin_with_token"`
	AllowedOrigins              []string     `yaml:"allowed_origins"`
}

type SecurityMode added in v0.2.0

type SecurityMode string
const (
	SecurityModeUnset      SecurityMode = ""
	SecurityModeLocalToken SecurityMode = "local_token"
	SecurityModeNone       SecurityMode = "none"
	SecurityModePassword   SecurityMode = "password"
	SecurityModeExternal   SecurityMode = "external"
)

type ShelfConfWithID added in v0.6.0

type ShelfConfWithID struct {
	// ID is a unique identifier for the shelf. It should be uri-safe as it may be used in URLs.
	// It is used in the API to specify which shelf to use.
	ID string `yaml:"id"`

	// Name is a human-readable name for the shelf.
	// If not provided, it will default to the same value as ID.
	Name string `yaml:"name"`

	shelf.ShelfConf `yaml:",inline"`
}

type ShelfData added in v0.6.0

type ShelfData struct {
	ID   string
	Name string
	*shelf.Shelf
}

type ShelfInfo added in v0.6.0

type ShelfInfo struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type ShelfManager added in v0.6.0

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

func NewShelfManager added in v0.6.0

func NewShelfManager() *ShelfManager

func (*ShelfManager) AddShelf added in v0.6.0

func (sm *ShelfManager) AddShelf(conf ShelfConfWithID) error

func (*ShelfManager) Close added in v0.6.0

func (sm *ShelfManager) Close() error

func (*ShelfManager) GetAllShelves added in v0.6.0

func (sm *ShelfManager) GetAllShelves() []*ShelfData

func (*ShelfManager) GetShelf added in v0.6.0

func (sm *ShelfManager) GetShelf(id string) (*ShelfData, bool)

func (*ShelfManager) RemoveShelf added in v0.6.0

func (sm *ShelfManager) RemoveShelf(id string) error

type SrvConf

type SrvConf struct {
	Logger     logutil.LogConf `yaml:"logger"`
	ServerConf *httputil.Conf  `yaml:"server_conf"`
	AppConf    *AppConf        `yaml:"app_conf"`
}

type TrashedBook added in v0.5.0

type TrashedBook struct {
	ID            string        `json:"id"`
	Title         string        `json:"title"`
	Authors       []string      `json:"authors,omitempty"`
	OriginalPath  string        `json:"original_path,omitempty"`
	OriginalLayer shelf.Layers  `json:"original_layer,omitempty"`
	DeletedAt     util.JSONTime `json:"deleted_at,omitzero"`
}

type UpdateBookRequest

type UpdateBookRequest struct {
	Title       *string        `json:"title"`
	Authors     *[]string      `json:"authors"`
	Tags        *[]string      `json:"tags"`
	Language    *string        `json:"language"`
	Comment     *string        `json:"comment"`
	Star        *int           `json:"star"`
	PublishedAt *util.JSONTime `json:"published_at"`
	Layer       *shelf.Layers  `json:"layer"`
	Layers      *shelf.Layers  `json:"layers"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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