mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-16 19:15:38 +00:00
feature: Email argument type (#433)
* feature: Email argument type * bugfix: Fix error if additional links is null
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/mail"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -137,10 +138,13 @@ func typecheckChoiceEntity(value string, arg *config.ActionArgument) error {
|
|||||||
// TypeSafetyCheck checks argument values match a specific type. The types are
|
// TypeSafetyCheck checks argument values match a specific type. The types are
|
||||||
// defined in typecheckRegex, and, you guessed it, uses regex to check for allowed
|
// defined in typecheckRegex, and, you guessed it, uses regex to check for allowed
|
||||||
// characters.
|
// characters.
|
||||||
|
//gocyclo:ignore
|
||||||
func TypeSafetyCheck(name string, value string, argumentType string) error {
|
func TypeSafetyCheck(name string, value string, argumentType string) error {
|
||||||
switch argumentType {
|
switch argumentType {
|
||||||
case "password":
|
case "password":
|
||||||
return nil
|
return nil
|
||||||
|
case "email":
|
||||||
|
return typeSafetyCheckEmail(name, value)
|
||||||
case "url":
|
case "url":
|
||||||
return typeSafetyCheckUrl(name, value)
|
return typeSafetyCheckUrl(name, value)
|
||||||
case "datetime":
|
case "datetime":
|
||||||
@@ -150,6 +154,18 @@ func TypeSafetyCheck(name string, value string, argumentType string) error {
|
|||||||
return typeSafetyCheckRegex(name, value, argumentType)
|
return typeSafetyCheckRegex(name, value, argumentType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func typeSafetyCheckEmail(name string, value string) error {
|
||||||
|
_, err := mail.ParseAddress(value)
|
||||||
|
|
||||||
|
log.Errorf("Email check: %v, %v", err, value)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func typeSafetyCheckDatetime(name string, value string) error {
|
func typeSafetyCheckDatetime(name string, value string) error {
|
||||||
_, err := time.Parse("2006-01-02T15:04:05", value)
|
_, err := time.Parse("2006-01-02T15:04:05", value)
|
||||||
|
|
||||||
|
|||||||
@@ -120,54 +120,61 @@ class ArgumentForm extends window.HTMLElement {
|
|||||||
for (const choice of arg.choices) {
|
for (const choice of arg.choices) {
|
||||||
domEl.appendChild(this.createSelectOption(choice))
|
domEl.appendChild(this.createSelectOption(choice))
|
||||||
}
|
}
|
||||||
} else if (arg.type === 'confirmation') {
|
|
||||||
this.domBtnStart.disabled = true
|
|
||||||
|
|
||||||
domEl = document.createElement('input')
|
|
||||||
domEl.setAttribute('type', 'checkbox')
|
|
||||||
domEl.onchange = () => {
|
|
||||||
this.domBtnStart.disabled = false
|
|
||||||
domEl.disabled = true
|
|
||||||
}
|
|
||||||
} else if (arg.type === 'datetime') {
|
|
||||||
domEl = document.createElement('input')
|
|
||||||
domEl.setAttribute('type', 'datetime-local')
|
|
||||||
domEl.setAttribute('step', '1')
|
|
||||||
} else if (arg.type === 'password') {
|
|
||||||
domEl = document.createElement('input')
|
|
||||||
domEl.setAttribute('type', 'password')
|
|
||||||
} else {
|
} else {
|
||||||
domEl = document.createElement('input')
|
switch (arg.type) {
|
||||||
|
case 'confirmation':
|
||||||
|
this.domBtnStart.disabled = true
|
||||||
|
|
||||||
if (arg.type.startsWith('regex:')) {
|
domEl = document.createElement('input')
|
||||||
domEl.setAttribute('pattern', arg.type.replace('regex:', ''))
|
domEl.setAttribute('type', 'checkbox')
|
||||||
}
|
domEl.onchange = () => {
|
||||||
|
this.domBtnStart.disabled = false
|
||||||
domEl.onchange = () => {
|
domEl.disabled = true
|
||||||
const validateArgumentTypeArgs = {
|
|
||||||
value: domEl.value,
|
|
||||||
type: arg.type
|
|
||||||
}
|
|
||||||
|
|
||||||
window.fetch(window.restBaseUrl + 'ValidateArgumentType', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(validateArgumentTypeArgs)
|
|
||||||
}).then((res) => {
|
|
||||||
if (res.ok) {
|
|
||||||
return res.json()
|
|
||||||
} else {
|
|
||||||
throw new Error(res.statusText)
|
|
||||||
}
|
}
|
||||||
}).then((json) => {
|
break
|
||||||
if (json.valid) {
|
case 'datetime':
|
||||||
domEl.setCustomValidity('')
|
domEl = document.createElement('input')
|
||||||
} else {
|
domEl.setAttribute('type', 'datetime-local')
|
||||||
domEl.setCustomValidity(json.description)
|
domEl.setAttribute('step', '1')
|
||||||
|
break
|
||||||
|
case 'password':
|
||||||
|
case 'email':
|
||||||
|
domEl = document.createElement('input')
|
||||||
|
domEl.setAttribute('type', arg.type)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
domEl = document.createElement('input')
|
||||||
|
|
||||||
|
if (arg.type.startsWith('regex:')) {
|
||||||
|
domEl.setAttribute('pattern', arg.type.replace('regex:', ''))
|
||||||
|
}
|
||||||
|
|
||||||
|
domEl.onchange = () => {
|
||||||
|
const validateArgumentTypeArgs = {
|
||||||
|
value: domEl.value,
|
||||||
|
type: arg.type
|
||||||
|
}
|
||||||
|
|
||||||
|
window.fetch(window.restBaseUrl + 'ValidateArgumentType', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(validateArgumentTypeArgs)
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.ok) {
|
||||||
|
return res.json()
|
||||||
|
} else {
|
||||||
|
throw new Error(res.statusText)
|
||||||
|
}
|
||||||
|
}).then((json) => {
|
||||||
|
if (json.valid) {
|
||||||
|
domEl.setCustomValidity('')
|
||||||
|
} else {
|
||||||
|
domEl.setCustomValidity(json.description)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ function processWebuiSettingsJson (settings) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processAdditionaLinks (links) {
|
function processAdditionaLinks (links) {
|
||||||
if (links === undefined) {
|
if (links === null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user