forked from Mirrors/doipjs
Adapt proxy URL generator to v2 API
This commit is contained in:
parent
5951315ebf
commit
f5964ed305
1 changed files with 12 additions and 15 deletions
27
src/utils.js
27
src/utils.js
|
@ -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) => {
|
||||||
|
|
Loading…
Reference in a new issue