diff --git a/main.go b/main.go index 974aa9a..cad3d7e 100644 --- a/main.go +++ b/main.go @@ -12,8 +12,8 @@ import ( func main() { r := mux.NewRouter() - // Handle the calendar.ics route - r.HandleFunc("/3irc.ics", generateICSHandler).Methods("GET") + // Handle the calendar.ics route with default filename "calendar.ics" + r.HandleFunc("/3irc.ics", generate3IRCHandler).Methods("GET") // Serve static files r.PathPrefix("/").Handler(http.FileServer(http.Dir("static/"))) @@ -22,7 +22,8 @@ func main() { log.Fatal(http.ListenAndServe(":8080", r)) } -func generateICSHandler(w http.ResponseWriter, r *http.Request) { +// generateICSHandler generates the ICS file and sends it in the response with a given filename +func generateICSHandler(w http.ResponseWriter, _ *http.Request, filename string) { // Set start and end times (these could be retrieved from request parameters if needed) start := "1725228000000" // Example start timestamp end := "1728684000000" // Example end timestamp @@ -48,7 +49,16 @@ func generateICSHandler(w http.ResponseWriter, r *http.Request) { // Step 3: Generate the iCal file icsContent := ical.GenerateICS(events) - // Step 4: Write the iCal file to the response + // Step 4: Set headers for the iCal file response with the provided filename w.Header().Set("Content-Type", "text/calendar") + w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"") + + // Step 5: Write the iCal content to the response w.Write([]byte(icsContent)) } + +// generate3IRCHandler is a wrapper around generateICSHandler that uses a specific filename +func generate3IRCHandler(w http.ResponseWriter, r *http.Request) { + // Call generateICSHandler with the specific filename + generateICSHandler(w, r, "3irc_calendar.ics") +} diff --git a/static/Frame 64.png b/static/banner.png similarity index 100% rename from static/Frame 64.png rename to static/banner.png diff --git a/static/index.html b/static/index.html index 30f5f11..3814755 100644 --- a/static/index.html +++ b/static/index.html @@ -5,6 +5,18 @@ CPE Calendar + + + + + + + + + + + +