mirror of
https://github.com/gmemstr/pogo.git
synced 2024-09-20 01:31:09 +01:00
Implemented episode publishing
File uploads working via /admin route, currently working on fixing generate_rss.go function as only one episode is actually added (contents of feed.Items is replaced instead of added to ):).
This commit is contained in:
parent
d48735c6a6
commit
565f0c3948
39
admin.go
39
admin.go
|
@ -1,10 +1,45 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"net/http"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"io/ioutil"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateEpisode() {
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,14 +2,25 @@
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>WR Admin</title>
|
<title>WR Publish</title>
|
||||||
<link rel="stylesheet" href="/assets/styles.css">
|
<link rel="stylesheet" href="/assets/styles.css">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>White Rabbit Admin</h1>
|
<h1>White Rabbit Publish</h1>
|
||||||
|
|
||||||
|
<form enctype="multipart/form-data" action="/admin/publish" method="post">
|
||||||
|
<label for="title">Episode Title</label>
|
||||||
|
<input type="text" id="title" name="title">
|
||||||
|
<label for="description">Episode Description</label>
|
||||||
|
<textarea name="description" id="description" cols="50" rows="10" style="resize: none;"></textarea>
|
||||||
|
<label for="file">Media File</label>
|
||||||
|
<input type="file" id="file" name="file">
|
||||||
|
<label for="date">Publish Date</label>
|
||||||
|
<input type="date" id="date" name="date">
|
||||||
|
<input type="submit" value="Publish">
|
||||||
|
</form>
|
||||||
|
|
||||||
<button id="newcast" class="newcast btn"></button>
|
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>White Rabbit licensed under the GPLv3</p>
|
<p>White Rabbit licensed under the GPLv3</p>
|
||||||
|
|
|
@ -21,7 +21,7 @@ get("/json", function(data){
|
||||||
document.title = json.title;
|
document.title = json.title;
|
||||||
document.getElementById("title").innerHTML = json.title;
|
document.getElementById("title").innerHTML = json.title;
|
||||||
|
|
||||||
for (i=0;i<json.items.length; i++){
|
for (i=0;i<=json.items.length; i++){
|
||||||
var div = document.createElement('div');
|
var div = document.createElement('div');
|
||||||
div.className = 'podcast';
|
div.className = 'podcast';
|
||||||
// Todo: Add audio element (must modify feeds fork first!)
|
// Todo: Add audio element (must modify feeds fork first!)
|
||||||
|
|
|
@ -7,3 +7,7 @@ body {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
padding:5%;
|
padding:5%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
display: block;
|
||||||
|
}
|
|
@ -3,6 +3,6 @@
|
||||||
"Name": "Git Galaxy Stargazers",
|
"Name": "Git Galaxy Stargazers",
|
||||||
"Host": "Gabriel Simmer",
|
"Host": "Gabriel Simmer",
|
||||||
"Email": "gabriel@gitgalaxy.com",
|
"Email": "gabriel@gitgalaxy.com",
|
||||||
"Image": "https://podcast.gitgalaxy.com/assets/podcast_image.png",
|
"Image": "localhost:8000/assets/podcast_image.png",
|
||||||
"PodcastUrl": "https://podcast.gitgalaxy.com"
|
"PodcastUrl": "http://localhost:8000"
|
||||||
}
|
}
|
|
@ -66,6 +66,7 @@ func generate_rss() {
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if strings.Contains(file.Name(), ".mp3") {
|
if strings.Contains(file.Name(), ".mp3") {
|
||||||
|
fmt.Println(file.Name())
|
||||||
s := strings.Split(file.Name(), "_")
|
s := strings.Split(file.Name(), "_")
|
||||||
t := strings.Split(s[1], ".")
|
t := strings.Split(s[1], ".")
|
||||||
title := t[0]
|
title := t[0]
|
||||||
|
@ -97,7 +98,7 @@ func generate_rss() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
fmt.Println(rss)
|
// fmt.Println(rss)
|
||||||
rss_byte := []byte(rss)
|
rss_byte := []byte(rss)
|
||||||
ioutil.WriteFile("feed.rss", rss_byte, 0644)
|
ioutil.WriteFile("feed.rss", rss_byte, 0644)
|
||||||
json_byte := []byte(json)
|
json_byte := []byte(json)
|
||||||
|
|
|
@ -86,5 +86,6 @@ func main() {
|
||||||
r.HandleFunc("/json", JsonHandler)
|
r.HandleFunc("/json", JsonHandler)
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
r.HandleFunc("/admin", BasicAuth(AdminHandler, "g", "password", "Login to White Rabbit admin interface"))
|
r.HandleFunc("/admin", BasicAuth(AdminHandler, "g", "password", "Login to White Rabbit admin interface"))
|
||||||
|
r.HandleFunc("/admin/publish", CreateEpisode)
|
||||||
log.Fatal(http.ListenAndServe(":8000", r))
|
log.Fatal(http.ListenAndServe(":8000", r))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue