refactor: cleanup db helpers, ratelimit and base template padding
This commit is contained in:
@@ -24,14 +24,6 @@ func (r GetUserWatchListRow) DisplayTitle() string {
|
|||||||
return DisplayTitle(r.TitleEnglish, r.TitleJapanese, r.TitleOriginal)
|
return DisplayTitle(r.TitleEnglish, r.TitleJapanese, r.TitleOriginal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoolPtr converts a nullable bool to a pointer; nil if not valid
|
|
||||||
func BoolPtr(b sql.NullBool) *bool {
|
|
||||||
if !b.Valid {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return &b.Bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// BeginTx starts a transaction and returns the Queries wrapper bound to it
|
// BeginTx starts a transaction and returns the Queries wrapper bound to it
|
||||||
func BeginTx(ctx context.Context, db *sql.DB) (*Queries, *sql.Tx, error) {
|
func BeginTx(ctx context.Context, db *sql.DB) (*Queries, *sql.Tx, error) {
|
||||||
if db == nil {
|
if db == nil {
|
||||||
|
|||||||
@@ -61,17 +61,6 @@ func getIP(r *http.Request) string {
|
|||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
|
|
||||||
// Middleware returns 429 for rate-limited API requests
|
|
||||||
func (l *Limiter) Middleware(next http.Handler) http.Handler {
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if !l.allow(getIP(r)) {
|
|
||||||
http.Error(w, "Too many requests. Please try again later.", http.StatusTooManyRequests)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// AuthMiddleware redirects rate-limited form submissions back to the page
|
// AuthMiddleware redirects rate-limited form submissions back to the page
|
||||||
// returns 429 for non-path requests (e.g. API calls)
|
// returns 429 for non-path requests (e.g. API calls)
|
||||||
func (l *Limiter) AuthMiddleware(next http.Handler) http.Handler {
|
func (l *Limiter) AuthMiddleware(next http.Handler) http.Handler {
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ if (window.showToast) showToast({ message: 'Something went wrong' })
|
|||||||
<div class="sticky top-0 z-40 w-full">
|
<div class="sticky top-0 z-40 w-full">
|
||||||
{{template "header" .}}
|
{{template "header" .}}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 p-4 md:p-8 lg:p-12">
|
<div class="flex-1 p-4 md:p-8 lg:p-10">
|
||||||
{{template "content" .}}
|
{{template "content" .}}
|
||||||
</div>
|
</div>
|
||||||
{{template "footer" .}}
|
{{template "footer" .}}
|
||||||
|
|||||||
Reference in New Issue
Block a user