add libravatar/style endpoint

This commit is contained in:
Jon Lundy 2020-11-28 15:11:49 -07:00
parent b56f27dcfb
commit 616997fdc6
Signed by untrusted user who does not match committer: xuu
GPG Key ID: C63E6D61F3035024
7 changed files with 60 additions and 22 deletions

1
.gitignore vendored
View File

@ -16,3 +16,4 @@
sour.is-keyproofs
.env
/pub

View File

@ -1,5 +1,7 @@
# Rename to '.env' or pass required items to environment when running.
# Basic Configuration.
# REDDIT_APIKEY [REQUIRED]
# REDDIT_SECRET [REQUIRED]
# To prevent reddits low ratelimits for non-authenticated requests
@ -26,6 +28,12 @@ HTTP_LISTEN=
BASE_URL=
# AVATAR_PATH [OPTIONAL]
# To set the path for avatar/bg/cover image directories to serve. (default: pub)
# Path should allow read/write to application. The folders will be generated automatically.
# Advanced Options. These are used to customize the application in non-standard deployments
# XMPP_URL [OPTIONAL]
# To set XMPP http url for VCard verification. (default: BASE_URL)
@ -35,3 +43,20 @@ XMPP_URL=
# To set DNS http url for DNS verification. (default: BASE_URL)
XMPP_URL=
# Avatar app
# DISABLE_AVATAR [OPTIONAL]
# Disable the Avatar application. Set to any value other than "false"
# DNS app
# DISABLE_DNS [OPTIONAL]
# Disable the DNS application. Set to any value other than "false"
# Keyproofs app
# DISABLE_KEYPROOFS [OPTIONAL]
# Disable the KeyProofs application. Set to any value other than "false"
# XMPP VCard app
# DISABLE_VCARD [OPTIONAL]
# Disable the VCard application. Set to any value other than "false"
# If disabled the username/password are no longer required.

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/sour-is/keyproofs
go 1.15
require (
github.com/fsnotify/fsnotify v1.4.7
github.com/go-chi/chi v4.1.2+incompatible
github.com/google/go-cmp v0.5.4 // indirect
github.com/hashicorp/golang-lru v0.5.4

1
go.sum
View File

@ -138,6 +138,7 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190927073244-c990c680b611/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

38
main.go
View File

@ -86,38 +86,48 @@ func run(ctx context.Context) error {
Credential: xmpp.Password(os.Getenv("XMPP_PASSWORD")),
})
// configure cors middleware
corsMiddleware := cors.New(cors.Options{
AllowCredentials: true,
AllowedMethods: strings.Fields(env("CORS_METHODS", "GET")),
AllowedOrigins: strings.Fields(env("CORS_ORIGIN", "*")),
}).Handler
mux := chi.NewRouter()
mux.Use(
cfg.ApplyHTTP,
secHeaders,
corsMiddleware,
cors.New(cors.Options{
AllowCredentials: true,
AllowedMethods: strings.Fields(env("CORS_METHODS", "GET")),
AllowedOrigins: strings.Fields(env("CORS_ORIGIN", "*")),
}).Handler,
middleware.RequestID,
middleware.RealIP,
middleware.RequestLogger(&middleware.DefaultLogFormatter{Logger: accessLog(log.Info)}),
middleware.Recoverer,
)
if env("DISABLE_KEYPROOF", "false") == "false" {
// Create cache for promise engine
arc, _ := lru.NewARC(4096)
c := cache.New(arc)
keyproofs.NewKeyProofApp(ctx, c).Routes(mux)
}
keyproofApp := keyproofs.NewKeyProofApp(ctx, c)
dnsApp := keyproofs.NewDNSApp(ctx)
vcardApp, err := keyproofs.NewVCardApp(ctx)
if env("DISABLE_DNS", "false") == "false" {
keyproofs.NewDNSApp(ctx).Routes(mux)
}
if env("DISABLE_AVATAR", "false") == "false" {
avatarApp, err := keyproofs.NewAvatarApp(ctx, env("AVATAR_PATH", "pub"))
if err != nil {
return err
}
keyproofApp.Routes(mux)
dnsApp.Routes(mux)
avatarApp.Routes(mux)
}
if env("DISABLE_VCARD", "false") == "false" {
vcardApp, err := keyproofs.NewVCardApp(ctx)
if err != nil {
return err
}
vcardApp.Routes(mux)
}
log.Info().
Str("app", cfg.GetString("app-name")).
@ -127,7 +137,7 @@ func run(ctx context.Context) error {
Str("listen", listen).
Msg("startup")
err = New(&http.Server{
err := New(&http.Server{
Addr: listen,
WriteTimeout: 15 * time.Second,
ReadTimeout: 15 * time.Second,

View File

@ -37,7 +37,6 @@ func getStyle(ctx context.Context, email string) (*Style, error) {
hash := md5.New()
email = strings.TrimSpace(strings.ToLower(email))
_, _ = hash.Write([]byte(email))
id := hash.Sum(nil)
style := &Style{}

View File

@ -50,6 +50,7 @@ var pageTPL = `
.shade { background-color: {{index .Palette 3}}80; border-radius: .25rem;}
.lead { padding:0; margin:0; }
.scroll { height: 20em; overflow: scroll; }
@media only screen and (max-width: 991px) {
.jumbotron h1 { font-size: 2rem; }
.jumbotron .lead { font-size: 1.0rem; }