model

package
v0.0.0-...-07dc153 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBookConflict = errors.New("book conflict")
	ErrBookNotFound = errors.New("book not found")
	ErrMimeNotFound = errors.New("mime not found")
	ErrFileConflict = errors.New("file conflict")
	ErrFileNotFound = errors.New("file not found")
	ErrInvalidExt   = errors.New("invalid ext")
)
View Source
var MimeAlias = map[string]string{
	"application/x-mobi8-ebook":      "azw3",
	"application/epub+zip":           "epub",
	"application/fb2+zip":            "fb2",
	"application/x-mobipocket-ebook": "mobi",
	"application/pdf":                "pdf",
	"text/plain":                     "txt",
}

Functions

func AddBook

func AddBook(db *gorm.DB, book *Book) error

func AddFile

func AddFile(db *gorm.DB, file *File) error

func AutoMigrate

func AutoMigrate(db *gorm.DB) (err error)

func DeleteBook

func DeleteBook(db *gorm.DB, book *Book) error

func DeleteFile

func DeleteFile(db *gorm.DB, bookID uint64, mime string) error

func EntriesFromBooks

func EntriesFromBooks(books *[]Book) []opds.Entry

func GenerateFilePath

func GenerateFilePath(bookID uint64, mimeAlias string) string

func GetBooks

func GetBooks(db *gorm.DB) (*[]Book, error)

func GetBooksWithCount

func GetBooksWithCount(db *gorm.DB, count uint64) (*[]Book, error)

func GetBooksWithNext

func GetBooksWithNext(db *gorm.DB, next uint64) (*[]Book, error)

func GetBooksWithNextCount

func GetBooksWithNextCount(db *gorm.DB, next, count uint64) (*[]Book, error)

func GetMimeAlias

func GetMimeAlias(mime string) (string, error)

func GetMimeAliasByFilename

func GetMimeAliasByFilename(filename string) (string, error)

func GetMimes

func GetMimes() map[string]string

func MimeByExt

func MimeByExt(ext string) (string, error)

func MimeByFilename

func MimeByFilename(filename string) (string, error)

func UpdateBook

func UpdateBook(db *gorm.DB, book *Book) error

Types

type Book

type Book struct {
	ID          uint64     `json:"ID" gorm:"primary_key"`
	CreatedAt   time.Time  `json:"CreatedAt"`
	UpdatedAt   time.Time  `json:"UpdatedAt"`
	DeletedAt   *time.Time `json:"-" sql:"index"`
	UUID        string     `json:"UUID" gorm:"not null"`
	ISBN        string     `json:"ISBN"`
	Title       string     `json:"Title"`
	Author      string     `json:"Author"`
	Description string     `json:"Description"`
	CoverURL    string     `json:"CoverURL"`
	Publisher   string     `json:"Publisher"`
	PubDate     string     `json:"PubDate"`
	Files       []File     `json:"Files"`
}

func GetBookByID

func GetBookByID(db *gorm.DB, bookID uint64) (*Book, error)

type File

type File struct {
	ID        uint64     `json:"ID"`
	CreatedAt time.Time  `json:"CreatedAt"`
	UpdatedAt time.Time  `json:"UpdatedAt"`
	DeletedAt *time.Time `json:"-" sql:"index"`
	BookID    uint64     `json:"BookID"`
	MimeType  string     `json:"MimeType"`
	Path      string     `json:"-"`
	Link      string     `json:"Link" gorm:"-"`
}

func GetFile

func GetFile(db *gorm.DB, bookID uint64, mime string) (*File, error)

Jump to

Keyboard shortcuts

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