This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
e621-sdk-go/internal/api/user.go

40 lines
1.1 KiB
Go
Raw Normal View History

2023-05-24 14:05:27 +00:00
package api
import (
"context"
"fmt"
"git.dragse.it/anthrove/e621-to-graph/internal/e621"
"git.dragse.it/anthrove/e621-to-graph/internal/service"
"git.dragse.it/anthrove/e621-to-graph/pkg/logic"
log "github.com/sirupsen/logrus"
2023-05-24 14:05:27 +00:00
"net/http"
)
// ScapeUserFavourites is the handler for the user API
func ScapeUserFavourites(ctx context.Context, graphConnection logic.GraphConnection, e621Client *e621.Client) func(response http.ResponseWriter, request *http.Request) {
2023-05-24 14:05:27 +00:00
return func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(w, "only POST requests are allowed")
2023-05-24 14:05:27 +00:00
return
}
username := r.FormValue("username")
if username == "" {
w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "username is required")
2023-05-24 14:05:27 +00:00
return
}
// Perform further processing with the username
go service.ScrapeUser(ctx, graphConnection, *e621Client, username)
2023-05-24 14:05:27 +00:00
// Send a response
w.WriteHeader(http.StatusOK)
log.WithFields(log.Fields{
"requested_user": username,
}).Info("api: processing user")
2023-05-24 14:05:27 +00:00
}
}