Fixed linter errors
This commit is contained in:
parent
1819367160
commit
506fd3c0a7
@ -11,6 +11,9 @@ linters:
|
||||
- gochecknoglobals
|
||||
- gochecknoinits
|
||||
- gocyclo
|
||||
- gocognit
|
||||
- gosec
|
||||
- maligned
|
||||
- stylecheck
|
||||
- funlen
|
||||
- wsl
|
@ -22,6 +22,7 @@ const (
|
||||
|
||||
var (
|
||||
discordNickRegex = regexp.MustCompile(`^([^#]{2,32})#(\d{4})$`)
|
||||
emailRegex = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||
)
|
||||
|
||||
// Nick tests if the given nickname is valid.
|
||||
@ -70,8 +71,7 @@ func YearMonth(date string) bool {
|
||||
|
||||
// Email tests if the given email address is valid.
|
||||
func Email(email string) bool {
|
||||
// TODO: Add email check
|
||||
return email != ""
|
||||
return emailRegex.MatchString(email)
|
||||
}
|
||||
|
||||
// URI validates a URI.
|
||||
|
@ -28,6 +28,9 @@ func TestIsValidNick(t *testing.T) {
|
||||
|
||||
func TestIsValidEmail(t *testing.T) {
|
||||
assert.False(t, validate.Email(""))
|
||||
assert.False(t, validate.Email("ç$€§/az@gmail.com"))
|
||||
assert.False(t, validate.Email("abc@gmail_yahoo.com"))
|
||||
assert.True(t, validate.Email("abc@gmail-yahoo.com"))
|
||||
assert.True(t, validate.Email("support@notify.moe"))
|
||||
}
|
||||
|
||||
|
@ -164,8 +164,6 @@ func InstallTwitterAuth(app *aero.Application) {
|
||||
user.Nick = "tw" + twUser.ID
|
||||
user.Email = twUser.Email
|
||||
user.LastLogin = arn.DateTimeUTC()
|
||||
|
||||
// TODO: The full name is in the Name field
|
||||
user.FirstName = twUser.Name
|
||||
|
||||
// Save basic user info already to avoid data inconsistency problems
|
||||
|
@ -1,9 +1,7 @@
|
||||
package graphql
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
@ -39,55 +37,55 @@ func Install(app *aero.Application) {
|
||||
})
|
||||
|
||||
// Like objects
|
||||
api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
|
||||
if !strings.HasPrefix(name, "like") {
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
id, ok := arguments["ID"].(string)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("'%s' needs to specify an ID", name), true
|
||||
}
|
||||
|
||||
typeName := strings.TrimPrefix(name, "like")
|
||||
obj, err := arn.DB.Get(typeName, id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err, true
|
||||
}
|
||||
|
||||
field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft")
|
||||
|
||||
if field.IsValid() && field.Bool() {
|
||||
return nil, errors.New("Drafts need to be published before they can be liked"), true
|
||||
}
|
||||
|
||||
likeable, ok := obj.(arn.Likeable)
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true
|
||||
}
|
||||
|
||||
// TODO: Authentication
|
||||
// user := GetUserFromContext(ctx)
|
||||
|
||||
// if user == nil {
|
||||
// return errors.New("Not logged in")
|
||||
// api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
|
||||
// if !strings.HasPrefix(name, "like") {
|
||||
// return nil, nil, false
|
||||
// }
|
||||
|
||||
// likeable.Like(user.ID)
|
||||
// id, ok := arguments["ID"].(string)
|
||||
|
||||
// Call OnLike if the object implements it
|
||||
// receiver, ok := likeable.(LikeEventReceiver)
|
||||
|
||||
// if ok {
|
||||
// receiver.OnLike(user)
|
||||
// if !ok {
|
||||
// return nil, fmt.Errorf("'%s' needs to specify an ID", name), true
|
||||
// }
|
||||
|
||||
likeable.Save()
|
||||
return obj, nil, true
|
||||
})
|
||||
// typeName := strings.TrimPrefix(name, "like")
|
||||
// obj, err := arn.DB.Get(typeName, id)
|
||||
|
||||
// if err != nil {
|
||||
// return nil, err, true
|
||||
// }
|
||||
|
||||
// field := reflect.ValueOf(obj).Elem().FieldByName("IsDraft")
|
||||
|
||||
// if field.IsValid() && field.Bool() {
|
||||
// return nil, errors.New("Drafts need to be published before they can be liked"), true
|
||||
// }
|
||||
|
||||
// likeable, ok := obj.(arn.Likeable)
|
||||
|
||||
// if !ok {
|
||||
// return nil, fmt.Errorf("'%s' does not implement the Likeable interface", name), true
|
||||
// }
|
||||
|
||||
// // TODO: Authentication
|
||||
// // user := GetUserFromContext(ctx)
|
||||
|
||||
// // if user == nil {
|
||||
// // return errors.New("Not logged in")
|
||||
// // }
|
||||
|
||||
// // likeable.Like(user.ID)
|
||||
|
||||
// // Call OnLike if the object implements it
|
||||
// // receiver, ok := likeable.(LikeEventReceiver)
|
||||
|
||||
// // if ok {
|
||||
// // receiver.OnLike(user)
|
||||
// // }
|
||||
|
||||
// likeable.Save()
|
||||
// return obj, nil, true
|
||||
// })
|
||||
|
||||
app.Post("/graphql", api.Handler())
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func main() {
|
||||
|
||||
if anime == nil {
|
||||
color.Yellow(episode.AnimeID)
|
||||
episode.Delete()
|
||||
_ = episode.Delete()
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user