API使用说明
使用本服务获取任意网站的favicon图标,支持多种尺寸和格式。
基本用法
<img src="https://您的域名/api/favicon?domain=github.com" alt="图标">
参数说明
| 参数 |
说明 |
可选值 |
默认值 |
domain |
网站域名 |
任何有效域名 |
必填 |
size |
图标尺寸 |
16, 24, 32, 48, 64, 96, 128, 192, 256 |
32 |
format |
图标格式 |
png, ico, svg |
自动 |
direct |
是否直接从网站获取 |
true, false |
false |
nocache |
忽略缓存,强制刷新 |
true, false |
false |
source |
指定图标来源 |
google, googlev2, faviconim |
自动 |
示例
指定尺寸和格式
https://您的域名/api/favicon?domain=github.com&size=64&format=png
直接从网站获取
https://您的域名/api/favicon?domain=github.com&direct=true
跳过缓存,强制刷新
https://您的域名/api/favicon?domain=github.com&nocache=true
指定图标来源
https://您的域名/api/favicon?domain=github.com&source=googlev2
缓存系统说明
本服务使用了优化的缓存策略,提高响应速度和可靠性:
- 仅使用D1和R2进行存储和读取,不使用KV保存
- 域名级别缓存,每个域名只保存一份图标
- R2存储限制为8GB,超过限制时不再存储新域名的图标
- 单个图标大小限制为512KB,超过限制的图标将被拒绝
- 当D1超过读取限制时,自动使用R2读取
高级API功能
1. 批量获取多个域名的图标
使用批量API一次获取多个域名的图标信息,返回JSON格式的结果。
https://您的域名/api/batch-favicon?domains=github.com,google.com,apple.com&size=64
2. 获取图标详细信息
获取图标的详细信息,包括尺寸、格式、来源等,返回JSON格式的结果。
https://您的域名/api/favicon-info?domain=github.com&size=64
响应示例:
{
"success": true,
"domain": "github.com",
"image": {
"type": "image/png",
"extension": "png",
"size_bytes": 5461,
"width": 64,
"height": 64
},
"request": {
"size": "64",
"format": null,
"direct": false,
"source": "auto"
},
"source": {
"cached": true,
"cache_source": "D1",
"original_source": "google",
"content_type": "image/png"
},
"urls": {
"favicon": "/api/favicon?domain=github.com&size=64",
"info": "/api/favicon-info?domain=github.com&size=64"
}
}
3. 存储统计API
获取R2和D1存储的统计信息,包括存储大小、对象数量、域名数量等。
https://您的域名/api/storage-stats
响应示例:
{
"success": true,
"timestamp": "2023-06-01T12:34:56.789Z",
"r2": {
"available": true,
"total_size": 1073741824,
"total_size_formatted": "1.00 GB",
"object_count": 5000,
"domain_count": 1000,
"last_updated": "2023-06-01T12:30:00.000Z"
},
"d1": {
"available": true,
"total_icons": 5000,
"domain_count": 1000,
"total_size": 536870912,
"total_size_formatted": "512.00 MB"
}
}