Skip to content

Commit

Permalink
refactor: use @microlink/ping-url
Browse files Browse the repository at this point in the history
It's like reachable-url but it keeps the value in redis
  • Loading branch information
Kikobeats committed Mar 23, 2023
1 parent 1c1ce63 commit 30b5bb1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@keyvhq/multi": "~1.6.26",
"@keyvhq/redis": "~1.6.28",
"@microlink/mql": "~0.10.32",
"@microlink/ping-url": "~1.4.6",
"async-ratelimiter": "~1.3.7",
"browserless": "~9.9.4",
"cacheable-lookup": "~6.1.0",
Expand Down Expand Up @@ -116,7 +117,6 @@
"p-timeout": "~4.1.0",
"puppeteer": "~19.7.5",
"qsm": "~2.1.2",
"reachable-url": "~1.7.1",
"router-http": "~1.0.0",
"send-http": "~1.0.2",
"serve-static": "~1.15.0",
Expand Down
5 changes: 2 additions & 3 deletions src/avatar/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

const isAbsoluteUrl = require('is-absolute-url')
const dataUriRegex = require('data-uri-regex')
const reachableUrl = require('reachable-url')
const isEmail = require('is-email-like')
const pTimeout = require('p-timeout')
const urlRegex = require('url-regex')
const pAny = require('p-any')

const { providers, providersBy } = require('../providers')
const reachableUrl = require('../util/reachable-url')
const isIterable = require('../util/is-iterable')
const ExtendableError = require('../util/error')
const { gotOpts } = require('../util/got')

const { STATUS_CODES } = require('http')
const { AVATAR_TIMEOUT } = require('../constant')
Expand Down Expand Up @@ -43,7 +42,7 @@ const getAvatarContent = name => async input => {
})
}

const { statusCode, url } = await reachableUrl(input, gotOpts)
const { statusCode, url } = await reachableUrl(input)

if (!reachableUrl.isReachable({ statusCode })) {
throw new ExtendableError({
Expand Down
20 changes: 20 additions & 0 deletions src/util/reachable-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const createPingUrl = require('@microlink/ping-url')

const { gotOpts } = require('./got')
const { createRedisCache } = require('./keyv')

const pingCache = createRedisCache({ namespace: 'ping' })

const pingUrl = createPingUrl(pingCache, {
value: ({ url, statusCode }) => ({ url, statusCode })
})

module.exports = (url, opts) =>
pingUrl(url, {
...gotOpts,
...opts
})

module.exports.isReachable = createPingUrl.isReachable

0 comments on commit 30b5bb1

Please sign in to comment.