Skip to content

Commit

Permalink
Merge pull request #2172 from h3poteto/feat/gotosocial
Browse files Browse the repository at this point in the history
Add support gotosocial
  • Loading branch information
h3poteto authored May 1, 2024
2 parents 3adddc8 + a059b05 commit 1a1e8dc
Show file tree
Hide file tree
Showing 43 changed files with 4,266 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4
Expand Down
44 changes: 44 additions & 0 deletions example/typescript/src/gotosocial/authorization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import * as readline from 'readline'
import generator, { OAuth } from 'megalodon'

const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
output: process.stdout
})

const SCOPES: Array<string> = ['read', 'write', 'follow']
const BASE_URL: string = process.env.GOTOSOCIAL_URL!

let clientId: string
let clientSecret: string

const client = generator('gotosocial', BASE_URL)

client
.registerApp('Test App', {
scopes: SCOPES
})
.then(appData => {
clientId = appData.client_id
clientSecret = appData.client_secret
console.log('Authorization URL is generated.')
console.log(appData.url)
console.log()
return new Promise<string>(resolve => {
rl.question('Enter the authorization code from website: ', code => {
resolve(code)
rl.close()
})
})
})
.then((code: string) => {
return client.fetchAccessToken(clientId, clientSecret, code)
})
.then((tokenData: OAuth.TokenData) => {
console.log('\naccess_token:')
console.log(tokenData.access_token)
console.log('\nrefresh_token:')
console.log(tokenData.refresh_token)
console.log()
})
.catch((err: Error) => console.error(err))
9 changes: 9 additions & 0 deletions example/typescript/src/gotosocial/instance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import generator, { Entity, Response } from 'megalodon'

const BASE_URL: string = process.env.GOTOSOCIAL_URL!

const client = generator('gotosocial', BASE_URL)

client.getInstance().then((res: Response<Entity.Instance>) => {
console.log(res.data)
})
11 changes: 11 additions & 0 deletions example/typescript/src/gotosocial/timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import generator, { MegalodonInterface, Entity, Response } from 'megalodon'

const BASE_URL: string = process.env.GOTOSOCIAL_URL!

const access_token: string = process.env.GOTOSOCIAL_ACCESS_TOKEN!

const client: MegalodonInterface = generator('gotosocial', BASE_URL, access_token)

client.getPublicTimeline().then((resp: Response<Array<Entity.Status>>) => {
console.log(resp.data)
})
8 changes: 7 additions & 1 deletion megalodon/src/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Metadata = {
* @param proxyConfig Proxy setting, or set false if don't use proxy.
* @return SNS name.
*/
export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'friendica' | 'firefish'> => {
export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'friendica' | 'firefish' | 'gotosocial'> => {
const options: AxiosRequestConfig = {
timeout: 20000
}
Expand All @@ -71,6 +71,8 @@ export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'f
return 'firefish'
case 'iceshrimp':
return 'firefish'
case 'gotosocial':
return 'gotosocial'
default:
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') {
return 'mastodon'
Expand All @@ -93,6 +95,8 @@ export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'f
return 'firefish'
case 'iceshrimp':
return 'firefish'
case 'gotosocial':
return 'gotosocial'
default:
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') {
return 'mastodon'
Expand All @@ -115,6 +119,8 @@ export const detector = async (url: string): Promise<'mastodon' | 'pleroma' | 'f
return 'firefish'
case 'iceshrimp':
return 'firefish'
case 'gotosocial':
return 'gotosocial'
default:
if (res.data.metadata.upstream?.name && res.data.metadata.upstream.name === 'mastodon') {
return 'mastodon'
Expand Down
2 changes: 1 addition & 1 deletion megalodon/src/entities/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Poll } from './poll'
export type Status = {
id: string
uri: string
url: string
url?: string
account: Account
in_reply_to_id: string | null
in_reply_to_account_id: string | null
Expand Down
Loading

0 comments on commit 1a1e8dc

Please sign in to comment.