Add network module, flaresolverr options

This commit is contained in:
Yarmo Mackenbach 2022-12-01 09:21:51 +01:00
parent 1720c59093
commit d76cee1b2b
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
3 changed files with 65 additions and 3 deletions

View file

@ -49,6 +49,10 @@ const opts = {
hostname: null, hostname: null,
policy: E.ProxyPolicy.NEVER policy: E.ProxyPolicy.NEVER
}, },
flaresolverr: {
url: '',
maxTimeout: 60000
},
claims: { claims: {
activitypub: { activitypub: {
url: null, url: null,

View file

@ -13,7 +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 axios = require('axios') const network = require('../network')
const validator = require('validator') const validator = require('validator')
const jsEnv = require('browser-or-node') const jsEnv = require('browser-or-node')
@ -80,10 +80,10 @@ module.exports.fn = async (data, opts) => {
headers.signature = `keyId="${opts.claims.activitypub.url}#main-key",headers="(request-target) host date",signature="${signatureSig}",algorithm="rsa-sha256"` headers.signature = `keyId="${opts.claims.activitypub.url}#main-key",headers="(request-target) host date",signature="${signatureSig}",algorithm="rsa-sha256"`
} }
axios.get(data.url, network.get(data.url,
{ {
headers headers
}) }, opts)
.then(res => { .then(res => {
return res.data return res.data
}) })

58
src/network.js Normal file
View file

@ -0,0 +1,58 @@
/*
Copyright 2022 Yarmo Mackenbach
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
const axios = require('axios')
/**
* Network related functions
* @module keys
*/
/**
* Make a GET HTTP request
* @function
* @param {string} url - URL for the Axios request
* @param {object} requestConfig - Config for Axios request
* @param {object} opts - doip options
* @returns {object}
*/
const get = (url, requestConfig, opts) => {
return new Promise((resolve, reject) => {
switch (opts.flaresolverr.url === '') {
case false:
axios.get(url, requestConfig)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
break
case true:
default:
axios.get(url, requestConfig)
.then(res => {
resolve(res)
})
.catch(err => {
reject(err)
})
break
}
})
}
exports.get = get