-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2172 from h3poteto/feat/gotosocial
Add support gotosocial
- Loading branch information
Showing
43 changed files
with
4,266 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.