mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-23 06:59:29 -07:00
Migrate bent to axios
This commit is contained in:
parent
0565446eae
commit
08e64425a7
8 changed files with 6128 additions and 5908 deletions
|
@ -6,7 +6,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xmpp/client": "^0.12.0",
|
"@xmpp/client": "^0.12.0",
|
||||||
"@xmpp/debug": "^0.12.0",
|
"@xmpp/debug": "^0.12.0",
|
||||||
"bent": "^7.3.12",
|
"axios": "^0.25.0",
|
||||||
"browser-or-node": "^1.3.0",
|
"browser-or-node": "^1.3.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
|
|
|
@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
const bent = require('bent')
|
const axios = require('axios')
|
||||||
const req = bent('GET')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @module fetcher/gitlab
|
* @module fetcher/gitlab
|
||||||
|
@ -47,9 +46,12 @@ module.exports.fn = async (data, opts) => {
|
||||||
const fetchPromise = new Promise((resolve, reject) => {
|
const fetchPromise = new Promise((resolve, reject) => {
|
||||||
const urlUser = `https://${data.domain}/api/v4/users?username=${data.username}`
|
const urlUser = `https://${data.domain}/api/v4/users?username=${data.username}`
|
||||||
// const resUser = await req(urlUser, null, { Accept: 'application/json' })
|
// const resUser = await req(urlUser, null, { Accept: 'application/json' })
|
||||||
const res = req(urlUser, null, { Accept: 'application/json' })
|
const res = axios.get(urlUser,
|
||||||
|
{
|
||||||
|
headers: { Accept: 'application/json' }
|
||||||
|
})
|
||||||
.then(resUser => {
|
.then(resUser => {
|
||||||
return resUser.json()
|
return resUser.data
|
||||||
})
|
})
|
||||||
.then(jsonUser => {
|
.then(jsonUser => {
|
||||||
return jsonUser.find((user) => user.username === data.username)
|
return jsonUser.find((user) => user.username === data.username)
|
||||||
|
@ -62,12 +64,13 @@ module.exports.fn = async (data, opts) => {
|
||||||
})
|
})
|
||||||
.then(user => {
|
.then(user => {
|
||||||
const urlProject = `https://${data.domain}/api/v4/users/${user.id}/projects`
|
const urlProject = `https://${data.domain}/api/v4/users/${user.id}/projects`
|
||||||
return req(urlProject, null, {
|
return axios.get(urlProject,
|
||||||
Accept: 'application/json'
|
{
|
||||||
})
|
headers: { Accept: 'application/json' }
|
||||||
|
})
|
||||||
})
|
})
|
||||||
.then(resProject => {
|
.then(resProject => {
|
||||||
return resProject.json()
|
return resProject.data
|
||||||
})
|
})
|
||||||
.then(jsonProject => {
|
.then(jsonProject => {
|
||||||
return jsonProject.find((proj) => proj.path === 'gitlab_proof')
|
return jsonProject.find((proj) => proj.path === 'gitlab_proof')
|
||||||
|
|
|
@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
const bent = require('bent')
|
const axios = require('axios')
|
||||||
const req = bent('GET')
|
|
||||||
const E = require('../enums')
|
const E = require('../enums')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,29 +52,33 @@ module.exports.fn = async (data, opts) => {
|
||||||
|
|
||||||
switch (data.format) {
|
switch (data.format) {
|
||||||
case E.ProofFormat.JSON:
|
case E.ProofFormat.JSON:
|
||||||
req(data.url, null, {
|
axios.get(data.url, {
|
||||||
Accept: 'application/json',
|
headers: {
|
||||||
'User-Agent': `doipjs/${require('../../package.json').version}`
|
Accept: 'application/json',
|
||||||
|
'User-Agent': `doipjs/${require('../../package.json').version}`
|
||||||
|
},
|
||||||
|
validateStatus: function (status) {
|
||||||
|
return status >= 200 && status < 400
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(res => {
|
||||||
return await res.json()
|
resolve(res.data)
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.catch(e => {
|
||||||
resolve(res)
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case E.ProofFormat.TEXT:
|
case E.ProofFormat.TEXT:
|
||||||
req(data.url)
|
axios.get(data.url, {
|
||||||
.then(async (res) => {
|
validateStatus: function (status) {
|
||||||
return await res.text()
|
return status >= 200 && status < 400
|
||||||
|
},
|
||||||
|
responseType: 'text'
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
resolve(res.data)
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.catch(e => {
|
||||||
resolve(res)
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
|
|
|
@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
const bent = require('bent')
|
const axios = require('axios')
|
||||||
const bentReq = bent('GET')
|
|
||||||
const validator = require('validator')
|
const validator = require('validator')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,11 +56,12 @@ module.exports.fn = async (data, opts) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `https://${opts.claims.matrix.instance}/_matrix/client/r0/rooms/${data.roomId}/event/${data.eventId}?access_token=${opts.claims.matrix.accessToken}`
|
const url = `https://${opts.claims.matrix.instance}/_matrix/client/r0/rooms/${data.roomId}/event/${data.eventId}?access_token=${opts.claims.matrix.accessToken}`
|
||||||
bentReq(url, null, {
|
axios.get(url,
|
||||||
Accept: 'application/json'
|
{
|
||||||
})
|
headers: { Accept: 'application/json' }
|
||||||
.then(async (res) => {
|
})
|
||||||
return await res.json()
|
.then(res => {
|
||||||
|
return res.data
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
|
|
|
@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
const bent = require('bent')
|
const axios = require('axios')
|
||||||
const bentReq = bent('GET')
|
|
||||||
const validator = require('validator')
|
const validator = require('validator')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,16 +54,17 @@ module.exports.fn = async (data, opts) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
bentReq(
|
axios.get(
|
||||||
`https://api.twitter.com/1.1/statuses/show.json?id=${data.tweetId}&tweet_mode=extended`,
|
`https://api.twitter.com/1.1/statuses/show.json?id=${data.tweetId}&tweet_mode=extended`,
|
||||||
null,
|
|
||||||
{
|
{
|
||||||
Accept: 'application/json',
|
headers: {
|
||||||
Authorization: `Bearer ${opts.claims.twitter.bearerToken}`
|
Accept: 'application/json',
|
||||||
|
Authorization: `Bearer ${opts.claims.twitter.bearerToken}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(async (data) => {
|
.then(data => {
|
||||||
return await data.json()
|
return data.data
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
resolve(data.full_text)
|
resolve(data.full_text)
|
||||||
|
|
12
src/keys.js
12
src/keys.js
|
@ -13,8 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
const bent = require('bent')
|
const axios = require('axios')
|
||||||
const req = bent('GET')
|
|
||||||
const validUrl = require('valid-url')
|
const validUrl = require('valid-url')
|
||||||
const openpgp = require('openpgp')
|
const openpgp = require('openpgp')
|
||||||
const Claim = require('./claim')
|
const Claim = require('./claim')
|
||||||
|
@ -99,13 +98,18 @@ exports.fetchKeybase = async (username, fingerprint) => {
|
||||||
const keyLink = `https://keybase.io/${username}/pgp_keys.asc?fingerprint=${fingerprint}`
|
const keyLink = `https://keybase.io/${username}/pgp_keys.asc?fingerprint=${fingerprint}`
|
||||||
let rawKeyContent
|
let rawKeyContent
|
||||||
try {
|
try {
|
||||||
rawKeyContent = await req(keyLink)
|
rawKeyContent = await axios.get(
|
||||||
|
keyLink,
|
||||||
|
{
|
||||||
|
responseType: 'text'
|
||||||
|
}
|
||||||
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((response) => response.text())
|
.then((response) => response.data)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`Error fetching Keybase key: ${e.message}`)
|
throw new Error(`Error fetching Keybase key: ${e.message}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
const router = require('express').Router()
|
const router = require('express').Router()
|
||||||
const dns = require('dns')
|
const dns = require('dns')
|
||||||
const bent = require('bent')
|
const axios = require('axios')
|
||||||
const bentReq = bent('GET')
|
|
||||||
const validUrl = require('valid-url')
|
const validUrl = require('valid-url')
|
||||||
const jsdom = require('jsdom')
|
const jsdom = require('jsdom')
|
||||||
const { client, xml } = require('@xmpp/client')
|
const { client, xml } = require('@xmpp/client')
|
||||||
|
@ -126,11 +125,14 @@ router.param('xmppdata', async (req, res, next, xmppdata) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/get/json/:url', (req, res) => {
|
router.get('/get/json/:url', (req, res) => {
|
||||||
bentReq(req.params.url, 'json', {
|
axios.get(req.params.url,
|
||||||
Accept: 'application/json'
|
{
|
||||||
})
|
headers: {
|
||||||
.then(async (result) => {
|
Accept: 'application/json'
|
||||||
return await result.json()
|
}
|
||||||
|
})
|
||||||
|
.then(result => {
|
||||||
|
return result.data
|
||||||
})
|
})
|
||||||
.then(async (result) => {
|
.then(async (result) => {
|
||||||
return res.status(200).json({ url: req.params.url, content: result })
|
return res.status(200).json({ url: req.params.url, content: result })
|
||||||
|
@ -141,9 +143,12 @@ router.get('/get/json/:url', (req, res) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
router.get('/get/text/:url', (req, res) => {
|
router.get('/get/text/:url', (req, res) => {
|
||||||
bentReq(req.params.url)
|
axios.get(req.params.url,
|
||||||
.then(async (result) => {
|
{
|
||||||
return await result.text()
|
responseType: 'text'
|
||||||
|
})
|
||||||
|
.then(result => {
|
||||||
|
return result.data
|
||||||
})
|
})
|
||||||
.then(async (result) => {
|
.then(async (result) => {
|
||||||
return res.status(200).json({ url: req.params.url, content: result })
|
return res.status(200).json({ url: req.params.url, content: result })
|
||||||
|
@ -238,16 +243,17 @@ router.get('/get/twitter/:tweetid', async (req, res) => {
|
||||||
return res.status(500).json('Twitter not enabled on server')
|
return res.status(500).json('Twitter not enabled on server')
|
||||||
}
|
}
|
||||||
|
|
||||||
bentReq(
|
axios.get(
|
||||||
`https://api.twitter.com/1.1/statuses/show.json?id=${req.params.tweetid}`,
|
`https://api.twitter.com/1.1/statuses/show.json?id=${req.params.tweetid}`,
|
||||||
null,
|
|
||||||
{
|
{
|
||||||
Accept: 'application/json',
|
headers: {
|
||||||
Authorization: `Bearer ${twitterBearerToken}`
|
Accept: 'application/json',
|
||||||
|
Authorization: `Bearer ${twitterBearerToken}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(async (data) => {
|
.then(data => {
|
||||||
return await data.json()
|
return data.data
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
return res.status(200).json({ data: data, message: 'Success', error: {} })
|
return res.status(200).json({ data: data, message: 'Success', error: {} })
|
||||||
|
@ -268,11 +274,14 @@ router.get('/get/matrix/:matrixroomid/:matrixeventid', async (req, res) => {
|
||||||
|
|
||||||
const url = `https://${matrixInstance}/_matrix/client/r0/rooms/${req.params.matrixroomid}/event/${req.params.matrixeventid}?access_token=${matrixAccessToken}`
|
const url = `https://${matrixInstance}/_matrix/client/r0/rooms/${req.params.matrixroomid}/event/${req.params.matrixeventid}?access_token=${matrixAccessToken}`
|
||||||
|
|
||||||
bentReq(url, null, {
|
axios.get(url,
|
||||||
Accept: 'application/json'
|
{
|
||||||
})
|
headers: {
|
||||||
.then(async (data) => {
|
Accept: 'application/json'
|
||||||
return await data.json()
|
}
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
return data.data
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
return res.status(200).json({ data: data, message: 'Success', error: {} })
|
return res.status(200).json({ data: data, message: 'Success', error: {} })
|
||||||
|
|
Loading…
Reference in a new issue