From 4486d5020cf364532d68fa4dffc020792867971f Mon Sep 17 00:00:00 2001 From: perennial Date: Fri, 18 Oct 2024 13:47:27 +1100 Subject: [PATCH] clean up inline comments --- core/artwork.go | 9 ++++----- server/middleware/logger.go | 6 +----- server/middleware/set_redirect_header.go | 3 --- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/core/artwork.go b/core/artwork.go index 39d8017..9266ab8 100644 --- a/core/artwork.go +++ b/core/artwork.go @@ -276,11 +276,10 @@ func GetRelatedArtworks(r *http.Request, id string) ([]ArtworkBrief, error) { // GetArtworkByID retrieves information about a specific artwork, with the option to include additional related data. // External API calls are made to gather metadata, images, related works, user info, and comments. -// Some information is fetched in parallel to improve performance. func GetArtworkByID(r *http.Request, id string, full bool) (*Illust, error) { token := session.GetUserToken(r) - // Fetch the core artwork metadata from Pixiv. + // Core artwork metadata fetched from Pixiv. var illust struct { Illust UserIllusts map[int]any `json:"userIllusts"` // Allows fetching user's other artworks. @@ -353,7 +352,7 @@ func GetArtworkByID(r *http.Request, id string, full bool) (*Illust, error) { illustAuxilary.Images = images }() - // If full details are requested, fetch related artworks (helpful when exploring more work by the artist or related themes). + // If full details are requested, fetch related artworks. if full { wg.Add(1) go func() { @@ -400,7 +399,7 @@ func GetArtworkByID(r *http.Request, id string, full bool) (*Illust, error) { illust.Tags = tagsList }() - // User's recent works are only fetched when full details are requested, for users exploring multiple artworks by the same creator. + // If full details are requested, fetch the user's recent works. if full { wg.Add(1) go func() { @@ -435,7 +434,7 @@ func GetArtworkByID(r *http.Request, id string, full bool) (*Illust, error) { }() } - // We only fetch comments if 'full' details are requested and comments are enabled (since disabled comments would lead to unnecessary API calls). + // We only fetch comments if full details are requested and comments are enabled (since disabled comments would lead to unnecessary API calls). // This condition is evaluated *after* fetching basic artwork information since we first need the comment-off flag. if full && illust.CommentDisabled != 1 { wg.Add(1) diff --git a/server/middleware/logger.go b/server/middleware/logger.go index 5193ac8..9af87f2 100644 --- a/server/middleware/logger.go +++ b/server/middleware/logger.go @@ -25,7 +25,7 @@ func (w *ResponseWriterInterceptStatus) WriteHeader(code int) { // CanRequestSkipLogger determines if a request should bypass the logging middleware. // This is useful for reducing log clutter from static assets and development-specific routes. func CanRequestSkipLogger(r *http.Request) bool { - // Uncomment the following line to log all requests + // NOTE: Uncomment the following line to log all requests // return false path := r.URL.Path return strings.HasPrefix(path, "/img/") || @@ -52,16 +52,12 @@ func LogRequest(h http.Handler) http.Handler { // TODO: Set user context here if needed - // Record the start time of the request start_time := time.Now() - // Call the next handler in the chain h.ServeHTTP(w, r) - // Record the end time of the request end_time := time.Now() - // Log the request details using the audit package audit.LogServerRoundTrip(audit.ServerRequestSpan{ StartTime: start_time, EndTime: end_time, diff --git a/server/middleware/set_redirect_header.go b/server/middleware/set_redirect_header.go index cd4e2a6..52989a2 100644 --- a/server/middleware/set_redirect_header.go +++ b/server/middleware/set_redirect_header.go @@ -8,15 +8,12 @@ import ( // HTTP header when a request contains the "redirected=1" query parameter. func SetRedirectHeader(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - // Check if the request contains the "redirected" query parameter redirected := r.URL.Query().Get("redirected") if redirected == "1" { - // If redirected, set headers on the request r.Header.Set("X-Handled-Redirected", "true") } - // Call the next handler h.ServeHTTP(w, r) }) }