Skip to content

zryyyy/wallpaper-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Wallpaper API

A lightweight, edge-rendered wallpaper API built with Cloudflare Workers & Hono.

Features

  • Multi-Source Aggregation: Fetch wallpapers from multiple popular platforms using a unified interface.
  • Scheduled Updates: Uses Cloudflare Workers Cron Triggers (0 0 * * *) to automatically fetch and cache a daily collection of wallpapers into Cloudflare KV.
  • Direct Image Redirects: Every source includes a /pic endpoint that directly redirects the client to the raw image URL.
  • Edge-Ready: Built for Cloudflare Workers for global, low-latency responses.
  • Type-Safe Validation: Query parameters are strictly validated using Valibot.
  • Modern Tooling: Uses Biome for fast formatting and linting.

Project Structure

.
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts                 # Main application entry point and router setup
β”‚   β”œβ”€β”€ jobs/
β”‚   β”‚   └── updateWallpapers.ts  # Scheduled cron job to fetch and cache wallpapers in KV
β”‚   β”œβ”€β”€ routes/                  # API route definitions and parameter validation
β”‚   β”‚   β”œβ”€β”€ bing.ts
β”‚   β”‚   β”œβ”€β”€ pexels.ts
β”‚   β”‚   β”œβ”€β”€ random.ts
β”‚   β”‚   β”œβ”€β”€ unsplash.ts
β”‚   β”‚   └── wallhaven.ts
β”‚   β”œβ”€β”€ services/                # Core logic and external API integrations
β”‚   β”‚   β”œβ”€β”€ bing.ts
β”‚   β”‚   β”œβ”€β”€ pexels.ts
β”‚   β”‚   β”œβ”€β”€ random.ts
β”‚   β”‚   β”œβ”€β”€ unsplash.ts
β”‚   β”‚   └── wallhaven.ts
β”‚   └── utils/                   # Shared utilities (fetch client, array shuffler)
β”‚       β”œβ”€β”€ client.ts
β”‚       └── shuffle.ts
β”œβ”€β”€ wrangler.jsonc               # Cloudflare Workers configuration
β”œβ”€β”€ biome.json                   # Biome linter/formatter configuration
└── package.json                 # Project dependencies and scripts

Getting Started

  1. Clone the repository and install dependencies:

    npm install
  2. Set up Environment Variables:

    Create a .dev.vars file in the root directory for local development to store your API keys:

    UNSPLASH_ACCESS_KEY=your_unsplash_key
    PEXELS_API_KEY=your_pexels_key
    WALLHAVEN_API_KEY=your_wallhaven_key
  3. Start the local development server:

    npm run dev

Scripts

  • npm run dev - Start the local development server using Wrangler.
  • npm run deploy - Deploy the project to Cloudflare Workers.
  • npm run lint - Check for linting errors using Biome.
  • npm run fmt - Format code using Biome.
  • npm run typecheck - Run TypeScript compiler checks.

About

πŸ‘» A lightweight, edge-rendered wallpaper API built with Cloudflare Workers & Hono.

Topics

Resources

Stars

Watchers

Forks

Contributors