chore: bump version to 2.0.32
This commit is contained in:
+46
-22
@@ -2,10 +2,13 @@
|
|||||||
* FediDB API client with MongoDB caching.
|
* FediDB API client with MongoDB caching.
|
||||||
*
|
*
|
||||||
* Wraps https://api.fedidb.org/v1/ endpoints:
|
* Wraps https://api.fedidb.org/v1/ endpoints:
|
||||||
* - /servers?q=... — search known fediverse instances
|
* - /servers — cursor-paginated list of known fediverse instances (ranked by size)
|
||||||
* - /popular-accounts — top accounts by follower count
|
* - /popular-accounts — top accounts by follower count
|
||||||
*
|
*
|
||||||
* Responses are cached in ap_kv to avoid hitting the API on every keystroke.
|
* NOTE: The /servers endpoint ignores query params (q, search, name) and always
|
||||||
|
* returns the same ranked list. We paginate through ~500 servers, cache the full
|
||||||
|
* corpus for 24 hours, and filter locally when the user searches.
|
||||||
|
*
|
||||||
* Cache TTL: 24 hours for both datasets.
|
* Cache TTL: 24 hours for both datasets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -71,41 +74,62 @@ async function writeToCache(kvCollection, cacheKey, data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the full FediDB server list (up to 40, the API max).
|
* Fetch the FediDB server catalogue by paginating through cursor-based results.
|
||||||
* Cached for 24 hours as a single entry. The API ignores query params
|
* Cached for 24 hours as a single entry. The API ignores the `q` param and
|
||||||
* and always returns the same ranked-by-MAU list, so we fetch once
|
* always returns a ranked list, so we collect a large corpus and filter locally.
|
||||||
* and filter client-side in searchInstances().
|
*
|
||||||
|
* Paginates up to MAX_PAGES (13 pages × 40 = ~520 servers), which covers
|
||||||
|
* all well-known instances. Results are cached in ap_kv for 24 hours.
|
||||||
*
|
*
|
||||||
* @param {object} kvCollection - MongoDB ap_kv collection
|
* @param {object} kvCollection - MongoDB ap_kv collection
|
||||||
* @returns {Promise<Array>}
|
* @returns {Promise<Array>}
|
||||||
*/
|
*/
|
||||||
|
const MAX_PAGES = 13;
|
||||||
|
|
||||||
async function getAllServers(kvCollection) {
|
async function getAllServers(kvCollection) {
|
||||||
const cacheKey = "fedidb:servers-all";
|
const cacheKey = "fedidb:servers-all";
|
||||||
const cached = await getFromCache(kvCollection, cacheKey);
|
const cached = await getFromCache(kvCollection, cacheKey);
|
||||||
if (cached) return cached;
|
if (cached) return cached;
|
||||||
|
|
||||||
|
const results = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = `${API_BASE}/servers?limit=40`;
|
let cursor = null;
|
||||||
const res = await fetchWithTimeout(url);
|
|
||||||
if (!res.ok) return [];
|
|
||||||
|
|
||||||
const json = await res.json();
|
for (let page = 0; page < MAX_PAGES; page++) {
|
||||||
const servers = json.data || [];
|
let url = `${API_BASE}/servers?limit=40`;
|
||||||
|
if (cursor) url += `&cursor=${cursor}`;
|
||||||
|
|
||||||
const results = servers.map((s) => ({
|
const res = await fetchWithTimeout(url);
|
||||||
domain: s.domain,
|
if (!res.ok) break;
|
||||||
software: s.software?.name || "Unknown",
|
|
||||||
description: s.description || "",
|
|
||||||
mau: s.stats?.monthly_active_users || 0,
|
|
||||||
userCount: s.stats?.user_count || 0,
|
|
||||||
openRegistration: s.open_registration || false,
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeToCache(kvCollection, cacheKey, results);
|
const json = await res.json();
|
||||||
return results;
|
const servers = json.data || [];
|
||||||
|
if (servers.length === 0) break;
|
||||||
|
|
||||||
|
for (const s of servers) {
|
||||||
|
results.push({
|
||||||
|
domain: s.domain,
|
||||||
|
software: s.software?.name || "Unknown",
|
||||||
|
description: s.description || "",
|
||||||
|
mau: s.stats?.monthly_active_users || 0,
|
||||||
|
userCount: s.stats?.user_count || 0,
|
||||||
|
openRegistration: s.open_registration || false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor = json.meta?.next_cursor;
|
||||||
|
if (!cursor) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.length > 0) {
|
||||||
|
await writeToCache(kvCollection, cacheKey, results);
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
return [];
|
// Return whatever we collected so far
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rmdes/indiekit-endpoint-activitypub",
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
||||||
"version": "2.0.31",
|
"version": "2.0.32",
|
||||||
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"indiekit",
|
"indiekit",
|
||||||
|
|||||||
Reference in New Issue
Block a user