mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-22 08:36:21 +01:00
Switch to the list from joinmastodon.org/servers
This commit is contained in:
parent
49cdba2652
commit
14b92f3f98
4 changed files with 349 additions and 694 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -25,6 +25,5 @@ dist-ssr
|
||||||
|
|
||||||
# Custom
|
# Custom
|
||||||
.env.dev
|
.env.dev
|
||||||
src/data/instances-full.json
|
|
||||||
phanpy-dist.zip
|
phanpy-dist.zip
|
||||||
phanpy-dist.tar.gz
|
phanpy-dist.tar.gz
|
|
@ -103,8 +103,7 @@ Prerequisites: Node.js 18+
|
||||||
- `npm run dev` - Start development server
|
- `npm run dev` - Start development server
|
||||||
- `npm run build` - Build for production
|
- `npm run build` - Build for production
|
||||||
- `npm run preview` - Preview the production build
|
- `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`
|
- `npm run fetch-instances` - Fetch instances list from [joinmastodon.org/servers](https://joinmastodon.org/servers), save it to `src/data/instances.json`
|
||||||
- requires `.env.local` file with `INSTANCES_SOCIAL_SECRET_TOKEN` variable set
|
|
||||||
- `npm run sourcemap` - Run `source-map-explorer` on the production build
|
- `npm run sourcemap` - Run `source-map-explorer` on the production build
|
||||||
|
|
||||||
## Tech stack
|
## Tech stack
|
||||||
|
|
|
@ -1,34 +1,12 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
const { INSTANCES_SOCIAL_SECRET_TOKEN } = process.env;
|
const url = 'https://api.joinmastodon.org/servers';
|
||||||
|
const results = await fetch(url);
|
||||||
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 json = await results.json();
|
const json = await results.json();
|
||||||
|
|
||||||
// Filters
|
const domains = json.map((instance) => instance.domain);
|
||||||
json.instances = json.instances.filter(
|
|
||||||
(instance) => Number(instance.connections) > 20,
|
|
||||||
);
|
|
||||||
|
|
||||||
const names = json.instances.map((instance) => instance.name);
|
|
||||||
|
|
||||||
// Write to file
|
// Write to file
|
||||||
const path = './src/data/instances.json';
|
const path = './src/data/instances.json';
|
||||||
fs.writeFileSync(path, JSON.stringify(names, null, '\t'), 'utf8');
|
fs.writeFileSync(path, JSON.stringify(domains, 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');
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue