refs #1028 Use authorized request to get instance information when start streamings

This commit is contained in:
AkiraFukushima 2019-09-14 22:44:43 +09:00
parent 2a8f3ec226
commit 0510b0920e
1 changed files with 6 additions and 2 deletions

View File

@ -1,9 +1,13 @@
import Mastodon, { WebSocket as SocketListener, Status, Notification, Instance } from 'megalodon'
import Mastodon, { WebSocket as SocketListener, Status, Notification, Instance, Response } from 'megalodon'
import log from 'electron-log'
import { LocalAccount } from '~/src/types/localAccount'
const StreamingURL = async (account: LocalAccount): Promise<string> => {
const res = await Mastodon.get<Instance>('/api/v1/instance', {}, account.baseURL)
if (!account.accessToken) {
throw new Error('access token is empty')
}
const client = new Mastodon(account.accessToken, account.baseURL + '/api/v1')
const res: Response<Instance> = await client.get<Instance>('/instance')
return res.data.urls.streaming_api
}