Skip to content

Commit

Permalink
Implemented episode publishing
Browse files Browse the repository at this point in the history
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 ):).
  • Loading branch information
gmemstr committed Jul 16, 2017
1 parent d48735c commit 565f0c3
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
41 changes: 38 additions & 3 deletions admin.go
@@ -1,10 +1,45 @@
package main

import (
"io/ioutil"
"net/http"
"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)
}
}
17 changes: 14 additions & 3 deletions assets/admin.html
Expand Up @@ -2,14 +2,25 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WR Admin</title>
<title>WR Publish</title>
<link rel="stylesheet" href="/assets/styles.css">

</head>
<body>
<h1>White Rabbit Admin</h1>
<h1>White Rabbit Publish</h1>

<button id="newcast" class="newcast btn"></button>
<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>


<footer>
<p>White Rabbit licensed under the GPLv3</p>
Expand Down
2 changes: 1 addition & 1 deletion assets/index.html
Expand Up @@ -21,7 +21,7 @@ <h1 id="title" class="title">Loading</h1>
document.title = 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');
div.className = 'podcast';
// Todo: Add audio element (must modify feeds fork first!)
Expand Down
4 changes: 4 additions & 0 deletions assets/static/styles.css
Expand Up @@ -7,3 +7,7 @@ body {
background-color: white;
padding:5%;
}

label {
display: block;
}
4 changes: 2 additions & 2 deletions config.json
Expand Up @@ -3,6 +3,6 @@
"Name": "Git Galaxy Stargazers",
"Host": "Gabriel Simmer",
"Email": "gabriel@gitgalaxy.com",
"Image": "https://podcast.gitgalaxy.com/assets/podcast_image.png",
"PodcastUrl": "https://podcast.gitgalaxy.com"
"Image": "localhost:8000/assets/podcast_image.png",
"PodcastUrl": "http://localhost:8000"
}
3 changes: 2 additions & 1 deletion generate_rss.go
Expand Up @@ -66,6 +66,7 @@ func generate_rss() {

for _, file := range files {
if strings.Contains(file.Name(), ".mp3") {
fmt.Println(file.Name())
s := strings.Split(file.Name(), "_")
t := strings.Split(s[1], ".")
title := t[0]
Expand Down Expand Up @@ -97,7 +98,7 @@ func generate_rss() {
if err != nil {
log.Fatal(err)
}
fmt.Println(rss)
// fmt.Println(rss)
rss_byte := []byte(rss)
ioutil.WriteFile("feed.rss", rss_byte, 0644)
json_byte := []byte(json)
Expand Down
1 change: 1 addition & 0 deletions webserver.go
Expand Up @@ -86,5 +86,6 @@ func main() {
r.HandleFunc("/json", JsonHandler)
http.Handle("/", r)
r.HandleFunc("/admin", BasicAuth(AdminHandler, "g", "password", "Login to White Rabbit admin interface"))
r.HandleFunc("/admin/publish", CreateEpisode)
log.Fatal(http.ListenAndServe(":8000", r))
}

0 comments on commit 565f0c3

Please sign in to comment.