Use megalodon instead of mastodon-api as mastodon api client in main process
This commit is contained in:
parent
4a877956bb
commit
a46eb5ab07
89
package-lock.json
generated
89
package-lock.json
generated
@ -42,11 +42,42 @@
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"@types/caseless": {
|
||||
"version": "0.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.1.tgz",
|
||||
"integrity": "sha512-FhlMa34NHp9K5MY1Uz8yb+ZvuX0pnvn3jScRSNAb75KHGB8d3rEU6hqMs3Z2vjuytcMfRg6c5CHMc3wtYyD2/A=="
|
||||
},
|
||||
"@types/form-data": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/form-data/-/form-data-2.2.1.tgz",
|
||||
"integrity": "sha512-JAMFhOaHIciYVh8fb5/83nmuO/AHwmto+Hq7a9y8FzLDcC1KCU344XDOMEmahnrTFlHjgh4L0WJFczNIX2GxnQ==",
|
||||
"requires": {
|
||||
"@types/node": "8.9.4"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "8.9.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-8.9.4.tgz",
|
||||
"integrity": "sha512-dSvD36qnQs78G1BPsrZFdPpvLgMW/dnvr5+nTW2csMs5TiP9MOXrjUbnMZOEwnIuBklXtn7b6TPA2Cuq07bDHA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-dSvD36qnQs78G1BPsrZFdPpvLgMW/dnvr5+nTW2csMs5TiP9MOXrjUbnMZOEwnIuBklXtn7b6TPA2Cuq07bDHA=="
|
||||
},
|
||||
"@types/oauth": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/oauth/-/oauth-0.9.0.tgz",
|
||||
"integrity": "sha512-1oouefxKPGiDkb5m6lNxDkFry3PItCOJ+tlNtEn/gRvWShb2Rb3y0pccOIGwN/AwHUpwsuwlRwSpg7aoCN3bQQ==",
|
||||
"requires": {
|
||||
"@types/node": "8.9.4"
|
||||
}
|
||||
},
|
||||
"@types/request": {
|
||||
"version": "2.47.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.47.0.tgz",
|
||||
"integrity": "sha512-/KXM5oev+nNCLIgBjkwbk8VqxmzI56woD4VUxn95O+YeQ8hJzcSmIZ1IN3WexiqBb6srzDo2bdMbsXxgXNkz5Q==",
|
||||
"requires": {
|
||||
"@types/caseless": "0.12.1",
|
||||
"@types/form-data": "2.2.1",
|
||||
"@types/node": "8.9.4",
|
||||
"@types/tough-cookie": "2.3.3"
|
||||
}
|
||||
},
|
||||
"@types/tapable": {
|
||||
"version": "1.0.0",
|
||||
@ -54,6 +85,11 @@
|
||||
"integrity": "sha512-DrV8VQDeDAJwWqiV+QceN4EHKd3scPPYiwrXr476y7T+2hMoOaH43NVGoaDM3siCz69h/1vMabKaMgMF539qFQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/tough-cookie": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-2.3.3.tgz",
|
||||
"integrity": "sha512-MDQLxNFRLasqS4UlkWMSACMKeSm1x4Q3TxzUC7KQUsh6RK1ZrQ0VEyE3yzXcBu+K8ejVj4wuX32eUG02yNp+YQ=="
|
||||
},
|
||||
"@types/uglify-js": {
|
||||
"version": "2.6.30",
|
||||
"resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-2.6.30.tgz",
|
||||
@ -7800,7 +7836,7 @@
|
||||
},
|
||||
"onetime": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
|
||||
"resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
|
||||
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k="
|
||||
},
|
||||
"pluralize": {
|
||||
@ -10702,6 +10738,48 @@
|
||||
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
|
||||
"dev": true
|
||||
},
|
||||
"megalodon": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/megalodon/-/megalodon-0.1.0.tgz",
|
||||
"integrity": "sha512-4PjAXECAdZgbsWYkErN8bSHHpQ9fBiBoBTZ0riDIUWYBQTVdZq5zNZsU4TcO1ypvAkiWC5CS+2brjFbQcRcXXg==",
|
||||
"requires": {
|
||||
"@types/oauth": "0.9.0",
|
||||
"@types/request": "2.47.0",
|
||||
"axios": "0.18.0",
|
||||
"oauth": "0.9.15",
|
||||
"request": "2.87.0",
|
||||
"typescript": "2.9.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"request": {
|
||||
"version": "2.87.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.87.0.tgz",
|
||||
"integrity": "sha512-fcogkm7Az5bsS6Sl0sibkbhcKsnyon/jV1kF3ajGmF0c8HrttdKTPRT9hieOaQHA5HEq6r8OyWOo/o781C1tNw==",
|
||||
"requires": {
|
||||
"aws-sign2": "0.7.0",
|
||||
"aws4": "1.6.0",
|
||||
"caseless": "0.12.0",
|
||||
"combined-stream": "1.0.6",
|
||||
"extend": "3.0.1",
|
||||
"forever-agent": "0.6.1",
|
||||
"form-data": "2.3.2",
|
||||
"har-validator": "5.0.3",
|
||||
"http-signature": "1.2.0",
|
||||
"is-typedarray": "1.0.0",
|
||||
"isstream": "0.1.2",
|
||||
"json-stringify-safe": "5.0.1",
|
||||
"mime-types": "2.1.18",
|
||||
"oauth-sign": "0.8.2",
|
||||
"performance-now": "2.1.0",
|
||||
"qs": "6.5.1",
|
||||
"safe-buffer": "5.1.1",
|
||||
"tough-cookie": "2.3.4",
|
||||
"tunnel-agent": "0.6.0",
|
||||
"uuid": "3.2.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"mem": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz",
|
||||
@ -15914,6 +15992,11 @@
|
||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
|
||||
},
|
||||
"typescript": {
|
||||
"version": "2.9.1",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.1.tgz",
|
||||
"integrity": "sha512-h6pM2f/GDchCFlldnriOhs1QHuwbnmj6/v7499eMHqPeW4V2G0elua2eIc2nu8v2NdHV0Gm+tzX83Hr6nUFjQA=="
|
||||
},
|
||||
"uglify-js": {
|
||||
"version": "3.3.16",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.3.16.tgz",
|
||||
|
@ -97,6 +97,7 @@
|
||||
"hoek": "^5.0.3",
|
||||
"is-empty": "^1.2.0",
|
||||
"mastodon-api": "github:h3poteto/mastodon-api#lib",
|
||||
"megalodon": "^0.1.0",
|
||||
"moment": "^2.21.0",
|
||||
"mousetrap": "^1.6.2",
|
||||
"nedb": "^1.8.0",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import empty from 'is-empty'
|
||||
import Mastodon from 'mastodon-api'
|
||||
import Mastodon from 'megalodon'
|
||||
|
||||
export default class Account {
|
||||
constructor (db) {
|
||||
@ -167,21 +167,23 @@ export default class Account {
|
||||
refresh (account) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const client = new Mastodon(
|
||||
{
|
||||
access_token: account.accessToken,
|
||||
api_url: account.baseURL + '/api/v1'
|
||||
}
|
||||
account.accessToken,
|
||||
account.baseURL + '/api/v1'
|
||||
)
|
||||
client.get('/accounts/verify_credentials', (err, data, res) => {
|
||||
if (err) return reject(err)
|
||||
const json = {
|
||||
username: data.username,
|
||||
accountId: data.id,
|
||||
avatar: data.avatar
|
||||
}
|
||||
this.updateAccount(account._id, json)
|
||||
.then(ac => resolve(ac))
|
||||
})
|
||||
client.get('/accounts/verify_credentials')
|
||||
.then(data => {
|
||||
console.log(data)
|
||||
const json = {
|
||||
username: data.username,
|
||||
accountId: data.id,
|
||||
avatar: data.avatar
|
||||
}
|
||||
this.updateAccount(account._id, json)
|
||||
.then(ac => resolve(ac))
|
||||
})
|
||||
.catch(err => {
|
||||
return reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Mastodon from 'mastodon-api'
|
||||
import Mastodon from 'megalodon'
|
||||
|
||||
const appName = 'Whalebird'
|
||||
const appURL = 'https://whalebird.org'
|
||||
@ -23,15 +23,15 @@ export default class Authentication {
|
||||
|
||||
async getAuthorizationUrl (domain = 'mastodon.social') {
|
||||
this.setOtherInstance(domain)
|
||||
const res = await Mastodon.createOAuthApp(
|
||||
this.baseURL + '/api/v1/apps',
|
||||
appName,
|
||||
scope,
|
||||
'urn:ietf:wg:oauth:2.0:oob',
|
||||
appURL
|
||||
const res = await Mastodon.registerApp(
|
||||
appName, {
|
||||
scopes: scope,
|
||||
website: appURL
|
||||
},
|
||||
this.baseURL
|
||||
)
|
||||
this.clientId = res.client_id
|
||||
this.clientSecret = res.client_secret
|
||||
this.clientId = res.clientId
|
||||
this.clientSecret = res.clientSecret
|
||||
|
||||
const count = await this.db.countAuthorizedAccounts()
|
||||
const json = {
|
||||
@ -46,12 +46,11 @@ export default class Authentication {
|
||||
order: count + 1
|
||||
}
|
||||
await this.db.insertAccount(json)
|
||||
const url = await Mastodon.getAuthorizationUrl(this.clientId, this.clientSecret, this.baseURL)
|
||||
return url
|
||||
return res.url
|
||||
}
|
||||
|
||||
async getAccessToken (code) {
|
||||
const token = await Mastodon.getAccessToken(this.clientId, this.clientSecret, code, this.baseURL)
|
||||
const token = await Mastodon.fetchAccessToken(this.clientId, this.clientSecret, code, this.baseURL)
|
||||
const search = {
|
||||
baseURL: this.baseURL,
|
||||
domain: this.domain,
|
||||
@ -59,8 +58,9 @@ export default class Authentication {
|
||||
clientSecret: this.clientSecret
|
||||
}
|
||||
const rec = await this.db.searchAccount(search)
|
||||
await this.db.updateAccount(rec._id, { accessToken: token })
|
||||
return token
|
||||
const accessToken = token.access_token
|
||||
await this.db.updateAccount(rec._id, { accessToken: accessToken })
|
||||
return accessToken
|
||||
}
|
||||
// TODO: Refresh access token when expired
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
import Mastodon from 'mastodon-api'
|
||||
import Mastodon from 'megalodon'
|
||||
import log from 'electron-log'
|
||||
|
||||
export default class Streaming {
|
||||
constructor (account) {
|
||||
this.account = account
|
||||
this.client = new Mastodon(
|
||||
{
|
||||
access_token: account.accessToken,
|
||||
api_url: account.baseURL + '/api/v1'
|
||||
}
|
||||
account.accessToken,
|
||||
account.baseURL + '/api/v1'
|
||||
)
|
||||
this.listener = null
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user