mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
Renew [Mastodon] docs and improve parameter handling (#10789)
* refactor: handle parameter as domain and not url * docs: update Mastodon documentation * test: adapt Mastodon tests to changes * style: replace substring expressions with RegEx Co-authored-by: chris48s <chris48s@users.noreply.github.com> --------- Co-authored-by: chris48s <chris48s@users.noreply.github.com>
This commit is contained in:
parent
1b00489f57
commit
41d072e1c9
@ -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:<user>@<domain>\`
|
||||
|
||||
Failing that, you can also visit your profile page, where your user ID will be in the header in a tag like this: \`<link href='https://your.mastodon.server/api/salmon/<your-user-id>' rel='salmon'>\`
|
||||
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,
|
||||
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user