2017-07-25 15:39:49 +01:00
|
|
|
/* admin.go
|
|
|
|
*
|
|
|
|
* Here is where all the neccesary functions for managing episodes
|
|
|
|
* live, e.g adding removing etc.
|
|
|
|
*/
|
|
|
|
|
2017-07-15 16:06:37 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-16 18:43:47 +01:00
|
|
|
"net/http"
|
2017-07-15 16:06:37 +01:00
|
|
|
"fmt"
|
2017-07-16 18:43:47 +01:00
|
|
|
"strings"
|
|
|
|
"io/ioutil"
|
|
|
|
"io"
|
|
|
|
"os"
|
2017-07-15 16:06:37 +01:00
|
|
|
)
|
|
|
|
|
2017-09-03 17:53:17 +01:00
|
|
|
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 {
|
2017-09-07 04:02:14 +01:00
|
|
|
css,err := ioutil.ReadFile("./assets/static/custom.css")
|
|
|
|
if err != nil {
|
|
|
|
panic (err)
|
|
|
|
} else {
|
|
|
|
w.Write(css)
|
|
|
|
}
|
2017-09-03 17:53:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-16 18:43:47 +01:00
|
|
|
func CreateEpisode(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.Method == "POST" {
|
|
|
|
r.ParseMultipartForm(32 << 20)
|
2017-09-07 04:02:14 +01:00
|
|
|
|
|
|
|
// Build filename for episode
|
2017-07-16 18:43:47 +01:00
|
|
|
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)
|
2017-09-07 04:02:14 +01:00
|
|
|
// Finish building filenames
|
2017-07-16 18:43:47 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2017-07-25 15:39:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func RemoveEpisode(episode string) {
|
|
|
|
// Episode should be the full MP3 filename
|
|
|
|
// Remove MP3 first
|
|
|
|
os.Remove(episode)
|
2017-07-25 16:01:02 +01:00
|
|
|
sn := strings.Replace(episode, ".mp3", "_SHOWNOTES.md", 2)
|
2017-07-25 15:39:49 +01:00
|
|
|
os.Remove(sn)
|
2017-07-15 16:06:37 +01:00
|
|
|
}
|