files

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddComicInfoToCBR added in v1.12.0

func AddComicInfoToCBR(cbrPath string, comicInfoXML []byte) error

AddComicInfoToCBR adds a ComicInfo.xml file to a CBR archive by converting it to CBZ format

func AddComicInfoToCBZ added in v1.12.0

func AddComicInfoToCBZ(cbzPath string, comicInfoXML []byte) error

AddComicInfoToCBZ adds a ComicInfo.xml file to an existing CBZ archive

func CopyFile

func CopyFile(src, dst string) error

func CountImageFiles

func CountImageFiles(archiveFilePath string) (int, error)

CountImageFiles counts the number of image files in an archive (zip, cbz, rar, or cbr) or directory.

func CountPagesInArchive added in v1.12.0

func CountPagesInArchive(archivePath string) (int, error)

CountPagesInArchive counts the number of image pages in a CBZ/CBR archive

func DecryptSlug added in v1.12.0

func DecryptSlug(mediaSlug, chapterSlug, slug string) (slugType, librarySlug, value string, err error)

DecryptSlug decrypts a slug and returns the type ("page" or "asset"), library slug, and value.

func DownloadImageWithThumbnails

func DownloadImageWithThumbnails(fileName, fileUrl string, dataBackend *store.FileStore, useWebp bool) error

DownloadImageWithThumbnails downloads an image and creates multiple sizes for better performance

func DownloadPosterImage added in v1.12.0

func DownloadPosterImage(imageURL, slug string, dataBackend *store.FileStore, useWebp bool) (string, error)

DownloadPosterImage downloads an image from a URL and creates multiple cached sizes Creates: original, full (400x600), thumbnail (200x300), and small (100x150) versions Returns the URL path for the full-size image

func EncodeImageToBytes

func EncodeImageToBytes(img image.Image, format string, quality int) ([]byte, error)

EncodeImageToBytes encodes an image to bytes in the specified format This is the base version without WebP support

func ExtractAndStoreFirstImage

func ExtractAndStoreFirstImage(archivePath, slug, dataDir string, quality int) (string, error)

isImageFile checks if a file is an image based on its extension. ExtractAndStoreFirstImage extracts the first image from an archive and stores it with proper resizing. For tall images (webtoons), it crops from the top to capture the cover/title area. Returns the stored image URL path.

func ExtractAndStoreImageWithCrop

func ExtractAndStoreImageWithCrop(imagePath string, slug string, cropData map[string]any, quality int, useWebP bool) (string, error)

ExtractAndStoreImageWithCrop extracts an image (from a file path or archive) and stores it with optional cropping. ExtractAndStoreImageWithCrop extracts an image (from a file path or archive) and stores it with optional cropping.

func ExtractAndStoreImageWithCropByIndex

func ExtractAndStoreImageWithCropByIndex(mangaPath, slug string, imageIndex int, cropData map[string]any, useWebP bool, quality int) (string, error)

ExtractAndStoreImageWithCropByIndex extracts an image by index with cropping

func ExtractFirstImage

func ExtractFirstImage(archivePath, outputFolder string) error

ExtractFirstImage extracts the first image from an archive and saves it to the output folder.

func ExtractPosterImage

func ExtractPosterImage(filePath, slug string, dataBackend *store.FileStore, useWebp bool) (string, error)

ExtractPosterImage extracts a poster-sized image from any supported file type (image or archive) and caches it with proper processing. For archives, it extracts the first image. For tall images (webtoons), it crops from the top to capture the cover/title area. Creates multiple sizes: original, full (400x600), thumbnail (200x300), and small (100x150). Returns the cached image URL path.

func ExtractTitle

func ExtractTitle(html string) string

ExtractTitle extracts title from HTML content

func FindBestPreviewImage added in v1.13.0

func FindBestPreviewImage(chapterFilePath string) (image.Image, error)

FindBestPreviewImage analyzes pages and returns the decoded image of the best candidate.

func GenerateAssetSlug added in v1.12.0

func GenerateAssetSlug(mediaSlug, librarySlug, chapterSlug, assetPath string) string

GenerateAssetSlug creates a URL-safe slug that hides an EPUB asset path.

func GenerateChapterPreview added in v1.13.0

func GenerateChapterPreview(chapterFilePath string) ([]byte, error)

GenerateChapterPreview analyzes a chapter's images and returns a JPEG preview thumbnail from the most visually interesting page. It uses edge detection, color variance, and content density to find pages where "something is happening" rather than blank/title pages.

func GeneratePageSlug added in v1.12.0

func GeneratePageSlug(mediaSlug, librarySlug, chapterSlug string, page int) string

GeneratePageSlug creates a URL-safe slug that hides the page number. The slug encodes the library slug + page number, XORed with an HMAC keystream and authenticated with an HMAC tag. Deterministic for the same inputs + key.

func GenerateRandomSecret

func GenerateRandomSecret() (string, error)

GenerateRandomSecret generates a random 32-byte secret encoded as hex

func GenerateThumbnails

func GenerateThumbnails(fullImagePath, slug string, dataBackend *store.FileStore) error

GenerateThumbnails generates thumbnail and small versions from a cached full-size image

func GetBookContent

func GetBookContent(epubPath, mangaSlug, librarySlug, chapterSlug string) string

GetBookContent extracts all readable content from an EPUB file as HTML

func GetDataDirectory

func GetDataDirectory() string

GetDataDirectory returns the data directory path

func GetImageDataURIByIndex

func GetImageDataURIByIndex(mangaPath string, imageIndex int) (string, error)

GetImageDataURIByIndex extracts an image at the given index and returns a data URI

func GetMiddleImageDimensions

func GetMiddleImageDimensions(chapterPath string) (int, int, error)

GetMiddleImageDimensions gets the width and height of the middle image in the first chapter. Returns width, height, and error.

func GetOPFDir

func GetOPFDir(epubPath string) (string, error)

GetOPFDir returns the directory of the OPF file in the EPUB

func GetTOC

func GetTOC(epubPath string) string

GetTOC generates table of contents HTML from EPUB

func GetTitlesFromNCX

func GetTitlesFromNCX(epubPath string) (map[string]string, error)

GetTitlesFromNCX extracts titles from NCX navigation

func IsWebtoonByAspectRatio

func IsWebtoonByAspectRatio(width, height int) bool

IsWebtoonByAspectRatio checks if an image's aspect ratio suggests it's a webtoon. Returns true if height is >= 3 times the width.

func ListImagesInManga

func ListImagesInManga(mangaPath string) ([]string, error)

ListImagesInManga returns a list of image paths/URIs from a manga file or directory. For directories, it returns the file paths of images. For archive files (.cbz, .cbr, .zip, .rar), it returns data URIs of the images.

func OpenImage

func OpenImage(path string) (image.Image, error)

openImage opens and decodes an image file. OpenImage opens and decodes an image from the given path

func ProcessImage

func ProcessImage(fromPath, toPath string, quality int) error

ProcessImage processes an image by resizing and cropping it, then saving it to a new file.

func ProcessImageWithCrop

func ProcessImageWithCrop(fromPath, toPath string, cropData map[string]any, quality int) error

ProcessImageWithCrop processes an image by applying user-defined cropping and resizing

func ProcessImageWithTopCrop

func ProcessImageWithTopCrop(fromPath, toPath string, quality int) error

ProcessImageWithTopCrop processes an image by extracting the top portion and resizing it. It takes the top square (or near-square) section of the image, useful for cover/poster areas.

func ProcessLocalImageWithThumbnails

func ProcessLocalImageWithThumbnails(imagePath, slug string, dataBackend *store.FileStore, useWebp bool) (string, error)

ProcessLocalImageWithThumbnails processes a local image file and creates multiple cached sizes Creates: original, full (400x600), thumbnail (200x300), and small (100x150) versions Returns the URL path for the full-size image

func SaveImage

func SaveImage(filePath string, img image.Image, format string, quality int) error

saveImage encodes and saves an image to the specified path. SaveImage saves an image to the given path with the specified format and quality SaveImage saves an image to a file path with the specified format and quality

func SetDataDirectory

func SetDataDirectory(dir string)

SetDataDirectory sets the data directory path

func SetSlugKey added in v1.12.0

func SetSlugKey(imageAccessSecret string)

SetSlugKey derives the slug HMAC key from the ImageAccessSecret. Call this once during startup after the DB config is loaded.

Types

type ArchiveIterator

type ArchiveIterator interface {
	Next() (name string, reader io.ReadCloser, err error)
	Close() error
}

ArchiveIterator provides a common interface for iterating through archive files

type Chapter

type Chapter struct {
	ID    string
	Path  string
	Href  string
	Title string
}

EPUB parsing structures (from POC)

func GetChapters

func GetChapters(epubPath string) ([]Chapter, error)

GetChapters extracts chapter information from an EPUB file

type ChapterPreviewResult added in v1.13.0

type ChapterPreviewResult struct {
	PageIndex int
	Score     float64
}

ChapterPreviewResult holds the analysis score and page index

type Container

type Container struct {
	XMLName   xml.Name `xml:"container"`
	Rootfiles struct {
		Rootfile struct {
			FullPath string `xml:"full-path,attr"`
		} `xml:"rootfile"`
	} `xml:"rootfiles"`
}

type GrayscaleImage added in v1.13.0

type GrayscaleImage struct {
	Pix    []uint8
	Width  int
	Height int
}

GrayscaleImage is a simple grayscale image implementation

func (*GrayscaleImage) At added in v1.13.0

func (g *GrayscaleImage) At(x, y int) color.Color

func (*GrayscaleImage) Bounds added in v1.13.0

func (g *GrayscaleImage) Bounds() image.Rectangle

func (*GrayscaleImage) ColorModel added in v1.13.0

func (g *GrayscaleImage) ColorModel() color.Model

type NCX

type NCX struct {
	XMLName xml.Name `xml:"ncx"`
	NavMap  struct {
		NavPoints []struct {
			NavLabel struct {
				Text string `xml:"text"`
			} `xml:"navLabel"`
			Content struct {
				Src string `xml:"src,attr"`
			} `xml:"content"`
		} `xml:"navPoint"`
	} `xml:"navMap"`
}

type Package

type Package struct {
	XMLName  xml.Name `xml:"package"`
	Manifest struct {
		Items []struct {
			ID   string `xml:"id,attr"`
			Href string `xml:"href,attr"`
		} `xml:"item"`
	} `xml:"manifest"`
	Spine struct {
		Itemrefs []struct {
			Idref string `xml:"idref,attr"`
		} `xml:"itemref"`
	} `xml:"spine"`
}

type ThumbnailSize

type ThumbnailSize struct {
	Name   string
	Width  int
	Height int
}

Jump to

Keyboard shortcuts

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