AlpenQueue/cmd/alpenqueue/main.go
Soldier 405f9ca173 Add flexible CSS selector extraction
Replace hardcoded title extraction with user-defined CSS selectors using goquery. Users specify selector in job JSON to extract any HTML elements. Worker extracts text content plus src/href attributes. Webhook payload includes extracted content and URL.
2025-11-16 08:33:19 +00:00

54 lines
1.1 KiB
Go

package main
import (
"alpenqueue/pkg/db"
"alpenqueue/pkg/worker"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
func main() {
database, err := db.Init("./alpenqueue.db")
if err != nil {
log.Fatal(err)
}
defer database.Close()
worker.Start(database)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("AlpenQueue running!"))
})
http.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
var req struct {
WebhookURL string `json:"webhook_url"`
URL string `json:"url"`
Selector string `json:"selector"`
}
body, _ := io.ReadAll(r.Body)
json.Unmarshal(body, &req)
id, err := db.CreateJob(database, req.WebhookURL, req.URL, req.Selector)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
fmt.Fprintf(w, "Job %d created\n", id)
})
log.Println("Server starting on :8080")
http.ListenAndServe(":8080", nil)
}