mirror of
https://github.com/direct-img/direct-img.link.git
synced 2026-10-11 15:45:20 +00:00
- free.direct-img.link serves only unrestricted (public domain/CC0) images from Openverse (license=cc0,pdm) and Wikimedia Commons (haslicense:unrestricted), with optional ?src=openverse|wikimedia - ?i=1..20 picks the i-th working image on both sites; broken links are skipped so every index is a different image - Openverse OAuth token is cached in KV and refreshed automatically - Skip Flickr "photo unavailable" placeholders (served with HTTP 200) - Free/indexed cache keys use uppercase prefixes; plain main-site keys are unchanged so existing cache entries stay valid - Update README, homepage, privacy policy and terms Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
739 B
JavaScript
20 lines
739 B
JavaScript
export async function wikimediaImageSearch(query, env, ua) {
|
|
const params = new URLSearchParams({
|
|
action: "query", format: "json", formatversion: 2,
|
|
generator: "search", gsrsearch: `${query} filetype:bitmap haslicense:unrestricted`, gsrnamespace: 6, gsrlimit: 30,
|
|
prop: "imageinfo", iiprop: "url", iiurlwidth: 1920,
|
|
});
|
|
try {
|
|
const res = await fetch(`https://commons.wikimedia.org/w/api.php?${params}`, { headers: { "User-Agent": ua } });
|
|
if (!res.ok) return null;
|
|
const pages = (await res.json()).query?.pages || [];
|
|
return pages
|
|
.sort((a, b) => a.index - b.index)
|
|
.map(p => p.imageinfo?.[0])
|
|
.filter(Boolean)
|
|
.map(ii => ii.thumburl || ii.url);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|