Switch to the list from joinmastodon.org/servers

This commit is contained in:
Lim Chee Aun 2024-02-17 16:49:50 +08:00
parent 49cdba2652
commit 14b92f3f98
4 changed files with 349 additions and 694 deletions

1
.gitignore vendored
View file

@ -25,6 +25,5 @@ dist-ssr
# Custom
.env.dev
src/data/instances-full.json
phanpy-dist.zip
phanpy-dist.tar.gz

View file

@ -103,8 +103,7 @@ Prerequisites: Node.js 18+
- `npm run dev` - Start development server
- `npm run build` - Build for production
- `npm run preview` - Preview the production build
- `npm run fetch-instances` - Fetch instances list from [instances.social](https://instances.social/), save it to `src/data/instances.json`
- requires `.env.local` file with `INSTANCES_SOCIAL_SECRET_TOKEN` variable set
- `npm run fetch-instances` - Fetch instances list from [joinmastodon.org/servers](https://joinmastodon.org/servers), save it to `src/data/instances.json`
- `npm run sourcemap` - Run `source-map-explorer` on the production build
## Tech stack

View file

@ -1,34 +1,12 @@
import fs from 'fs';
const { INSTANCES_SOCIAL_SECRET_TOKEN } = process.env;
const params = new URLSearchParams({
count: 0,
min_users: 500,
sort_by: 'active_users',
sort_order: 'desc',
});
const url = `https://instances.social/api/1.0/instances/list?${params.toString()}`;
const results = await fetch(url, {
headers: {
Authorization: `Bearer ${INSTANCES_SOCIAL_SECRET_TOKEN}`,
},
});
const url = 'https://api.joinmastodon.org/servers';
const results = await fetch(url);
const json = await results.json();
// Filters
json.instances = json.instances.filter(
(instance) => Number(instance.connections) > 20,
);
const names = json.instances.map((instance) => instance.name);
const domains = json.map((instance) => instance.domain);
// Write to file
const path = './src/data/instances.json';
fs.writeFileSync(path, JSON.stringify(names, null, '\t'), 'utf8');
// Write everything to file, for debugging
const path2 = './src/data/instances-full.json';
fs.writeFileSync(path2, JSON.stringify(json, null, '\t'), 'utf8');
fs.writeFileSync(path, JSON.stringify(domains, null, '\t'), 'utf8');

File diff suppressed because it is too large Load diff