clean up inline comments

This commit is contained in:
perennial
2024-10-18 13:47:27 +11:00
parent 8bf28ece2b
commit 4486d5020c
3 changed files with 5 additions and 13 deletions
+4 -5
View File
@@ -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)
+1 -5
View File
@@ -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,
-3
View File
@@ -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)
})
}