Documentation
¶
Index ¶
- Constants
- Variables
- func BatchInsertWallpapersIgnore(wallpapers []*models.Wallpaper) (int, error)
- func BatchUpdateFileSizes(updates []FileSizeUpdate) error
- func BatchUpdateWallpaperFields(updates []FieldUpdate) error
- func BuildSourceURL(date, slug, imageDPI string) string
- func ConvertToWallpaper(raw *models.WallpaperRaw) *models.Wallpaper
- func DeleteOldThumbnail(wp *models.Wallpaper)
- func EnsureDirectory(dirPath string) error
- func ExtractResolution(filepathStr string) string
- func ExtractSlug(filepathStr string) string
- func FetchDetailData(guid string) (*models.DetailData, error)
- func FetchPageData(page, pageSize int) (*models.WiliiListResponse, error)
- func FileExists(path string) bool
- func GetBingImageURL(slug, imageDPI string) string
- func GetBingImageURLHD(slug string) string
- func GetDateRange() (earliest, latest string, err error)
- func GetFileSize(path string) int64
- func GetLocalImagePath(date string) string
- func GetRecentWallpapers(limit int) ([]*models.Wallpaper, error)
- func GetThumbnailPath(date string) string
- func GetWallpapersByMonth(year, month int) ([]*models.Wallpaper, error)
- func InitDirs(conf *Config)
- func InsertWallpaperIgnore(wp *models.Wallpaper) error
- func NeedsRebuildThumbnail(wp *models.Wallpaper) (bool, string)
- func UpdateDescription(guid, description string) error
- func UpdateFileSize(guid string, fileSize int64) error
- func UpdateImageDPI(guid, imageDPI string) error
- type Config
- type DecodeFailure
- type DecodeFailureReason
- type DownloadData
- type DownloadResult
- type DownloadSource
- type Entry
- type Environ
- func (v *Environ) Get(key string) string
- func (v *Environ) GetInt(key string, fallback ...int) int
- func (v *Environ) GetStr(key string, fallback ...string) string
- func (v *Environ) Load(reader io.ReadCloser, err error) error
- func (v *Environ) Lookup(key string) (Entry, bool)
- func (v *Environ) ScanLines(reader io.Reader) error
- type FieldUpdate
- type FileSizeUpdate
- type IntegrityCheckResult
- type IntegrityStatus
- type LocalCheckInfo
- type LocalSkipResult
Constants ¶
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=" )
const ( ThumbnailHeight = 240 ThumbnailWidth = 400 MinThumbnailSize int64 = 1024 MaxDownloadRetry = 2 )
Thumbnail dimensions
const MaxRecurDepth = 3
Variables ¶
var ( ImageDir = "./images" ThumbDir = "./thumbs" )
Functions ¶
func BatchInsertWallpapersIgnore ¶
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 ¶
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 ¶
DeleteOldThumbnail removes an existing thumbnail file so it can be rebuilt
func EnsureDirectory ¶
func ExtractResolution ¶
ExtractResolution extracts the resolution from a filepath string, e.g.:
"/path/to/BumbleBee_ZH-CN6429376340_1920x1080.jpg" => "1920x1080"
func ExtractSlug ¶
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 GetBingImageURL ¶
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 ¶
GetBingImageURLHD constructs the Bing image URL with highest quality (UHD)
func GetDateRange ¶
GetDateRange returns the earliest and latest dates in the database
func GetFileSize ¶
func GetLocalImagePath ¶
GetLocalImagePath returns the local image file path in ImageDir. Format: ./images/2014/20140501.jpg
func GetRecentWallpapers ¶
GetRecentWallpapers returns the most recent N wallpapers ordered by date descending
func GetThumbnailPath ¶
GetThumbnailPath returns the relative thumbnail path: year/date.jpg
func GetWallpapersByMonth ¶
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 ¶
InsertWallpaperIgnore inserts a wallpaper, ignoring if date already exists
func NeedsRebuildThumbnail ¶
NeedsRebuildThumbnail checks if a thumbnail needs to be rebuilt. Returns true if: missing, wrong dimensions (not 480x360), or too small.
func UpdateDescription ¶
UpdateDescription updates the description field of a wallpaper by GUID
func UpdateFileSize ¶
UpdateFileSize updates the file_size field of a wallpaper by GUID
func UpdateImageDPI ¶
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.
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 FieldUpdate ¶
FieldUpdate holds a GUID and the column-value pairs to update
type FileSizeUpdate ¶
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 LocalSkipResult ¶
type LocalSkipResult int
const ( SkipNone LocalSkipResult = iota SkipThumbOnly SkipFull )