-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Mastodon to blocked services #100
Changes from all commits
9cde1cf
2bc5029
103fd35
c44c05b
c5e4cdb
3a6f008
0b5072a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ const path = require('path'); | |
const fs = require('fs'); | ||
const md5 = require('md5'); | ||
const hostlistCompiler = require('@adguard/hostlist-compiler'); | ||
const mastodonServerlistCompiler = require('adguard-hostlists-builder/mastodon'); | ||
|
||
const HOSTLISTS_URL = 'https://adguardteam.github.io/HostlistsRegistry/assets'; | ||
|
||
const CONFIGURATION_FILE = 'configuration.json'; | ||
const REVISION_FILE = 'revision.json'; | ||
const METADATA_FILE = 'metadata.json'; | ||
const SERVICES_FILE = 'services.json'; | ||
|
||
const FILTERS_METADATA_FILE = 'filters.json'; | ||
const FILTERS_METADATA_DEV_FILE = "filters-dev.json"; | ||
|
@@ -253,6 +255,28 @@ async function build(filtersDir, tagsDir, localesDir, assetsDir) { | |
filtersMetadataDev.push(filterMetadata); | ||
} | ||
|
||
// Build Mastodon dynamic server list | ||
let services = JSON.parse(readFile(path.join(assetsDir, SERVICES_FILE))); | ||
const mastodonServers = await mastodonServerlistCompiler(); | ||
|
||
const mastodonIndex = services.blocked_services | ||
.findIndex((el) => { | ||
return el.id === 'mastodon'; | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need additional checks for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 100 seems like a fair limit. Just as an additional check, you want to sort them by total user count ? So that only the top 100 servers are blocked? |
||
if (mastodonIndex == -1) { | ||
throw Error("Mastodon service not found") | ||
} | ||
|
||
// Set Mastodon server list to be blocked | ||
const mastodonService = services.blocked_services[mastodonIndex]; | ||
mastodonService.rules = mastodonServers; | ||
services.blocked_services[mastodonIndex] = mastodonService; | ||
|
||
// Write Mastodon dynamic server list to service.json | ||
const servicesFile = path.join(assetsDir, SERVICES_FILE); | ||
writeFile(servicesFile, JSON.stringify(services, undefined, 2)); | ||
|
||
// copy tags as is | ||
const tagsMetadata = JSON.parse(readFile(path.join(tagsDir, METADATA_FILE))); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Returns an array of objects containing the following fields; | ||
* "domain": <string>, | ||
* "version": <string>, | ||
* "description": <string>, | ||
* "languages": Array<string> - containing ISO 639-1 language codes (en, fr, de), | ||
* "region": <string>, | ||
* "categories": Array<string> - A list of catgories | ||
* "proxied_thumbnail": <string>, | ||
* "total_users": <int>, | ||
* "last_week_users": <int>, | ||
* "approval_required": <boolean>, | ||
* "language": <string> - containing ISO 639-1 language code (en, fr, de), | ||
* "category": <string> | ||
* | ||
* @returns {Promise<Array>} | ||
*/ | ||
const serverList = async function () { | ||
/** | ||
* | ||
* @type {Promise<Response>} | ||
*/ | ||
let servers = await (await fetch('https://api.joinmastodon.org/servers')) | ||
.json(); | ||
|
||
// Sort servers by total_users | ||
servers = servers.sort((a, b) => { | ||
if (a.total_users > b.total_users) { | ||
return -1; | ||
} | ||
|
||
if (a.total_users < b.total_users) { | ||
return 1; | ||
} | ||
|
||
return 0; | ||
}); | ||
|
||
// Separately add the two Instances by Mastodon GmbH themselves. | ||
servers.unshift({ | ||
domain: "mastodon.social" | ||
}, { | ||
domain: "mastodon.online" | ||
}); | ||
|
||
return servers | ||
.slice(0, 99); | ||
} | ||
|
||
// Compile server list | ||
const compile = async function () { | ||
const result = (await serverList()); | ||
|
||
const mastodonRules = result.map((element) => { | ||
if (!element.hasOwnProperty('domain')) { | ||
throw Error("Domain key not found in server list") | ||
} | ||
|
||
return `||${element.domain}^` | ||
}); | ||
|
||
return mastodonRules; | ||
} | ||
|
||
module.exports = compile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since Mastodon logic is not related to hostlists and for better clarity I'd prefer to have it all in a separate file (
mastodon.js
) imported intoindex.js