entity

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 26 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// MainStore 带有层级关系的总书组,用于前端展示
	MainStore = Store{}
)

使用并发安全的 sync.Map 存储书籍和书组

Functions

func AddBook

func AddBook(b *Book, basePath string, minPageNum int) error

AddBook 添加一本书

func AddBooks

func AddBooks(list []*Book, basePath string, minPageNum int) error

AddBooks 添加一组书

func CheckAllBookFileExist added in v0.9.12

func CheckAllBookFileExist()

CheckAllBookFileExist 检查内存中的书的源文件是否存在,不存在就删掉

func CheckBookExist

func CheckBookExist(filePath string, bookType SupportFileType) bool

CheckBookExist 查看内存中是否已经有了这本书,有了就返回 true,让调用者跳过

func ClearAllBookData added in v0.9.12

func ClearAllBookData()

ClearAllBookData 清空所有书籍与虚拟书组数据

func ClearBookData added in v0.9.12

func ClearBookData()

ClearBookData 清空书籍数据

func ClearBookGroupData added in v0.9.12

func ClearBookGroupData()

ClearBookGroupData 清空书组相关数据

func ClearTempFilesALL

func ClearTempFilesALL(debug bool, cacheFilePath string)

ClearTempFilesALL 清理所有缓存的临时图片

func DeleteBookByID

func DeleteBookByID(bookID string)

DeleteBookByID 删除一本书

func GetBookGroupIDByBookID

func GetBookGroupIDByBookID(id string) (string, error)

GetBookGroupIDByBookID 通过子书籍 ID 获取所属书组 ID

func GetBooksNumber

func GetBooksNumber() int

GetBooksNumber 获取书籍总数,不包括 BookGroup

func ResetBookGroupData added in v0.9.12

func ResetBookGroupData()

ResetBookGroupData 重置虚拟书库

func RestoreDatabaseBooks

func RestoreDatabaseBooks(list []*Book)

RestoreDatabaseBooks 从数据库中读取的书籍信息,放到内存中

Types

type Book

type Book struct {
	BookInfo
	Pages Pages `json:"pages"`
}

Book 定义书籍结构

func GetAllBookList

func GetAllBookList() []*Book

GetAllBookList 获取所有书籍列表

func GetArchiveBooks

func GetArchiveBooks() []*Book

GetArchiveBooks 获取所有压缩包格式的书籍

func GetBookByAuthor

func GetBookByAuthor(author string, sortBy string) ([]*Book, error)

GetBookByAuthor 获取同一作者的书籍

func GetBookByID

func GetBookByID(id string, sortBy string) (*Book, error)

GetBookByID 根据 BookID 获取书籍

func GetRandomBook

func GetRandomBook() (*Book, error)

GetRandomBook 随机获取一本书

func NewBook

func NewBook(filePath string, modified time.Time, fileSize int64, storePath string, depth int, bookType SupportFileType) (*Book, error)

NewBook 初始化 Book,设置文件路径、书名、BookID 等

func (*Book) GetAuthor

func (b *Book) GetAuthor() string

GetAuthor 获取作者信息

func (*Book) GetBookID

func (b *Book) GetBookID() string

GetBookID 获取书籍的 ID

func (*Book) GetFilePath

func (b *Book) GetFilePath() string

GetFilePath 获取文件路径

func (*Book) GetPageCount

func (b *Book) GetPageCount() int

GetPageCount 获取页数

func (*Book) ScanAllImage

func (b *Book) ScanAllImage()

ScanAllImage 服务器端分析分辨率、漫画单双页,只适合已解压文件

func (*Book) ScanAllImageGo

func (b *Book) ScanAllImageGo()

ScanAllImageGo 并发分析图片

func (*Book) SortPages

func (b *Book) SortPages(s string)

SortPages 对页面进行排序

func (*Book) SortPagesByImageList

func (b *Book) SortPagesByImageList(imageList []string)

SortPagesByImageList 根据给定的文件列表排序页面(用于 EPUB)

type BookGroup

type BookGroup struct {
	BookInfo
	ChildBook sync.Map //key:BookID,value: *BookInfo
}

func GetBookGroupInfoByChildBookID

func GetBookGroupInfoByChildBookID(id string) (*BookGroup, error)

GetBookGroupInfoByChildBookID 通过子书籍 ID 获取所属书组信息

func NewBookGroup

func NewBookGroup(filePath string, modified time.Time, fileSize int64, storePath string, depth int, bookType SupportFileType) (*BookGroup, error)

NewBookGroup 初始化BookGroup,设置文件路径、书名、BookID等等

type BookInfo

type BookInfo struct {
	Author          string          `json:"author"`         // 作者
	BookID          string          `json:"id"`             // 根据 FilePath 生成的唯一 ID
	BookStorePath   string          `json:"-"`              // 在哪个子书库
	ChildBookNum    int             `json:"child_book_num"` // 子书籍数量
	Cover           ImageInfo       `json:"cover"`          // 封面图
	Deleted         bool            `json:"deleted"`        // 源文件是否已删除
	Depth           int             `json:"depth"`          // 书籍深度
	ExtractPath     string          `json:"-"`              // 解压路径,7z 用,JSON 不解析
	ExtractNum      int             `json:"-"`              // 文件解压数
	FileSize        int64           `json:"file_size"`      // 文件大小
	FilePath        string          `json:"-"`              // 文件绝对路径,JSON 不解析
	ISBN            string          `json:"isbn"`           // ISBN
	InitComplete    bool            `json:"-"`              // 是否解压完成
	Modified        time.Time       `json:"modified_time"`  // 修改时间
	NonUTF8Zip      bool            `json:"-"`              // 是否为特殊编码 zip
	PageCount       int             `json:"page_count"`     // 总页数
	ParentFolder    string          `json:"parent_folder"`  // 父文件夹
	Press           string          `json:"press"`          // 出版社
	PublishedAt     string          `json:"published_at"`   // 出版日期
	ReadPercent     float64         `json:"read_percent"`   // 阅读进度
	Title           string          `json:"title"`          // 书名
	Type            SupportFileType `json:"type"`           // 书籍类型
	ZipTextEncoding string          `json:"-"`              // zip 文件编码
}

BookInfo 与 Book 唯一的区别是没有 AllPageInfo,而是封面图 URL,减小 JSON 文件的大小

func NewBaseInfo

func NewBaseInfo(b *Book) *BookInfo

NewBaseInfo 创建新的 BookInfo 实例

func (*BookInfo) SetCover added in v0.9.12

func (b *BookInfo) SetCover(c ImageInfo) *BookInfo

SetCover 设置封面

func (*BookInfo) ShortTitle

func (b *BookInfo) ShortTitle() string

ShortTitle 返回简短的标题

type BookInfoList

type BookInfoList struct {
	BookInfos []BookInfo
}

BookInfoList 表示 BookInfo 的列表

func GetAllBookInfoList

func GetAllBookInfoList(sortBy string) (*BookInfoList, error)

GetAllBookInfoList 获取所有 BookInfo,并根据 sortBy 参数进行排序

func GetBookInfoListByDepth

func GetBookInfoListByDepth(depth int, sortBy string) (*BookInfoList, error)

GetBookInfoListByDepth 根据深度获取书籍列表

func GetBookInfoListByID

func GetBookInfoListByID(BookID string, sortBy string) (*BookInfoList, error)

GetBookInfoListByID 根据 ID 获取书籍列表

func GetBookInfoListByMaxDepth

func GetBookInfoListByMaxDepth(depth int, sortBy string) (*BookInfoList, error)

GetBookInfoListByMaxDepth 获取指定最大深度的书籍列表

func GetBookInfoListByParentFolder

func GetBookInfoListByParentFolder(parentFolder string, sortBy string) (*BookInfoList, error)

GetBookInfoListByParentFolder 根据父文件夹获取书籍列表

func TopOfShelfInfo

func TopOfShelfInfo(sortBy string) (*BookInfoList, error)

TopOfShelfInfo 获取顶层书架信息

func (*BookInfoList) SortBooks

func (s *BookInfoList) SortBooks(sortBy string)

SortBooks 根据 sortBy 参数对 BookInfos 进行排序

type ComigoConfig

type ComigoConfig struct {
	//AutoRescan             bool            `json:"AutoRescan" comment:"刷新页面时,是否自动重新扫描"`
	CachePath              string          `json:"CachePath" comment:"本地图片缓存位置,默认系统临时文件夹"`
	CertFile               string          `json:"CertFile" comment:"TLS/SSL 证书文件路径 (default: ~/.config/.comigo/cert.crt)"`
	ClearCacheExit         bool            `json:"ClearCacheExit" comment:"退出程序的时候,清理web图片缓存"`
	ClearDatabaseWhenExit  bool            `json:"ClearDatabaseWhenExit" comment:"启用本地数据库时,扫描完成后,清除不存在的书籍。"`
	ConfigPath             string          `json:"-" toml:"-" comment:"用户指定的的yaml设置文件路径"`
	Debug                  bool            `json:"Debug" comment:"开启Debug模式"`
	DefaultMode            string          `json:"DefaultMode" comment:"默认阅读模式,默认为空,可以设置为scroll或flip"`
	DisableLAN             bool            `json:"DisableLAN" comment:"只在本机提供阅读服务,不对外共享,此项配置不支持热重载"`
	EnableDatabase         bool            `json:"EnableDatabase" comment:"启用本地数据库,保存扫描到的书籍数据。此项配置不支持热重载。"`
	EnableLogin            bool            `json:"EnableLogin" comment:"是否启用登录。默认不需要登陆。此项配置不支持热重载。"`
	EnableTLS              bool            `json:"EnableTLS" comment:"是否启用HTTPS协议。需要设置证书于key文件。"`
	EnableUpload           bool            `json:"EnableUpload" comment:"启用上传功能"`
	ExcludePath            []string        `json:"ExcludePath" comment:"扫描书籍的时候,需要排除的文件或文件夹的名字"`
	GenerateMetaData       bool            `json:"GenerateMetaData" toml:"GenerateMetaData" comment:"生成书籍元数据"`
	Host                   string          `json:"Host" comment:"自定义二维码显示的主机名"`
	KeyFile                string          `json:"KeyFile" comment:"TLS/SSL key文件路径 (default: ~/.config/.comigo/key.key)"`
	LocalStores            []string        `json:"LocalStores" comment:"本地书库文件夹"`
	LogFileName            string          `json:"LogFileName" comment:"Log文件名"`
	LogFilePath            string          `json:"LogFilePath" comment:"Log文件的保存位置"`
	LogToFile              bool            `json:"LogToFile" comment:"是否保存程序Log到本地文件。默认不保存。"`
	MaxScanDepth           int             `json:"MaxScanDepth" comment:"最大扫描深度"`
	MinImageNum            int             `json:"MinImageNum" comment:"压缩包或文件夹内,至少有几张图片,才算作书籍"`
	OpenBrowser            bool            `json:"OpenBrowser" comment:"是否同时打开浏览器,windows默认true,其他默认false"`
	Password               string          `json:"Password" comment:"启用登陆后,登录界面需要的密码。"`
	Port                   int             `` /* 312-byte string literal not displayed */
	PrintAllPossibleQRCode bool            `json:"PrintAllPossibleQRCode" comment:"扫描完成后,打印所有可能的阅读链接二维码"`
	Stores                 []stores.Store  `json:"BookStores" toml:"-" comment:"书库设置"`
	SupportFileType        []string        `json:"SupportFileType" comment:"支持的书籍压缩包后缀"`
	SupportMediaType       []string        `json:"SupportMediaType" comment:"扫描压缩包时,用于统计图片数量的图片文件后缀"`
	SupportTemplateFile    []string        `json:"SupportTemplateFile" comment:"支持的模板文件类型,默认为html"`
	Timeout                int             `json:"Timeout" comment:"启用登陆后,cookie过期的时间。单位为分钟。默认180分钟后过期。"`
	TimeoutLimitForScan    int             `` /* 130-byte string literal not displayed */
	UploadDirOption        UploadDirOption `` /* 132-byte string literal not displayed */
	UploadPath             string          `json:"UploadPath" comment:"指定上传路径时,上传文件的存储位置"`
	UseCache               bool            `json:"UseCache" comment:"开启本地图片缓存,可以加快二次读取,但会占用硬盘空间"`
	Username               string          `json:"Username" comment:"启用登陆后,登录界面需要的用户名。"`
	ZipFileTextEncoding    string          `json:"ZipFileTextEncoding" comment:"非utf-8编码的ZIP文件,尝试用什么编码解析,默认GBK"`
}

func UpdateConfig

func UpdateConfig(config *ComigoConfig, jsonString string) (*ComigoConfig, error)

UpdateConfig 更新配置。 使用 JSON 反序列化将更新的配置解析为映射,遍历映射并更新配置,减少重复的代码。

func (*ComigoConfig) AddLocalStore added in v0.9.12

func (c *ComigoConfig) AddLocalStore(path string)

AddLocalStore 添加本地书库(单个路径)

func (*ComigoConfig) AddLocalStores added in v0.9.12

func (c *ComigoConfig) AddLocalStores(path []string)

AddLocalStores 添加本地书库(多个路径)

func (*ComigoConfig) CheckLocalStores added in v0.9.12

func (c *ComigoConfig) CheckLocalStores(path string) bool

CheckLocalStores 检查本地书库路径是否已存在

func (*ComigoConfig) LocalStoresList added in v0.9.12

func (c *ComigoConfig) LocalStoresList() []string

LocalStoresList 获取本地书库列表

func (*ComigoConfig) ReplaceLocalStores added in v0.9.12

func (c *ComigoConfig) ReplaceLocalStores(pathList []string)

ReplaceLocalStores 替换现有的“本地”类型的书库,保留其他类型的书库

func (*ComigoConfig) SetByExecutableFilename

func (c *ComigoConfig) SetByExecutableFilename()

SetByExecutableFilename 通过执行文件名设置默认网页模板参数

type ConfigStatus

type ConfigStatus struct {
	// 当前生效的配置文件路径 None、HomeDirectory、WorkingDirectory、ProgramDirectory
	// 设置读取顺序:None(默认值) -> HomeDirectory -> ProgramDirectory -> WorkingDirectory
	In   string
	Path struct {
		// 对应配置文件的绝对路径
		WorkingDirectory string
		HomeDirectory    string
		ProgramDirectory string
	}
}

func (*ConfigStatus) SetConfigStatus

func (c *ConfigStatus) SetConfigStatus() error

type FrpClientConfig

type FrpClientConfig struct {
	FrpcCommand      string `comment:"手动设定frpc可执行程序的路径,默认为frpc"`
	ServerAddr       string
	ServerPort       int
	Token            string
	FrpType          string //本地转发端口设置
	RemotePort       int
	RandomRemotePort bool
}

FrpClientConfig frp客户端配置

type ImageInfo

type ImageInfo struct {
	PageNum           int       `json:"-"`        //这个字段不解析
	NameInArchive     string    `json:"filename"` //用于解压的压缩文件内文件路径,或图片名,为了适应特殊字符,经过一次转义
	Url               string    `json:"url"`      //远程用户读取图片的URL,为了适应特殊字符,经过一次转义
	Blurhash          string    `json:"-"`        //`json:"blurhash"` //blurhash占位符。需要扫描图片生成(util.GetImageDataBlurHash)
	Height            int       `json:"-"`        //暂时用不着 这个字段不解析`json:"height"`   //blurhash用,图片高
	Width             int       `json:"-"`        //暂时用不着 这个字段不解析`json:"width"`    //blurhash用,图片宽
	ModeTime          time.Time `json:"-"`        //这个字段不解析
	FileSize          int64     `json:"-"`        //这个字段不解析
	RealImageFilePATH string    `json:"-"`        //这个字段不解析  书籍为文件夹的时候,实际图片的路径
	ImgType           string    `json:"-"`        //这个字段不解析
	InsertHtml        string    `json:"-"`        //这个字段不解析
}

ImageInfo 单张漫画图片

type Pages

type Pages struct {
	Images []ImageInfo `json:"images"`
	SortBy string      `json:"sort_by"`
}

Pages 定义页面结构

func (Pages) Len

func (s Pages) Len() int

Len 返回页面数量

func (Pages) Less

func (s Pages) Less(i, j int) bool

Less 按照排序方式比较页面

func (Pages) Swap

func (s Pages) Swap(i, j int)

Swap 交换页面

type ReadingProgress added in v0.9.12

type ReadingProgress struct {
	// 当前页
	NowPageNum int `json:"nowPageNum"`
	// 当前章节
	NowChapterNum int `json:"nowChapterNum"`
	// 阅读时间,单位为秒
	ReadingTime int `json:"readingTime"`
}

func GetReadingProgress added in v0.9.12

func GetReadingProgress(progress string) (ReadingProgress, error)

type Store added in v0.9.12

type Store struct {
	SubStores sync.Map //key为路径 存储 *subStore
}

Store 本地总书库,扫描后生成。可以有多个子书库。

func (*Store) AddBookToSubStore added in v0.9.12

func (folder *Store) AddBookToSubStore(searchPath string, b *BookInfo) error

AddBookToSubStore 将某一本书,放到BookMap里面去

func (*Store) AddSubStore added in v0.9.12

func (folder *Store) AddSubStore(basePath string) error

AddSubStore 创建一个新文件夹

func (*Store) AnalyzeStore added in v0.9.12

func (folder *Store) AnalyzeStore() (e error)

AnalyzeStore 分析并生成书籍组

type SupportFileType

type SupportFileType string
const (
	TypeDir         SupportFileType = "dir"
	TypeZip         SupportFileType = ".zip"
	TypeRar         SupportFileType = ".rar"
	TypeBooksGroup  SupportFileType = "book_group"
	TypeCbz         SupportFileType = ".cbz"
	TypeCbr         SupportFileType = ".cbr"
	TypeTar         SupportFileType = ".tar"
	TypeEpub        SupportFileType = ".epub"
	TypePDF         SupportFileType = ".pdf"
	TypeVideo       SupportFileType = "video"
	TypeAudio       SupportFileType = "audio"
	TypeUnknownFile SupportFileType = "unknown"
)

书籍类型

func GetBookTypeByFilename

func GetBookTypeByFilename(filename string) SupportFileType

GetBookTypeByFilename 初始化Book时,取得BookType

type UploadDirOption added in v0.9.12

type UploadDirOption int

type User

type User struct {
	ID        int    `json:"id"`
	Username  string `json:"username"`
	Password  string `json:"password"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
}

type WebPServerConfig

type WebPServerConfig struct {
	WebpCommand  string
	HOST         string
	PORT         string
	ImgPath      string
	QUALITY      int
	AllowedTypes []string
	ExhaustPath  string
}

WebPServerConfig WebPServer服务端配置

Jump to

Keyboard shortcuts

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