Adapt proxy URL generator to v2 API

This commit is contained in:
Yarmo Mackenbach 2021-04-16 11:36:59 +02:00
parent 5951315ebf
commit f5964ed305
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1

View file

@ -13,28 +13,25 @@ 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 validator = require('validator')
const E = require('./enums') const E = require('./enums')
const generateProxyURL = (type, urlElements, opts) => { const generateProxyURL = (type, data, opts) => {
if (!opts || !opts.doipProxyHostname) { try {
return null validator.isFQDN(opts.proxy.hostname)
} } catch (err) {
let addParam = '' throw new Error(`Invalid proxy hostname`)
if (type == 'xmpp') {
addParam += '/DESC'
} }
if (!Array.isArray(urlElements)) { let queryStrings = []
urlElements = [urlElements]
}
urlElements = urlElements.map((x) => { Object.keys(data).forEach(key => {
return encodeURIComponent(x) queryStrings.push(`${key}=${encodeURIComponent(data[key])}`)
}) })
return `https://${ return `http://${
opts.doipProxyHostname opts.proxy.hostname
}/api/1/get/${type}/${urlElements.join('/')}${addParam}` }/api/2/get/${type}?${queryStrings.join('&')}`
} }
const generateClaim = (fingerprint, format) => { const generateClaim = (fingerprint, format) => {