wallpapers

package module
v0.0.0-...-3e85a64 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 13 Imported by: 0

README

Wallpapers

A site that displays Nat Welch's personal wallpaper collection. Images live in Google Cloud Storage, served via Imgix CDN. Metadata (dimensions, colors, tags) is stored in a local SQLite file (wallpapers.db) that ships with the container.

Architecture

Component Path Purpose
Web server cmd/server/ Serves the gallery and all HTML pages
Uploader cmd/uploader/ Syncs Dropbox → GCS, analyzes new images
DB package db/ GORM/SQLite models and queries
Analysis package analysis/ Color extraction (k-means) + Gemini AI tagging

Pages

Route Description
/ Masonry gallery with search
/image/{filename} Image detail (metadata, colors, keywords)
/resolutions Browse all unique resolutions by count
/colors 18×18 HSL color grid showing match counts per cell
/tags Browse all AI-extracted keywords sorted by count
/search?q= JSON search API
/all.json JSON dump of all images
  • Keyword — matches against AI-extracted tags, filename, file format
  • Color (#rrggbb) — fuzzy match using RGB Euclidean distance (threshold ≈80), sorted closest-first
  • Resolution (1920x1080) — fuzzy match within ±20% of each dimension, sorted closest-first

Image Pipeline (uploader)

  1. Walk ~/Dropbox/Photos/Wallpapers/DesktopWallpapers
  2. Upload new/changed files to GCS (CRC32 deduplication)
  3. Analyze with Gemini (gemini-2.5-flash): extract top-3 colors (k-means), resolution, and content tags
  4. Store metadata in wallpapers.db
  5. Delete GCS files no longer present locally

Development

# Run the server (requires wallpapers.db in the working directory)
go run ./cmd/server
# or
task server

# Run tests
task test

# Run uploader (syncs Dropbox → GCS, needs GCP credentials)
task uploader

# Lint / format / vet
task check

Environment Variables

Variable Required Description
GEMINI_API_KEY Uploader only Google Gemini API key for image analysis
GOOGLE_APPLICATION_CREDENTIALS Uploader only Path to GCP service account JSON
PORT No Server port (default: 8080)

Deployment

Docker image builds both binaries from a single golang:1.26 stage and copies wallpapers.db into the final debian:bookworm-slim image. The container runs server by default on port 8080.

docker build -t wallpapers .
docker run -p 8080:8080 wallpapers

The uploader is a one-shot CLI run locally via update.sh (updates deps, syncs, commits the updated wallpapers.db).

Documentation

Overview

Package wallpapers provides helpers for managing wallpaper files stored in Google Cloud Storage, including CRC checksums, URL generation, and metadata.

Index

Constants

View Source
const (
	Bucket = "iccowalls"
)

Bucket is the GCS bucket name where wallpaper files are stored.

Variables

View Source
var (
	NameRegex = regexp.MustCompile("[^a-z0-9]")
)

NameRegex matches characters that are not allowed in normalized wallpaper file names.

Functions

func DeleteFile

func DeleteFile(ctx context.Context, filename string) error

DeleteFile removes the named object from the wallpaper GCS bucket.

func FormatName

func FormatName(in string) string

FormatName formats a filename to match our requirements.

func FullRezURL

func FullRezURL(key string) string

FullRezURL returns the URL a cropped version hosted by imgix.

func GetFileCRC

func GetFileCRC(content []byte) uint32

GetFileCRC computes the CRC32C (Castagnoli) checksum of the given content.

func GetGoogleCRC

func GetGoogleCRC(ctx context.Context, filename string) (uint32, error)

GetGoogleCRC returns the CRC32C checksum that GCS has stored for the given object. If the object does not exist, it returns 0 with a nil error.

func RawURL

func RawURL(key string) string

RawURL returns the direct URL to the original file in GCS.

func ThumbURL

func ThumbURL(key string) string

ThumbURL returns the URL a small cropped version hosted by imgix.

func UploadFile

func UploadFile(ctx context.Context, filename string, content []byte) error

UploadFile takes a file name and content and uploads it to GoogleCloud.

Types

type File

type File struct {
	CRC32C       uint32    `json:"-"`
	Etag         string    `json:"etag"`
	FileURL      string    `json:"-"`
	FullRezURL   string    `json:"cdn"`
	Name         string    `json:"key"`
	Size         int64     `json:"-"`
	ThumbnailURL string    `json:"thumbnail"`
	Created      time.Time `json:"created_at"`
	Updated      time.Time `json:"updated_at"`
}

File is a subset of storage.ObjectAttrs that we need.

func GetAll

func GetAll(ctx context.Context) ([]*File, error)

GetAll returns all of the attributes for files in GCS.

Directories

Path Synopsis
Package analysis provides image analysis functionality including color extraction, resolution detection, and Gemini API integration.
Package analysis provides image analysis functionality including color extraction, resolution detection, and Gemini API integration.
cmd
server command
Command server runs the wallpapers HTTP service: it serves the web UI, JSON API, and metrics endpoint backed by the wallpapers SQLite database.
Command server runs the wallpapers HTTP service: it serves the web UI, JSON API, and metrics endpoint backed by the wallpapers SQLite database.
server/static
Package static embeds the HTML templates, CSS, and other static assets served by the wallpapers HTTP server.
Package static embeds the HTML templates, CSS, and other static assets served by the wallpapers HTTP server.
uploader command
Command uploader walks the local Dropbox wallpapers folder, normalizes filenames, upscales small images, uploads new/changed files to GCS, and records image metadata in the wallpapers database.
Command uploader walks the local Dropbox wallpapers folder, normalizes filenames, upscales small images, uploads new/changed files to GCS, and records image metadata in the wallpapers database.
Package db provides SQLite database operations for image metadata.
Package db provides SQLite database operations for image metadata.

Jump to

Keyboard shortcuts

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