mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-16 11:05:32 +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"
|
||||
|
||||
"errors"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -137,10 +138,13 @@ func typecheckChoiceEntity(value string, arg *config.ActionArgument) error {
|
||||
// TypeSafetyCheck checks argument values match a specific type. The types are
|
||||
// defined in typecheckRegex, and, you guessed it, uses regex to check for allowed
|
||||
// characters.
|
||||
//gocyclo:ignore
|
||||
func TypeSafetyCheck(name string, value string, argumentType string) error {
|
||||
switch argumentType {
|
||||
case "password":
|
||||
return nil
|
||||
case "email":
|
||||
return typeSafetyCheckEmail(name, value)
|
||||
case "url":
|
||||
return typeSafetyCheckUrl(name, value)
|
||||
case "datetime":
|
||||
@@ -150,6 +154,18 @@ func TypeSafetyCheck(name string, value string, argumentType string) error {
|
||||
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 {
|
||||
_, err := time.Parse("2006-01-02T15:04:05", value)
|
||||
|
||||
|
||||
@@ -120,7 +120,9 @@ class ArgumentForm extends window.HTMLElement {
|
||||
for (const choice of arg.choices) {
|
||||
domEl.appendChild(this.createSelectOption(choice))
|
||||
}
|
||||
} else if (arg.type === 'confirmation') {
|
||||
} else {
|
||||
switch (arg.type) {
|
||||
case 'confirmation':
|
||||
this.domBtnStart.disabled = true
|
||||
|
||||
domEl = document.createElement('input')
|
||||
@@ -129,14 +131,18 @@ class ArgumentForm extends window.HTMLElement {
|
||||
this.domBtnStart.disabled = false
|
||||
domEl.disabled = true
|
||||
}
|
||||
} else if (arg.type === 'datetime') {
|
||||
break
|
||||
case 'datetime':
|
||||
domEl = document.createElement('input')
|
||||
domEl.setAttribute('type', 'datetime-local')
|
||||
domEl.setAttribute('step', '1')
|
||||
} else if (arg.type === 'password') {
|
||||
break
|
||||
case 'password':
|
||||
case 'email':
|
||||
domEl = document.createElement('input')
|
||||
domEl.setAttribute('type', 'password')
|
||||
} else {
|
||||
domEl.setAttribute('type', arg.type)
|
||||
break
|
||||
default:
|
||||
domEl = document.createElement('input')
|
||||
|
||||
if (arg.type.startsWith('regex:')) {
|
||||
@@ -170,6 +176,7 @@ class ArgumentForm extends window.HTMLElement {
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
domEl.name = arg.name
|
||||
domEl.value = arg.defaultValue
|
||||
|
||||
@@ -134,7 +134,7 @@ function processWebuiSettingsJson (settings) {
|
||||
}
|
||||
|
||||
function processAdditionaLinks (links) {
|
||||
if (links === undefined) {
|
||||
if (links === null) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user