SoXX
60b3502ee3
As mentioned in #17, I implemented the new SDK. I removed the scheduler and executor code since they were no longer needed. Reviewed-on: anthrove/e621-to-graph#18 Reviewed-by: Lennard Brinkhaus <lennard.brinkhaus@noreply.localhost> Reviewed-by: daskadse <daskadse@noreply.localhost> Co-authored-by: SoXX <soxx@fenpa.ws> Co-committed-by: SoXX <soxx@fenpa.ws>
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621"
|
|
"git.dragse.it/anthrove/e621-to-graph/internal/service"
|
|
"git.dragse.it/anthrove/e621-to-graph/pkg/logic"
|
|
log "github.com/sirupsen/logrus"
|
|
"net/http"
|
|
)
|
|
|
|
// ScapeUserFavourites is the handler for the user API
|
|
func ScapeUserFavourites(ctx context.Context, graphConnection logic.GraphConnection, client *e621.Client) func(response http.ResponseWriter, request *http.Request) {
|
|
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")
|
|
return
|
|
}
|
|
|
|
username := r.FormValue("username")
|
|
if username == "" {
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
fmt.Fprintf(w, "username is required")
|
|
return
|
|
}
|
|
|
|
// Perform further processing with the username
|
|
go service.ScrapeUser(ctx, graphConnection, client, username)
|
|
|
|
// Send a response
|
|
w.WriteHeader(http.StatusOK)
|
|
log.WithFields(log.Fields{
|
|
"requested_user": username,
|
|
}).Info("api: processing user")
|
|
|
|
}
|
|
}
|