Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as readline from 'readline'
import Mastodon, { OAuth } from 'megalodon'
const rl: readline.ReadLine = readline.createInterface({
input: process.stdin,
output: process.stdout
})
const SCOPES: string = 'read write follow'
const BASE_URL: string = 'https://mastodon.social'
let clientId: string
let clientSecret: string
Mastodon.registerApp('Test App', {
scopes: SCOPES
}, BASE_URL).then(appData => {
clientId = appData.clientId
clientSecret = appData.clientSecret
console.log('Authorization URL is generated.')
console.log(appData.url)
console.log()
return new Promise(resolve => {
rl.question('Enter the authorization code from website: ', code => {
resolve(code)
rl.close()
})
})
}).then((code: string) => {
return Mastodon.fetchAccessToken(clientId, clientSecret, code, BASE_URL)
})
async getAuthorizationUrl(domain = 'mastodon.social', proxy: ProxyConfig | false): Promise {
this.setOtherInstance(domain)
const res = await Mastodon.registerApp(
appName,
{
scopes: scope,
website: appURL
},
this.baseURL,
proxy
)
this.clientId = res.clientId
this.clientSecret = res.clientSecret
const order = await this.db
.lastAccount()
.then(account => account.order + 1)
.catch(err => {
console.log(err)
private static async setup(event: Event, instance: string, useURLScheme: boolean) {
let appData: OAuth.AppData
try {
let options: Partial<{ scopes: string, redirect_uris: string, website: string }> = {
scopes: "read write follow",
website: "https://thedesk.top",
}
if (useURLScheme) {
options.redirect_uris = this.redirectUri
}
appData = await Mastodon.registerApp(
"TheDesk",
options,
"https://" + instance
)
} catch (err) {
let error: Error = err
event.sender.send(`error`, {
id: "ERROR_CONNECTION",
message: "Connection error",
meta: error
})
return
}
let url: string | null = appData.url
if (url === null) {