Documentation
¶
Index ¶
- Variables
- func AddBook(b *Book, basePath string, minPageNum int) error
- func AddBooks(list []*Book, basePath string, minPageNum int) (err error)
- func CheckBookExist(filePath string, bookType SupportFileType, storePath string) (exit bool)
- func ClearTempFilesALL(debug bool, cacheFilePath string)
- func DeleteBookByID(bookID string)
- func GetBookGroupIDByBookID(id string) (group_id string, err error)
- func GetBooksNumber() int
- func ResetBookMap()
- func RestoreDatabaseBooks(list []*Book) (err error)
- type Book
- func GetAllBookList() []*Book
- func GetArchiveBooks() []*Book
- func GetBookByAuthor(author string, sortBy string) ([]*Book, error)
- func GetBookByID(id string, sortBy string) (*Book, error)
- func GetRandomBook() (*Book, error)
- func NewBook(filePath string, modified time.Time, fileSize int64, storePath string, ...) (*Book, error)
- type BookGroup
- type BookInfo
- type BookInfoList
- func GetAllBookInfoList(sortBy string) (*BookInfoList, error)
- func GetBookInfoListByDepth(depth int, sortBy string) (*BookInfoList, error)
- func GetBookInfoListByID(BookID string, sortBy string) (*BookInfoList, error)
- func GetBookInfoListByMaxDepth(depth int, sortBy string) (*BookInfoList, error)
- func GetBookInfoListByParentFolder(parentFolder string, sortBy string) (*BookInfoList, error)
- func TopOfShelfInfo(sortBy string) (*BookInfoList, error)
- type BookInterface
- type BookStore
- type ComigoConfig
- type ConfigStatus
- type Folder
- type FrpClientConfig
- type ImageInfo
- type Pages
- type SupportFileType
- type User
- type WebPServerConfig
Constants ¶
This section is empty.
Variables ¶
var (
MainFolder = Folder{
SortBy: "name",
}
)
https://wnanbei.github.io/post/go-%E5%B9%B6%E5%8F%91%E5%AE%89%E5%85%A8%E7%9A%84-sync.map/ sync.Map 是标准库 sync 中实现的并发安全的 map。
操作 普通map sync.Map map获取某个key map[1] sync.Load(1) map添加元素 map[1] = 10 sync.Store(1, 10) map删除一个key delete(map, 1) sync.Delete(1) 遍历map for…range sync.Range()
sync.Map 两个特有的函数: LoadOrStore - sync.Map 存在就返回,不存在就插入 LoadAndDelete - sync.Map 获取某个 key,如果存在的话,同时删除这个 key
Functions ¶
func CheckBookExist ¶
func CheckBookExist(filePath string, bookType SupportFileType, storePath string) (exit bool)
CheckBookExist 查看内存中是否已经有了这本书,有了就false,让调用者跳过
func ClearTempFilesALL ¶
ClearTempFilesALL web加载时保存的临时图片,在在退出后清理
func GetBookGroupIDByBookID ¶
func ResetBookMap ¶
func ResetBookMap()
ResetBookMap 将 sync.Map 的变量设置为一个新的实例。这样做会让原来的 sync.Map 实例失去引用,随后被垃圾回收器清理。
func RestoreDatabaseBooks ¶
RestoreDatabaseBooks 从数据库中读取的书籍信息,放到内存中
Types ¶
type Book ¶
Book 定义书籍,BooID不应该重复,根据文件路径生成
func GetAllBookList ¶
func GetAllBookList() []*Book
func GetArchiveBooks ¶
func GetArchiveBooks() []*Book
func GetBookByAuthor ¶
GetBookByAuthor 获取同一作者的书籍。
func GetBookByID ¶
GetBookByID 获取特定书籍,复制一份数据
func NewBook ¶
func NewBook(filePath string, modified time.Time, fileSize int64, storePath string, depth int, bookType SupportFileType) (*Book, error)
NewBook 初始化Book,设置文件路径、书名、BookID等等
func (*Book) GetFilePath ¶
func (*Book) GetPageCount ¶
func (*Book) SortPagesByImageList ¶
SortPagesByImageList 根据一个既定的文件列表,重新对页面排序。用于epub文件。
type BookGroup ¶
type BookInfo ¶
type BookInfo struct {
Title string `json:"title"` // 书名
BookID string `json:"id"` // 根据FilePath生成的唯一ID
BookStorePath string `json:"-" ` // 在哪个子书库
Type SupportFileType `json:"type"` // 书籍类型
Depth int `json:"depth"` // 书籍深度
ChildBookNum int `json:"child_book_num"` // 子书籍数量
PageCount int `json:"page_count"` // 总页数
Cover ImageInfo `json:"cover"` // 封面图
ParentFolder string `json:"parent_folder"` // 父文件夹
Author string `json:"author"` // 作者
ISBN string `json:"isbn"` // ISBN
Press string `json:"press"` // 出版社
PublishedAt string `json:"published_at"` // 出版日期
FilePath string `json:"-"` // 文件绝对路径,json不解析
FileSize int64 `json:"file_size"` // 文件大小
Modified time.Time `json:"modified_time"` // 修改时间
ReadPercent float64 `json:"read_percent"` // 阅读进度
ExtractPath string `json:"-"` // 解压路径,7z用,json不解析
ExtractNum int `json:"-"` // 文件解压数 extract_num
InitComplete bool `json:"-"` // 是否解压完成 extract_complete
NonUTF8Zip bool `json:"-"` // 是否为特殊编码zip
ZipTextEncoding string `json:"-"` // zip文件编码
}
BookInfo 与Book唯一的区别是没有AllPageInfo,而是封面图URL 减小 json文件的大小
func (*BookInfo) ShortTitle ¶
type BookInfoList ¶
BookInfoList Slice
func GetAllBookInfoList ¶
func GetAllBookInfoList(sortBy string) (*BookInfoList, error)
func GetBookInfoListByDepth ¶
func GetBookInfoListByDepth(depth int, sortBy string) (*BookInfoList, error)
func GetBookInfoListByID ¶
func GetBookInfoListByID(BookID string, sortBy string) (*BookInfoList, error)
func GetBookInfoListByMaxDepth ¶
func GetBookInfoListByMaxDepth(depth int, sortBy string) (*BookInfoList, error)
func GetBookInfoListByParentFolder ¶
func GetBookInfoListByParentFolder(parentFolder string, sortBy string) (*BookInfoList, error)
func TopOfShelfInfo ¶
func TopOfShelfInfo(sortBy string) (*BookInfoList, error)
func (BookInfoList) Len ¶
func (s BookInfoList) Len() int
func (*BookInfoList) SortBooks ¶
func (s *BookInfoList) SortBooks(by string)
SortBooks 上面三个函数定义好了,终于可以使用sort包排序了
func (BookInfoList) Swap ¶
func (s BookInfoList) Swap(i, j int)
type BookInterface ¶
type ComigoConfig ¶
type ComigoConfig struct {
Port int `` /* 312-byte string literal not displayed */
ConfigPath string `json:"-" toml:"-" comment:"用户指定的的yaml设置文件路径"`
Host string `json:"Host" comment:"自定义二维码显示的主机名"`
LocalStores []string `json:"LocalStores" comment:"本地书库文件夹"`
BookStores []BookStore `json:"BookStores" toml:"-" comment:"用户指定的的yaml设置文件路径"`
ExcludePath []string `json:"ExcludePath" comment:"扫描书籍的时候,需要排除的文件或文件夹的名字"`
SupportMediaType []string `json:"SupportMediaType" comment:"扫描压缩包时,用于统计图片数量的图片文件后缀"`
SupportFileType []string `json:"SupportFileType" comment:"支持的书籍压缩包后缀"`
SupportTemplateFile []string `json:"SupportTemplateFile" comment:"支持的模板文件类型,默认为html"`
MinImageNum int `json:"MinImageNum" comment:"压缩包或文件夹内,至少有几张图片,才算作书籍"`
TimeoutLimitForScan int `` /* 130-byte string literal not displayed */
EnableUpload bool `json:"EnableUpload" comment:"启用上传功能"`
UploadPath string `json:"UploadPath" comment:"上传文件存储位置,默认在当前执行目录下创建 upload 文件夹"`
MaxScanDepth int `json:"MaxScanDepth" comment:"最大扫描深度"`
ZipFileTextEncoding string `json:"ZipFileTextEncoding" comment:"非utf-8编码的ZIP文件,尝试用什么编码解析,默认GBK"`
PrintAllPossibleQRCode bool `json:"PrintAllPossibleQRCode" comment:"扫描完成后,打印所有可能的阅读链接二维码"`
Debug bool `json:"Debug" comment:"开启Debug模式"`
OpenBrowser bool `json:"OpenBrowser" comment:"是否同时打开浏览器,windows默认true,其他默认false"`
DisableLAN bool `json:"DisableLAN" comment:"只在本机提供阅读服务,不对外共享,此项配置不支持热重载"`
DefaultMode string `json:"DefaultMode" comment:"默认阅读模式,默认为空,可以设置为scroll或flip"`
EnableLogin bool `json:"EnableLogin" comment:"是否启用登录。默认不需要登陆。此项配置不支持热重载。"`
Username string `json:"Username" comment:"启用登陆后,登录界面需要的用户名。"`
Password string `json:"Password" comment:"启用登陆后,登录界面需要的密码。"`
Timeout int `json:"Timeout" comment:"启用登陆后,cookie过期的时间。单位为分钟。默认180分钟后过期。"`
EnableTLS bool `json:"EnableTLS" comment:"是否启用HTTPS协议。需要设置证书于key文件。"`
CertFile string `json:"CertFile" comment:"TLS/SSL 证书文件路径 (default: ~/.config/.comigo/cert.crt)"`
KeyFile string `json:"KeyFile" comment:"TLS/SSL key文件路径 (default: ~/.config/.comigo/key.key)"`
UseCache bool `json:"UseCache" comment:"开启本地图片缓存,可以加快二次读取,但会占用硬盘空间"`
CachePath string `json:"CachePath" comment:"本地图片缓存位置,默认系统临时文件夹"`
ClearCacheExit bool `json:"ClearCacheExit" comment:"退出程序的时候,清理web图片缓存"`
EnableDatabase bool `json:"EnableDatabase" comment:"启用本地数据库,保存扫描到的书籍数据。此项配置不支持热重载。"`
ClearDatabaseWhenExit bool `json:"ClearDatabaseWhenExit" comment:"启用本地数据库时,扫描完成后,清除不存在的书籍。"`
LogToFile bool `json:"LogToFile" comment:"是否保存程序Log到本地文件。默认不保存。"`
LogFilePath string `json:"LogFilePath" comment:"Log文件的保存位置"`
LogFileName string `json:"LogFileName" comment:"Log文件名"`
GenerateMetaData bool `json:"GenerateMetaData" toml:"GenerateMetaData" comment:"生成书籍元数据"`
}
ComigoConfig 服务器设置(config.toml)
func UpdateConfig ¶
func UpdateConfig(config *ComigoConfig, jsonString string) (*ComigoConfig, error)
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 Folder ¶
type Folder struct {
Path string
SortBy string //新字段 //排序方式
SubFolders sync.Map //key为路径 存储 *subFolder
}
Folder 本地总书库,扫描后生成。可以有多个子书库。
func (*Folder) AddBookToSubFolder ¶
AddBookToSubFolder 将某一本书,放到BookMap里面去
func (*Folder) AddSubFolder ¶
AddSubFolder 创建一个新文件夹
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 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