Merge pull request #1033 from h3poteto/iss-1028

closes #1028 Use authorized request to get instance information when start streamings
This commit is contained in:
AkiraFukushima 2019-09-14 22:51:05 +09:00 committed by GitHub
commit 501c79c621
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 log from 'electron-log'
import { LocalAccount } from '~/src/types/localAccount' import { LocalAccount } from '~/src/types/localAccount'
const StreamingURL = async (account: LocalAccount): Promise<string> => { 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 return res.data.urls.streaming_api
} }