mirror of
https://gitplac.si/aljaxus/upn-qr.git
synced 2025-12-17 04:00:59 +00:00
uriencode API qrcode query parameters
This commit is contained in:
@@ -24,7 +24,7 @@ app.get('/api/qrcode', async (req, res) => {
|
|||||||
function check (name, rgxp) {
|
function check (name, rgxp) {
|
||||||
if (!req.query[name]) errors.push(`${name} is required`)
|
if (!req.query[name]) errors.push(`${name} is required`)
|
||||||
else {
|
else {
|
||||||
req.query[name] = String(req.query[name]).trim()
|
req.query[name] = decodeURIComponent(String(req.query[name])).trim()
|
||||||
if (!String(req.query[name]).match(rgxp)) {
|
if (!String(req.query[name]).match(rgxp)) {
|
||||||
errors.push(`${name} does not match the required format`)
|
errors.push(`${name} does not match the required format`)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ app.get('/api/qrcode', async (req, res) => {
|
|||||||
check('client_address', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
check('client_address', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
check('client_city', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
check('client_city', /^[a-zA-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ]{0,31}[A-Z0-9ČŠŽĐ])?$/i)
|
||||||
check('amount', /^(?=.{11}$)[0]{1,11}[0-9]{0,11}$/)
|
check('amount', /^(?=.{11}$)[0]{1,11}[0-9]{0,11}$/)
|
||||||
check('payment_purpose', /^[A-Z0-9ČŠŽĐ](?:[A-Z0-9 ČŠŽĐ\-:;_'"]{0,40}[A-Z0-9ČŠŽĐ])?$/i)
|
check('payment_purpose', /^.{1,42}$/i)
|
||||||
check('iban', /^[A-Z]{2}\d{17}$/)
|
check('iban', /^[A-Z]{2}\d{17}$/)
|
||||||
check('reference', /^[A-Z]{2}[0-9\-]{1,24}$/)
|
check('reference', /^[A-Z]{2}[0-9\-]{1,24}$/)
|
||||||
check('issuer_name', /^[a-zA-Z0-9ČŠŽĐ'](?:[A-Z0-9 ČŠŽĐ']{0,31}[A-Z0-9ČŠŽĐ'])?$/i)
|
check('issuer_name', /^[a-zA-Z0-9ČŠŽĐ'](?:[A-Z0-9 ČŠŽĐ']{0,31}[A-Z0-9ČŠŽĐ'])?$/i)
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ section div {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<script>
|
<script>
|
||||||
function val (name) { return document.getElementsByName(name)?.[0]?.value || "" }
|
function val (name) { return encodeURIComponent(document.getElementsByName(name)?.[0]?.value) || "" }
|
||||||
function getNewUrl () {
|
function getNewUrl () {
|
||||||
const qstring = [
|
const qstring = [
|
||||||
["client_name", val("client-name")],
|
["client_name", val("client-name")],
|
||||||
@@ -117,7 +117,7 @@ function getNewUrl () {
|
|||||||
["issuer_address", val("issuer-address")],
|
["issuer_address", val("issuer-address")],
|
||||||
["issuer_city", val("issuer-city")],
|
["issuer_city", val("issuer-city")],
|
||||||
].map(v => `${v[0]}=${v[1]}`).join("&")
|
].map(v => `${v[0]}=${v[1]}`).join("&")
|
||||||
return `${window.location.origin}/api/qrcode?${qstring}`
|
return encodeURI(`${window.location.origin}/api/qrcode?${qstring}`)
|
||||||
}
|
}
|
||||||
const copyBtn = document.getElementById("copyurl")
|
const copyBtn = document.getElementById("copyurl")
|
||||||
copyBtn.addEventListener("click", () => copyUrl())
|
copyBtn.addEventListener("click", () => copyUrl())
|
||||||
@@ -136,7 +136,6 @@ function copyUrl () {
|
|||||||
copyBtn.innerText = "Copy image URL"
|
copyBtn.innerText = "Copy image URL"
|
||||||
copyBtn.classList.remove("success")
|
copyBtn.classList.remove("success")
|
||||||
}, 750)
|
}, 750)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
copyBtn.innerText = "Failed!"
|
copyBtn.innerText = "Failed!"
|
||||||
@@ -145,7 +144,6 @@ function copyUrl () {
|
|||||||
copyBtn.innerText = "Copy image URL"
|
copyBtn.innerText = "Copy image URL"
|
||||||
copyBtn.classList.remove("error")
|
copyBtn.classList.remove("error")
|
||||||
}, 750)
|
}, 750)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user