added download page

pull/24/head
Akhil Gupta 4 years ago
parent a56f4d3548
commit e0a016071c

@ -151,7 +151,7 @@
</div> </div>
<div class="columns one"> <div class="columns one">
{{ len .PodcastItems }} episodes <a href="/podcasts/{{ .ID }}/view"> {{ len .PodcastItems }} episodes</a>
</div> </div>
</div> </div>

@ -0,0 +1,157 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" integrity="sha512-EZLkOqwILORob+p0BXZc+Vm3RgJBOe1Iq/0fiI7r/wJgzOFZMlsqTa29UEl6v6U6gsV4uIpsNZoV32YZqrCRCQ==" crossorigin="anonymous" />
<title>PodGrab</title>
<style>
.container {
max-width: 800px; }
.header {
margin-top: 6rem;
text-align: center; }
.value-prop {
margin-top: 1rem; }
.value-props {
margin-top: 4rem;
margin-bottom: 4rem; }
.docs-header {
text-transform: uppercase;
font-size: 1.4rem;
letter-spacing: .2rem;
font-weight: 600; }
.docs-section {
border-top: 1px solid #eee;
padding: 4rem 0;
margin-bottom: 0;}
.value-img {
display: block;
text-align: center;
margin: 2.5rem auto 0; }
.example-grid .column,
.example-grid .columns {
background: #EEE;
text-align: center;
border-radius: 4px;
font-size: 1rem;
text-transform: uppercase;
height: 30px;
line-height: 30px;
margin-bottom: .75rem;
font-weight: 600;
letter-spacing: .1rem; }
.docs-example .row,
.docs-example.row,
.docs-example form {
margin-bottom: 0; }
.docs-example h1,
.docs-example h2,
.docs-example h3,
.docs-example h4,
.docs-example h5,
.docs-example h6 {
margin-bottom: 1rem; }
.heading-font-size {
font-size: 1.2rem;
color: #999;
letter-spacing: normal; }
.code-example {
margin-top: 1.5rem;
margin-bottom: 0; }
.code-example-body {
white-space: pre;
word-wrap: break-word }
.example {
position: relative;
margin-top: 4rem; }
.example-header {
font-weight: 600;
margin-top: 1.5rem;
margin-bottom: .5rem; }
.example-description {
margin-bottom: 1.5rem; }
.example-screenshot-wrapper {
display: block;
position: relative;
overflow: hidden;
border-radius: 6px;
border: 1px solid #eee;
height: 250px; }
.example-screenshot {
width: 100%;
height: auto; }
.example-screenshot.coming-soon {
width: auto;
position: absolute;
background: #eee;
top: 5px;
right: 5px;
bottom: 5px;
left: 5px; }
.navbar {
display: none; }
/* Larger than phone */
@media (min-width: 550px) {
.header {
margin-top: 8rem;
}
.value-props {
margin-top: 9rem;
margin-bottom: 7rem; }
.value-img {
margin-bottom: 1rem; }
.example-grid .column,
.example-grid .columns {
margin-bottom: 1.5rem; }
.docs-section {
padding: 6rem 0; }
.example-send-yourself-copy {
float: right;
margin-top: 12px; }
.example-screenshot-wrapper {
position: absolute;
width: 48%;
height: 100%;
left: 0;
max-height: none; }
}
/* Larger than tablet */
@media (min-width: 750px) {
}
</style>
</head>
<body>
<div class="container">
<section class="header">
<h1>{{ .title }}</h1>
</section>
<br>
{{range .podcast.PodcastItems}}
<div class="podcasts row">
<div class="columns three">
<img class="u-full-width" src="{{ .Image }}" alt="{{ .Title }}">
</div>
<div class="columns nine">
<h4>{{.Title}}</h4>
<small>{{ formatDate .PubDate }}</small>
<p>{{ .Summary }}</p>
<a class="button button-primary" href="/{{ .DownloadPath }}" download>Download</a>
</div>
<div class="columns one">
</div>
</div>
<hr>
{{end}}
</div>
</body>
</html>

@ -36,7 +36,8 @@ type PodcastItem struct {
FileURL string FileURL string
GUID string GUID string
Image string
DownloadDate time.Time DownloadDate time.Time
DownloadPath string DownloadPath string

@ -2,10 +2,12 @@ package main
import ( import (
"fmt" "fmt"
"html/template"
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"time"
"github.com/akhilrex/podgrab/controllers" "github.com/akhilrex/podgrab/controllers"
"github.com/akhilrex/podgrab/db" "github.com/akhilrex/podgrab/db"
@ -23,14 +25,22 @@ func main() {
db.DB, err = db.Init() db.DB, err = db.Init()
if err != nil { if err != nil {
fmt.Println("statuse: ", err) fmt.Println("statuse: ", err)
}else{ } else {
db.Migrate() db.Migrate()
} }
r := gin.Default() r := gin.Default()
dataPath := os.Getenv("DATA") dataPath := os.Getenv("DATA")
//r.Static("/assets", "./assets") //r.Static("/assets", "./assets")
r.Static("/assets", dataPath) r.Static("/assets", dataPath)
r.LoadHTMLGlob("client/*") funcMap := template.FuncMap{
"formatDate": func(raw time.Time) string {
return raw.Format("Jan 2 2006")
},
}
tmpl := template.Must(template.New("main").Funcs(funcMap).ParseGlob("client/*"))
//r.LoadHTMLGlob("client/*")
r.SetHTMLTemplate(tmpl)
r.GET("/podcasts", controllers.AddPodcast) r.GET("/podcasts", controllers.AddPodcast)
r.POST("/podcasts", controllers.GetAllPodcasts) r.POST("/podcasts", controllers.GetAllPodcasts)
@ -45,6 +55,22 @@ func main() {
podcasts := service.GetAllPodcasts() podcasts := service.GetAllPodcasts()
c.HTML(http.StatusOK, "index.html", gin.H{"title": "Podgrab", "podcasts": podcasts}) c.HTML(http.StatusOK, "index.html", gin.H{"title": "Podgrab", "podcasts": podcasts})
}) })
r.GET("/podcasts/:id/view", func(c *gin.Context) {
var searchByIdQuery controllers.SearchByIdQuery
if c.ShouldBindUri(&searchByIdQuery) == nil {
var podcast db.Podcast
if err := db.GetPodcastById(searchByIdQuery.Id, &podcast); err == nil {
c.HTML(http.StatusOK, "podcast.html", gin.H{"title": podcast.Title, "podcast": podcast})
} else {
c.JSON(http.StatusBadRequest, err)
}
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
})
r.POST( r.POST(
"/", func(c *gin.Context) { "/", func(c *gin.Context) {
var addPodcastData controllers.AddPodcastData var addPodcastData controllers.AddPodcastData

@ -80,6 +80,7 @@ func AddPodcastItems(podcast *db.Podcast) error {
PubDate: pubDate, PubDate: pubDate,
FileURL: obj.Enclosure.URL, FileURL: obj.Enclosure.URL,
GUID: obj.Guid.Text, GUID: obj.Guid.Text,
Image: obj.Image.Href,
} }
db.CreatePodcastItem(&podcastItem) db.CreatePodcastItem(&podcastItem)
} }

Loading…
Cancel
Save