mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
973ad0e72e
Admins can now set custom CSS in the admin interface - next up is to add classes to all elements for easier theming.
82 lines
1.8 KiB
Go
82 lines
1.8 KiB
Go
/* admin.go
|
|
*
|
|
* Here is where all the neccesary functions for managing episodes
|
|
* live, e.g adding removing etc.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"net/http"
|
|
"fmt"
|
|
"strings"
|
|
"io/ioutil"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func CustomCss(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "POST" {
|
|
r.ParseMultipartForm(32 << 20)
|
|
css := strings.Join(r.Form["css"], "")
|
|
|
|
filename := "custom.css"
|
|
|
|
err := ioutil.WriteFile("./assets/static/" + filename, []byte(css), 0644)
|
|
if err != nil {
|
|
panic(err)
|
|
} else {
|
|
w.Write([]byte("success"))
|
|
}
|
|
} else {
|
|
css,err := ioutil.ReadFile("./assets/static/custom.css")
|
|
if err != nil {
|
|
panic (err)
|
|
} else {
|
|
w.Write(css)
|
|
}
|
|
}
|
|
}
|
|
|
|
func CreateEpisode(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "POST" {
|
|
r.ParseMultipartForm(32 << 20)
|
|
date := strings.Join(r.Form["date"], "")
|
|
title := strings.Join(r.Form["title"], "")
|
|
|
|
name := fmt.Sprintf("%v_%v", date, title)
|
|
filename := name + ".mp3"
|
|
shownotes := name + "_SHOWNOTES.md"
|
|
fmt.Println(name)
|
|
description := strings.Join(r.Form["description"], "")
|
|
fmt.Println(description)
|
|
|
|
err := ioutil.WriteFile("./podcasts/" + shownotes, []byte(description), 0644)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
file, handler, err := r.FormFile("file")
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
defer file.Close()
|
|
fmt.Fprintf(w, "%v", handler.Header)
|
|
f, err := os.OpenFile("./podcasts/"+filename, os.O_WRONLY|os.O_CREATE, 0666)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
defer f.Close()
|
|
io.Copy(f, file)
|
|
}
|
|
}
|
|
|
|
func RemoveEpisode(episode string) {
|
|
// Episode should be the full MP3 filename
|
|
// Remove MP3 first
|
|
os.Remove(episode)
|
|
sn := strings.Replace(episode, ".mp3", "_SHOWNOTES.md", 2)
|
|
os.Remove(sn)
|
|
} |