diff --git a/services/mastodon/mastodon-follow.service.js b/services/mastodon/mastodon-follow.service.js index 1507b22009561..ba601c8ad6246 100644 --- a/services/mastodon/mastodon-follow.service.js +++ b/services/mastodon/mastodon-follow.service.js @@ -1,6 +1,6 @@ import Joi from 'joi' import { metric } from '../text-formatters.js' -import { optionalUrl, nonNegativeInteger } from '../validators.js' +import { nonNegativeInteger } from '../validators.js' import { BaseJsonService, NotFound, pathParam, queryParam } from '../index.js' const schema = Joi.object({ @@ -9,15 +9,11 @@ const schema = Joi.object({ }) const queryParamSchema = Joi.object({ - domain: optionalUrl, + domain: Joi.string().optional(), }).required() const description = ` -To find your user id, you can use [this tool](https://prouser123.me/misc/mastodon-userid-lookup.html). - -Alternatively you can make a request to \`https://your.mastodon.server/.well-known/webfinger?resource=acct:@\` - -Failing that, you can also visit your profile page, where your user ID will be in the header in a tag like this: \`\` +To find your user id, you can make a request to \`https://your.mastodon.server/api/v1/accounts/lookup?acct=yourusername\`. ` export default class MastodonFollow extends BaseJsonService { @@ -41,7 +37,7 @@ export default class MastodonFollow extends BaseJsonService { }), queryParam({ name: 'domain', - example: 'https://mastodon.social', + example: 'mastodon.social', }), ], }, @@ -58,8 +54,8 @@ export default class MastodonFollow extends BaseJsonService { message: metric(followers), style: 'social', link: [ - `${domain}/users/${username}`, - `${domain}/users/${username}/followers`, + `https://${domain}/users/${username}`, + `https://${domain}/users/${username}/followers`, ], } } @@ -67,13 +63,14 @@ export default class MastodonFollow extends BaseJsonService { async fetch({ id, domain }) { return this._requestJson({ schema, - url: `${domain}/api/v1/accounts/${id}/`, + url: `https://${domain}/api/v1/accounts/${id}/`, }) } - async handle({ id }, { domain = 'https://mastodon.social' }) { + async handle({ id }, { domain = 'mastodon.social' }) { if (isNaN(id)) throw new NotFound({ prettyMessage: 'invalid user id format' }) + domain = domain.replace(/^https?:\/\//, '') const data = await this.fetch({ id, domain }) return this.constructor.render({ username: data.username, diff --git a/services/mastodon/mastodon-follow.tester.js b/services/mastodon/mastodon-follow.tester.js index d55d3706d531e..c1af88b829867 100644 --- a/services/mastodon/mastodon-follow.tester.js +++ b/services/mastodon/mastodon-follow.tester.js @@ -28,6 +28,17 @@ t.create('Followers - default domain - invalid user ID (id not in use)') }) t.create('Followers - alternate domain') + .get('/2214.json?domain=mastodon.xyz') + .expectBadge({ + label: 'follow @PhotonQyv', + message: isMetric, + link: [ + 'https://mastodon.xyz/users/PhotonQyv', + 'https://mastodon.xyz/users/PhotonQyv/followers', + ], + }) + +t.create('Followers - alternate domain legacy') .get('/2214.json?domain=https%3A%2F%2Fmastodon.xyz') .expectBadge({ label: 'follow @PhotonQyv',