Skip to content

Commit

Permalink
Merge pull request #2185 from h3poteto/fix/detector
Browse files Browse the repository at this point in the history
Fix detector for capitalized upstream name
  • Loading branch information
h3poteto committed Jun 19, 2024
2 parents 95042d9 + 4d75ea5 commit 1a6cd89
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions megalodon/src/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'f
case 'gotosocial':
return 'gotosocial'
default:
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') {
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name.toLowerCase() === 'mastodon') {
return 'mastodon'
}
throw new NodeinfoError('Unknown SNS')
Expand All @@ -98,7 +98,7 @@ export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'f
case 'gotosocial':
return 'gotosocial'
default:
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') {
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name.toLowerCase() === 'mastodon') {
return 'mastodon'
}
throw new NodeinfoError('Unknown SNS')
Expand All @@ -122,7 +122,7 @@ export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'f
case 'gotosocial':
return 'gotosocial'
default:
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') {
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name.toLowerCase() === 'mastodon') {
return 'mastodon'
}
throw new NodeinfoError('Unknown SNS')
Expand Down
8 changes: 8 additions & 0 deletions megalodon/test/integration/detector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe('detector', () => {
})
})

describe('kmy.blue', () => {
const url = 'https://kmy.blue'
it('should be mastodon', async () => {
const kmyblue = await detector(url)
expect(kmyblue).toEqual('mastodon')
})
})

describe('unknown', () => {
const url = 'https://google.com'
it('should be null', async () => {
Expand Down

0 comments on commit 1a6cd89

Please sign in to comment.