diff --git a/setting/index.js b/setting/index.js index 5cebbe9..9c136f4 100644 --- a/setting/index.js +++ b/setting/index.js @@ -72,8 +72,13 @@ function GetTOTPList(storage){ placeholder: "otpauth://", label: "Change OTP link", onChange: (changes) => { + try{ storage[elementId] = getTOTPByLink(changes) updateStorage(storage) + } + catch(err){ + console.log(err) + } }, labelStyle: { backgroundColor: "#14213D", diff --git a/setting/utils/queryParser.js b/setting/utils/queryParser.js index f016b32..98cff2d 100644 --- a/setting/utils/queryParser.js +++ b/setting/utils/queryParser.js @@ -3,6 +3,7 @@ import { TOTP } from "../../lib/totp-quickjs"; const otpScheme = "otpauth:/"; export function getTOTPByLink(link){ + try{ let args = link.split("/", otpScheme.length) let type = args[2] //Returns 'hotp' or 'totp' let issuer = args[3].split(':')[0]?.split('?')[0] //Returns issuer @@ -11,12 +12,15 @@ export function getTOTPByLink(link){ let period = args[3].split('period=')[1]?.split('&')[0] //Returns period let digits = args[3].split('digits=')[1]?.split('&')[0] //Returns digits let algorithm = args[3].split('algorithm=')[1]?.split('&')[0] //Returns algorithm - + } + catch(err){ + throw new Error("Link is not valid") + } if(type.toLowerCase() != 'totp') - return Error("Type is not valid, requires 'TOTP'") + throw new Error("Type is not valid, requires 'TOTP'") if(secret === undefined) - return Error("Secret not defined") + throw new Error("Secret not defined") issuer = issuer.replace("%20", " ") client = client.replace("%20", " ")