added discord api limiting
This commit is contained in:
@@ -4,14 +4,15 @@ import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/handlers"
|
||||
"git.haelnorr.com/h/oslstats/internal/session"
|
||||
|
||||
"git.haelnorr.com/h/golib/hlog"
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/uptrace/bun"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/discord"
|
||||
"git.haelnorr.com/h/oslstats/internal/handlers"
|
||||
"git.haelnorr.com/h/oslstats/internal/store"
|
||||
)
|
||||
|
||||
func setupHttpServer(
|
||||
@@ -19,7 +20,8 @@ func setupHttpServer(
|
||||
config *config.Config,
|
||||
logger *hlog.Logger,
|
||||
bun *bun.DB,
|
||||
store *session.Store,
|
||||
store *store.Store,
|
||||
discordAPI *discord.APIClient,
|
||||
) (server *hws.Server, err error) {
|
||||
if staticFS == nil {
|
||||
return nil, errors.New("No filesystem provided")
|
||||
@@ -55,7 +57,7 @@ func setupHttpServer(
|
||||
return nil, errors.Wrap(err, "httpServer.LoggerIgnorePaths")
|
||||
}
|
||||
|
||||
err = addRoutes(httpServer, &fs, config, bun, auth, store)
|
||||
err = addRoutes(httpServer, &fs, config, bun, auth, store, discordAPI)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "addRoutes")
|
||||
}
|
||||
|
||||
@@ -5,13 +5,14 @@ import (
|
||||
|
||||
"git.haelnorr.com/h/golib/hws"
|
||||
"git.haelnorr.com/h/golib/hwsauth"
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/db"
|
||||
"git.haelnorr.com/h/oslstats/internal/handlers"
|
||||
"git.haelnorr.com/h/oslstats/internal/session"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/uptrace/bun"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/db"
|
||||
"git.haelnorr.com/h/oslstats/internal/discord"
|
||||
"git.haelnorr.com/h/oslstats/internal/handlers"
|
||||
"git.haelnorr.com/h/oslstats/internal/store"
|
||||
)
|
||||
|
||||
func addRoutes(
|
||||
@@ -20,7 +21,8 @@ func addRoutes(
|
||||
cfg *config.Config,
|
||||
conn *bun.DB,
|
||||
auth *hwsauth.Authenticator[*db.User, bun.Tx],
|
||||
store *session.Store,
|
||||
store *store.Store,
|
||||
discordAPI *discord.APIClient,
|
||||
) error {
|
||||
// Create the routes
|
||||
routes := []hws.Route{
|
||||
@@ -37,12 +39,12 @@ func addRoutes(
|
||||
{
|
||||
Path: "/login",
|
||||
Method: hws.MethodGET,
|
||||
Handler: auth.LogoutReq(handlers.Login(server, cfg)),
|
||||
Handler: auth.LogoutReq(handlers.Login(server, cfg, store, discordAPI)),
|
||||
},
|
||||
{
|
||||
Path: "/auth/callback",
|
||||
Method: hws.MethodGET,
|
||||
Handler: auth.LogoutReq(handlers.Callback(server, conn, cfg, store)),
|
||||
Handler: auth.LogoutReq(handlers.Callback(server, conn, cfg, store, discordAPI)),
|
||||
},
|
||||
{
|
||||
Path: "/register",
|
||||
|
||||
@@ -9,10 +9,12 @@ import (
|
||||
"time"
|
||||
|
||||
"git.haelnorr.com/h/golib/hlog"
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/session"
|
||||
"git.haelnorr.com/h/oslstats/pkg/embedfs"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/config"
|
||||
"git.haelnorr.com/h/oslstats/internal/discord"
|
||||
"git.haelnorr.com/h/oslstats/internal/store"
|
||||
"git.haelnorr.com/h/oslstats/pkg/embedfs"
|
||||
)
|
||||
|
||||
// Initializes and runs the server
|
||||
@@ -44,10 +46,14 @@ func run(ctx context.Context, w io.Writer, config *config.Config) error {
|
||||
|
||||
// Setup session store
|
||||
logger.Debug().Msg("Setting up session store")
|
||||
store := session.NewStore()
|
||||
store := store.NewStore()
|
||||
|
||||
// Setup Discord API client
|
||||
logger.Debug().Msg("Setting up Discord API client")
|
||||
discordAPI := discord.NewRateLimitedClient(logger)
|
||||
|
||||
logger.Debug().Msg("Setting up HTTP server")
|
||||
httpServer, err := setupHttpServer(&staticFS, config, logger, bun, store)
|
||||
httpServer, err := setupHttpServer(&staticFS, config, logger, bun, store, discordAPI)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "setupHttpServer")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user