Fixed linter errors
This commit is contained in:
parent
1819367160
commit
506fd3c0a7
@ -11,6 +11,9 @@ linters:
|
|||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- gochecknoinits
|
- gochecknoinits
|
||||||
- gocyclo
|
- gocyclo
|
||||||
|
- gocognit
|
||||||
|
- gosec
|
||||||
- maligned
|
- maligned
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- funlen
|
- funlen
|
||||||
|
- wsl
|
@ -22,6 +22,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
discordNickRegex = regexp.MustCompile(`^([^#]{2,32})#(\d{4})$`)
|
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.
|
// 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.
|
// Email tests if the given email address is valid.
|
||||||
func Email(email string) bool {
|
func Email(email string) bool {
|
||||||
// TODO: Add email check
|
return emailRegex.MatchString(email)
|
||||||
return email != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// URI validates a URI.
|
// URI validates a URI.
|
||||||
|
@ -28,6 +28,9 @@ func TestIsValidNick(t *testing.T) {
|
|||||||
|
|
||||||
func TestIsValidEmail(t *testing.T) {
|
func TestIsValidEmail(t *testing.T) {
|
||||||
assert.False(t, validate.Email(""))
|
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"))
|
assert.True(t, validate.Email("support@notify.moe"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +164,6 @@ func InstallTwitterAuth(app *aero.Application) {
|
|||||||
user.Nick = "tw" + twUser.ID
|
user.Nick = "tw" + twUser.ID
|
||||||
user.Email = twUser.Email
|
user.Email = twUser.Email
|
||||||
user.LastLogin = arn.DateTimeUTC()
|
user.LastLogin = arn.DateTimeUTC()
|
||||||
|
|
||||||
// TODO: The full name is in the Name field
|
|
||||||
user.FirstName = twUser.Name
|
user.FirstName = twUser.Name
|
||||||
|
|
||||||
// Save basic user info already to avoid data inconsistency problems
|
// Save basic user info already to avoid data inconsistency problems
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package graphql
|
package graphql
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
@ -39,55 +37,55 @@ func Install(app *aero.Application) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Like objects
|
// Like objects
|
||||||
api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
|
// api.AddRootResolver(func(name string, arguments graphql.Map) (interface{}, error, bool) {
|
||||||
if !strings.HasPrefix(name, "like") {
|
// if !strings.HasPrefix(name, "like") {
|
||||||
return nil, nil, false
|
// 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")
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// likeable.Like(user.ID)
|
// id, ok := arguments["ID"].(string)
|
||||||
|
|
||||||
// Call OnLike if the object implements it
|
// if !ok {
|
||||||
// receiver, ok := likeable.(LikeEventReceiver)
|
// return nil, fmt.Errorf("'%s' needs to specify an ID", name), true
|
||||||
|
|
||||||
// if ok {
|
|
||||||
// receiver.OnLike(user)
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
likeable.Save()
|
// typeName := strings.TrimPrefix(name, "like")
|
||||||
return obj, nil, true
|
// 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())
|
app.Post("/graphql", api.Handler())
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ func main() {
|
|||||||
|
|
||||||
if anime == nil {
|
if anime == nil {
|
||||||
color.Yellow(episode.AnimeID)
|
color.Yellow(episode.AnimeID)
|
||||||
episode.Delete()
|
_ = episode.Delete()
|
||||||
count++
|
count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user