services

package
v0.0.0-...-a85cc8a Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ListAPIBaseURL   = "https://api.wilii.cn/api/bing?page=%d&pageSize=%d"
	DetailAPIURL     = "https://api.wilii.cn/api/Bing/%s"
	BingImageBaseURL = "https://bing.com/th?id="
)
View Source
const (
	ThumbnailHeight        = 240
	ThumbnailWidth         = 400
	MinThumbnailSize int64 = 1024
	MaxDownloadRetry       = 2
)

Thumbnail dimensions

View Source
const MaxRecurDepth = 3

Variables

View Source
var (
	ImageDir = "./images"
	ThumbDir = "./thumbs"
)

Functions

func BatchInsertWallpapersIgnore

func BatchInsertWallpapersIgnore(wallpapers []*models.Wallpaper) (int, error)

BatchInsertWallpapersIgnore inserts multiple wallpapers in a single transaction, ignoring records where date already exists. Returns the number of inserted rows.

func BatchUpdateFileSizes

func BatchUpdateFileSizes(updates []FileSizeUpdate) error

BatchUpdateFileSizes updates file_size for multiple wallpapers by GUID in a single transaction

func BatchUpdateWallpaperFields

func BatchUpdateWallpaperFields(updates []FieldUpdate) error

BatchUpdateWallpaperFields updates multiple fields for multiple wallpapers by GUID in a single transaction

func BuildSourceURL

func BuildSourceURL(date, slug, imageDPI string) string

BuildSourceURL reconstructs the wilii source URL from date, slug and resolution

func ConvertToWallpaper

func ConvertToWallpaper(raw *models.WallpaperRaw) *models.Wallpaper

ConvertToWallpaper converts raw API data to a Wallpaper model

func DeleteOldThumbnail

func DeleteOldThumbnail(wp *models.Wallpaper)

DeleteOldThumbnail removes an existing thumbnail file so it can be rebuilt

func EnsureDirectory

func EnsureDirectory(dirPath string) error

func ExtractResolution

func ExtractResolution(filepathStr string) string

ExtractResolution extracts the resolution from a filepath string, e.g.:

"/path/to/BumbleBee_ZH-CN6429376340_1920x1080.jpg"
=> "1920x1080"

func ExtractSlug

func ExtractSlug(filepathStr string) string

ExtractSlug extracts the core image ID from a filepath string. It strips the OHR. prefix, resolution suffix, and extension, e.g.:

"/path/to/OHR.BumbleBee_ZH-CN6429376340_1920x1080.jpg"
=> "BumbleBee_ZH-CN6429376340"

func FetchDetailData

func FetchDetailData(guid string) (*models.DetailData, error)

FetchDetailData fetches the detail data for a wallpaper by GUID. Returns all fields (title, headline, copyright, description, filepath) for backfilling.

func FetchPageData

func FetchPageData(page, pageSize int) (*models.WiliiListResponse, error)

FetchPageData fetches a page of wallpaper list data from the API

func FileExists

func FileExists(path string) bool

func GetBingImageURL

func GetBingImageURL(slug, imageDPI string) string

GetBingImageURL constructs the Bing image download URL from slug and resolution. Result: "https://bing.com/th?id=OHR.BumbleBee_ZH-CN6429376340_1920x1080.jpg" If imageDPI is larger than 1920x1080, uses "UHD" instead.

func GetBingImageURLHD

func GetBingImageURLHD(slug string) string

GetBingImageURLHD constructs the Bing image URL with highest quality (UHD)

func GetDateRange

func GetDateRange() (earliest, latest string, err error)

GetDateRange returns the earliest and latest dates in the database

func GetFileSize

func GetFileSize(path string) int64

func GetLocalImagePath

func GetLocalImagePath(date string) string

GetLocalImagePath returns the local image file path in ImageDir. Format: ./images/2014/20140501.jpg

func GetRecentWallpapers

func GetRecentWallpapers(limit int) ([]*models.Wallpaper, error)

GetRecentWallpapers returns the most recent N wallpapers ordered by date descending

func GetThumbnailPath

func GetThumbnailPath(date string) string

GetThumbnailPath returns the relative thumbnail path: year/date.jpg

func GetWallpapersByMonth

func GetWallpapersByMonth(year, month int) ([]*models.Wallpaper, error)

GetWallpapersByMonth returns all wallpapers for a given year and month

func InitDirs

func InitDirs(conf *Config)

InitDirs creates image and thumbnail directories if they don't exist

func InsertWallpaperIgnore

func InsertWallpaperIgnore(wp *models.Wallpaper) error

InsertWallpaperIgnore inserts a wallpaper, ignoring if date already exists

func NeedsRebuildThumbnail

func NeedsRebuildThumbnail(wp *models.Wallpaper) (bool, string)

NeedsRebuildThumbnail checks if a thumbnail needs to be rebuilt. Returns true if: missing, wrong dimensions (not 480x360), or too small.

func UpdateDescription

func UpdateDescription(guid, description string) error

UpdateDescription updates the description field of a wallpaper by GUID

func UpdateFileSize

func UpdateFileSize(guid string, fileSize int64) error

UpdateFileSize updates the file_size field of a wallpaper by GUID

func UpdateImageDPI

func UpdateImageDPI(guid, imageDPI string) error

UpdateImageDPI updates the image_dpi field of a wallpaper by GUID

Types

type Config

type Config struct {
	AppName  string
	Host     string
	Port     int
	CertDir  string
	ImageDir string
	ThumbDir string
	LogFile  string
	Database drivers.DatabaseConfig
}

Config holds application configuration loaded from .env

func LoadConfig

func LoadConfig() *Config

LoadConfig loads configuration from .env file with defaults. If .env file doesn't exist, falls back to system environment variables.

func (*Config) GetCertFile

func (c *Config) GetCertFile() (string, string, bool)

type DecodeFailure

type DecodeFailure struct {
	Reason  DecodeFailureReason
	Err     error
	Path    string
	Attempt int
}

type DecodeFailureReason

type DecodeFailureReason string
const (
	ReasonFormatUnsupported DecodeFailureReason = "format_unsupported"
	ReasonDataCorrupted     DecodeFailureReason = "data_corrupted"
	ReasonMemoryExceeded    DecodeFailureReason = "memory_exceeded"
	ReasonReadFailed        DecodeFailureReason = "read_failed"
	ReasonDownloadTruncated DecodeFailureReason = "download_truncated"
	ReasonUnknown           DecodeFailureReason = "unknown"
)

type DownloadData

type DownloadData struct {
	Body   []byte
	Source DownloadSource
	URL    string
}

type DownloadResult

type DownloadResult struct {
	FileSize int64  // Original file size in bytes
	ImageDPI string // Actual resolution, e.g. "3840x2160"
}

DownloadResult holds the result of a download operation

func DownloadThumbnailForWallpaper

func DownloadThumbnailForWallpaper(wp *models.Wallpaper) (DownloadResult, error)

func DownloadThumbnailHD

func DownloadThumbnailHD(wp *models.Wallpaper) (DownloadResult, error)

DownloadThumbnailHD downloads a UHD image, generates a thumbnail, and returns the original file size and actual resolution.

type DownloadSource

type DownloadSource string
const (
	SourceCDN  DownloadSource = "wilii_cdn"
	SourceBing DownloadSource = "bing"
	SourceUHD  DownloadSource = "bing_uhd"
)

type Entry

type Entry struct {
	Key   string
	Value string
}

func (*Entry) Int

func (t *Entry) Int() int

func (*Entry) Str

func (t *Entry) Str() string

type Environ

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

func NewWithFile

func NewWithFile(filename string) (*Environ, error)

func (*Environ) Get

func (v *Environ) Get(key string) string

func (*Environ) GetInt

func (v *Environ) GetInt(key string, fallback ...int) int

func (*Environ) GetStr

func (v *Environ) GetStr(key string, fallback ...string) string

func (*Environ) Load

func (v *Environ) Load(reader io.ReadCloser, err error) error

func (*Environ) Lookup

func (v *Environ) Lookup(key string) (Entry, bool)

func (*Environ) ScanLines

func (v *Environ) ScanLines(reader io.Reader) error

type FieldUpdate

type FieldUpdate struct {
	GUID  string
	Pairs []goent.Pair
}

FieldUpdate holds a GUID and the column-value pairs to update

type FileSizeUpdate

type FileSizeUpdate struct {
	GUID     string
	FileSize int64
}

FileSizeUpdate holds data for a batch file_size update

type IntegrityCheckResult

type IntegrityCheckResult struct {
	Status       IntegrityStatus
	ExpectedSize int64
	ActualSize   int64
}

type IntegrityStatus

type IntegrityStatus string
const (
	IntegrityIntact    IntegrityStatus = "intact"
	IntegrityTruncated IntegrityStatus = "truncated"
	IntegritySkipped   IntegrityStatus = "skipped"
)

type LocalCheckInfo

type LocalCheckInfo struct {
	FileSize int64
	ImageDPI string
}

type LocalSkipResult

type LocalSkipResult int
const (
	SkipNone LocalSkipResult = iota
	SkipThumbOnly
	SkipFull
)

Jump to

Keyboard shortcuts

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