kaliber

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: GPL-3.0 Imports: 27 Imported by: 0

README

Kaliber

GoDoc view examples License

Purpose

//TODO

Installation

You can use Go to install this package for you:

go get -u github.com/mwat56/kaliber

Usage

//TODO

Licence

    Copyright © 2019 M.Watermann, 10247 Berlin, Germany
                    All rights reserved
                EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the GNU General Public License for details.

Documentation

Overview

Package kaliber implements a server for the `Calibre` library software.

Copyright © 2019 M.Watermann, 10247 Berlin, Germany
                All rights reserved
            EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.

Index

Constants

View Source
const (
	SortUnsorted = uint8(iota)
	SortByAuthor
	SortByLanguage
	SortByPublisher
	SortByRating
	SortBySeries
	SortBySize
	SortByTags
	SortByTime
	SortByTitle
)

Constants defining the ORDER_BY clause

Variables

View Source
var (
	// AppArguments is the list for the cmdline arguments and INI values.
	AppArguments tAguments
)

Functions

func AddUser

func AddUser(aUser, aFilename string)

AddUser reads a password for `aUser` from the commandline and adds it to `aFilename`.

NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.

`aUser` the username to add to the password file.

`aFilename` name of the password file to use.

func CalibreCachePath

func CalibreCachePath() string

CalibreCachePath returns the directory of the copied `Calibre` databse.

func CalibreDatabaseName

func CalibreDatabaseName() string

CalibreDatabaseName returns the name of the `Calibre` database.

func CalibreDatabasePath

func CalibreDatabasePath() string

CalibreDatabasePath returns rhe complete path-/filename of the `Calibre` library.

func CalibreLibraryPath

func CalibreLibraryPath() string

CalibreLibraryPath returns the base directory of the `Calibre` library.

func CheckUser

func CheckUser(aUser, aFilename string)

CheckUser reads a password for `aUser` from the commandline and compares it with the one stored in `aFilename`.

NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.

`aUser` the username to check in the password file.

`aFilename` name of the password file to use.

func DBopen

func DBopen(aFilename string) error

DBopen establishes a new database connection.

`aFilename` is the path-/filename of the SQLite database to use.

func DeleteUser

func DeleteUser(aUser, aFilename string)

DeleteUser removes the entry for `aUser` from the password list `aFilename`.

NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.

`aUser` the username to remove from the password file.

`aFilename` name of the password file to use.

func ListUser

func ListUser(aFilename string)

ListUser reads `aFilename` and lists all users stored in there.

NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.

`aFilename` name of the password file to use.

func RemoveWhiteSpace

func RemoveWhiteSpace(aPage []byte) []byte

RemoveWhiteSpace removes HTML comments and unneccessary whitespace.

This function removes all unneeded/redundant whitespace and HTML comments from the given <tt>aPage</tt>. This can reduce significantly the amount of data to send to the remote user agent thus saving bandwidth.

func SetCalibreCachePath

func SetCalibreCachePath(aPath string) string

SetCalibreCachePath sets the directory of the `Calibre` database copy.

func SetCalibreLibraryPath

func SetCalibreLibraryPath(aPath string) string

SetCalibreLibraryPath sets the base directory of the `Calibre` library.

func SetThumbWidth added in v0.2.0

func SetThumbWidth(aWidth uint) uint

SetThumbWidth set the new width for generated thumbnails.

If `aWidth` is smaller than `64` it's increased.

func ShowHelp

func ShowHelp()

ShowHelp lists the commandline options to `Stderr`.

func ThumbWidth added in v0.2.0

func ThumbWidth() uint

ThumbWidth returns the configured width of generated thumbnails.

func Thumbnail added in v0.2.0

func Thumbnail(aDoc *TDocument) (string, error)

Thumbnail generates a thumbnail of the document's cover.

func ThumbnailName added in v0.2.0

func ThumbnailName(aDoc *TDocument) string

ThumbnailName returns the name of thumbnail file of `aDoc`.

func ThumbnailRemove added in v0.2.0

func ThumbnailRemove(aDoc *TDocument) error

ThumbnailRemove deletes the thumbnail of `aDoc`.

func ThumbnailUpdate added in v0.2.0

func ThumbnailUpdate()

ThumbnailUpdate creates thumbnails for all existing documents

func URLparts

func URLparts(aURL string) (rDir, rPath string)

URLparts returns two parts: `rDir` holds the base-directory of `aURL`, `rPath` holds the remaining part of `aURL`.

Depending on the actual value of `aURL` both return values may be empty or both may be filled; none of both will hold a leading slash.

func UpdateUser

func UpdateUser(aUser, aFilename string)

UpdateUser reads a password for `aUser` from the commandline and updates the entry in the password list `aFilename`.

NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.

`aUser` the username to remove from the password file.

`aFilename` name of the password file to use.

Types

type TDocList

type TDocList []TDocument

TDocList is a list of `TDocument` instances.

func QueryBy

func QueryBy(aOption *TQueryOptions) (rCount int, rList *TDocList, rErr error)

QueryBy returns all documents according to `aOption`.

func QueryIDs added in v0.2.0

func QueryIDs() (*TDocList, error)

QueryIDs returns a list of documents with only the `ID` and `path` fields set.

func QueryLimit

func QueryLimit(aStart, aLength uint) (*TDocList, error)

QueryLimit returns a list of `TDocument` objects.

func QuerySearch

func QuerySearch(aOption *TQueryOptions) (rCount int, rList *TDocList, rErr error)

QuerySearch returns a list of documents

func (*TDocList) Add added in v0.2.0

func (dl *TDocList) Add(aDoc *TDocument) *TDocList

Add appends `aDoc` to the list.

type TDocument

type TDocument tDocument

TDocument represents a single document (e.g. book)

func QueryDocMini

func QueryDocMini(aID TID) *TDocument

QueryDocMini returns the document identified by `aID`.

This function fills only the document fields `ID`, `formats`, `path`, `authorSort`, and `Title`.

func QueryDocument

func QueryDocument(aID TID) *TDocument

QueryDocument returns the `TDocument` identified by `aID`.

func (*TDocument) Authors

func (doc *TDocument) Authors() *TEntityList

Authors returns a list of ID/Name author fields.

func (*TDocument) Comment

func (doc *TDocument) Comment() template.HTML

Comment returns the comments of the document.

func (*TDocument) Cover

func (doc *TDocument) Cover() string

Cover returns the relative path-filename of the document's cover image.

func (doc *TDocument) DocLink() string

DocLink returns a link to this document's page.

func (*TDocument) Filename

func (doc *TDocument) Filename(aFormat string) string

Filename returns the path-/filename of `aFormat`.

func (*TDocument) Filenames

func (doc *TDocument) Filenames() *TPathList

Filenames returns a list of path-/filename for this document

func (*TDocument) Files

func (doc *TDocument) Files() *TEntityList

Files returns a list of ID/Name/URL fields for doc format files.

func (*TDocument) Formats

func (doc *TDocument) Formats() *TEntityList

Formats returns a list of ID/Name/URL fields for doc formats.

func (*TDocument) Identifiers

func (doc *TDocument) Identifiers() *TEntityList

Identifiers returns a list of ID/Name/URL identifier fields.

func (*TDocument) Language

func (doc *TDocument) Language() *TEntity

Language returns an ID/Name series struct.

func (*TDocument) PubDate

func (doc *TDocument) PubDate() string

PubDate returns the formatted `pubdate` property.

func (*TDocument) Publisher

func (doc *TDocument) Publisher() *TEntity

Publisher returns an ID/Name publisher struct.

func (*TDocument) Series

func (doc *TDocument) Series() *TEntity

Series returns an ID/Name series struct.

func (*TDocument) SeriesIndex

func (doc *TDocument) SeriesIndex() string

SeriesIndex returns the document's series index as formatted string.

func (*TDocument) Tags

func (doc *TDocument) Tags() *TEntityList

Tags returns a list of ID/Name tag fields.

func (*TDocument) Thumb added in v0.2.0

func (doc *TDocument) Thumb() string

Thumb returns the relative path-filename of the document's cover image.

func (*TDocument) Timestamp

func (doc *TDocument) Timestamp() string

Timestamp returns the formatted `timestamp` property.

type TEntity

type TEntity struct {
	ID   TID
	Name string
	URL  string
}

TEntity is a basic entity structure.

type TEntityList

type TEntityList []TEntity

TEntityList is a list of entities

type TID

type TID = int

TID is the database index type.

type TPageHandler

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

TPageHandler provides the handling of HTTP request/response.

func NewPageHandler

func NewPageHandler() (*TPageHandler, error)

NewPageHandler returns a new `TPageHandler` instance.

func (*TPageHandler) Address

func (ph *TPageHandler) Address() string

Address returns the configured `IP:Port` address to use for listening.

func (*TPageHandler) GetErrorPage

func (ph *TPageHandler) GetErrorPage(aData []byte, aStatus int) []byte

GetErrorPage returns an error page for `aStatus`, implementing the `TErrorPager` interface.

func (*TPageHandler) NeedAuthentication

func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool

NeedAuthentication returns `true` if authentication is needed, or `false` otherwise.

`aRequest` is the request to check.

func (TPageHandler) ServeHTTP

func (ph TPageHandler) ServeHTTP(aWriter http.ResponseWriter, aRequest *http.Request)

ServeHTTP handles the incoming HTTP requests.

type TPathList

type TPathList TStringMap

TPathList is a map of document formats holding the respective library file.

type TQueryOptions

type TQueryOptions struct {
	ID          TID    // an entity ID to lookup
	Descending  bool   // sort direction
	Entity      string // limiting query to a certain entity (author,publisher, series, tag)
	LimitLength uint   // number of documents per page
	LimitStart  uint   // starting number
	Matching    string // text to lookup in all documents
	SortBy      uint8  // display order of documents
	QueryCount  uint   // number of DB records matching the query option
}

TQueryOptions holds properties configuring a query.

This type is used by the HTTP pagehandler when receiving a page's data.

func NewQueryOptions

func NewQueryOptions() *TQueryOptions

NewQueryOptions returns a new `TQueryOptions` instance.

func (*TQueryOptions) CGI

func (qo *TQueryOptions) CGI() string

CGI returns the object's query escaped string representation fit for use as the `qos` CGI argument.

func (*TQueryOptions) DecLimit

func (qo *TQueryOptions) DecLimit() *TQueryOptions

DecLimit decrements the LIMIT values.

func (*TQueryOptions) IncLimit

func (qo *TQueryOptions) IncLimit() *TQueryOptions

IncLimit increments the LIMIT values.

func (*TQueryOptions) Scan

func (qo *TQueryOptions) Scan(aString string) *TQueryOptions

Scan returns the options read from `aString`.

func (*TQueryOptions) SelectLimitOptions

func (qo *TQueryOptions) SelectLimitOptions() *TStringMap

SelectLimitOptions returns a list of SELECT/OPTIONs.

func (*TQueryOptions) SelectOrderOptions

func (qo *TQueryOptions) SelectOrderOptions() *TStringMap

SelectOrderOptions returns a list of SELECT/OPTIONs.

func (*TQueryOptions) SelectSortByOptions

func (qo *TQueryOptions) SelectSortByOptions() *TStringMap

SelectSortByOptions returns a list of SELECT/OPTIONs.

func (*TQueryOptions) String

func (qo *TQueryOptions) String() string

String returns the options as a `|` delimited string.

func (*TQueryOptions) UnCGI

func (qo *TQueryOptions) UnCGI(aCGI string) *TQueryOptions

UnCGI unescapes the given `aCGI`.

If there are errors during unescaping the current values remain unchanged.

func (*TQueryOptions) Update

func (qo *TQueryOptions) Update(aRequest *http.Request) *TQueryOptions

Update returns a `TQueryOptions` instance with values read from the `aRequest` data.

type TSearch

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

TSearch provides text search capabilities.

func NewSearch

func NewSearch(aSearchTerm string) *TSearch

NewSearch returns a new `TSearch` instance.

func (*TSearch) Clause

func (so *TSearch) Clause() string

Clause returns the produced FROM/WHERE clause.

func (*TSearch) Parse

func (so *TSearch) Parse() *TSearch

Parse returns the parsed search term(s).

func (*TSearch) String

func (so *TSearch) String() string

String returns a stringfied representation.

type TStringMap

type TStringMap map[string]string

TStringMap is a map of strings indexed by string.

type TView

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

TView combines a template and its logical name.

func NewView

func NewView(aBaseDir, aName string) (*TView, error)

NewView returns a new `TView` with `aName`.

`aBaseDir` is the path to the directory storing the template files.

`aName` is the name of the template file providing the page's main body without the filename extension (i.e. w/o ".gohtml"). `aName` serves as both the main template's name as well as the view's name.

func (*TView) Render

func (v *TView) Render(aWriter http.ResponseWriter, aData *TemplateData) error

Render executes the template using the TView's properties.

`aWriter` is a http.ResponseWriter, or e.g. `os.Stdout` in console apps.

`aData` is a list of data to be injected into the template.

If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.

func (*TView) RenderedPage

func (v *TView) RenderedPage(aData *TemplateData) (rBytes []byte, rErr error)

RenderedPage returns the rendered template/page and a possible Error executing the template.

`aData` is a list of data to be injected into the template.

type TViewList

type TViewList tViewList

TViewList is a list of `TView` instances (to be used as a template pool).

func NewViewList

func NewViewList() *TViewList

NewViewList returns a new (empty) `TViewList` instance.

func (*TViewList) Add

func (vl *TViewList) Add(aView *TView) *TViewList

Add appends `aView` to the list.

`aView` is the view to add to this list.

The view's name (as specified in the `NewView()` function call) is used as the view's key in this list.

func (*TViewList) Get

func (vl *TViewList) Get(aName string) (*TView, bool)

Get returns the view with `aName`.

`aName` is the name (key) of the `TView` object to retrieve.

If `aName` doesn't exist, the return value is `nil`. The second value (ok) is a `bool` that is `true` if `aName` exists in the list, and `false` if not.

func (*TViewList) Render

func (vl *TViewList) Render(aName string, aWriter http.ResponseWriter, aData *TemplateData) error

Render executes the template with the key `aName`.

`aName` is the name of the template/view to use.

`aWriter` is a `http.ResponseWriter` to handle the executed template.

`aData` is a list of data to be injected into the template.

If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.

func (*TViewList) RenderedPage

func (vl *TViewList) RenderedPage(aName string, aData *TemplateData) (rBytes []byte, rErr error)

RenderedPage returns the rendered template/page with the key `aName`.

`aName` is the name of the template/view to use.

`aData` is a list of data to be injected into the template.

type TemplateData

type TemplateData map[string]interface{}

TemplateData is a list of values to be injected into a template.

func NewTemplateData

func NewTemplateData() *TemplateData

NewTemplateData returns a new (empty) TDataList instance.

func (*TemplateData) Set

func (dl *TemplateData) Set(aKey string, aValue interface{}) *TemplateData

Set inserts `aValue` identified by `aKey` to the list.

If there's already a list entry with `aKey` its current value gets replaced by `aValue`.

`aKey` is the values's identifier (as used as placeholder in the template).

`aValue` contains the data entry's value.

Directories

Path Synopsis
db module

Jump to

Keyboard shortcuts

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