Export OPML

pull/34/head
Akhil Gupta 4 years ago
parent 76a8ba90db
commit 319b34831a

@ -151,4 +151,11 @@
@media (min-width: 750px) {
}
</style>
<script>
function onImageError(image) {
image.onerror = "";
image.src = "/webassets/blank.png";
return true;
}
</script>
{{end}}

@ -5,11 +5,6 @@
<script>
Vue.use(Toasted);
function onImageError(image) {
image.onerror = "";
image.src = "/webassets/blank.png";
return true;
}
const limit = 300;
let elements = document.getElementsByClassName("useMore");

@ -33,9 +33,12 @@
{{template "navbar" .}}
<br>
<div class="row">
<div class="columns twelve">
<div class="columns two">
<a href="/backups" class="button">Backups</a>
</div>
<div class="columns two">
<a href="/opml" class="button">Export OPML</a>
</div>
</div>
<hr>
<div class="row" id="app">

@ -202,7 +202,8 @@ func GetOmpl(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"message": "Invalid request"})
return
}
c.XML(200, data)
c.Header("Content-Disposition", "attachment; filename=podgrab-export.opml")
c.Data(200, "text/xml", data)
}
func UploadOpml(c *gin.Context) {
file, _, err := c.Request.FormFile("file")

@ -1,6 +1,9 @@
package model
import "encoding/xml"
import (
"encoding/xml"
"time"
)
type OpmlModel struct {
XMLName xml.Name `xml:"opml"`
@ -13,6 +16,7 @@ type OpmlModel struct {
type OpmlHead struct {
Text string `xml:",chardata"`
Title string `xml:"title"`
DateCreated time.Time `xml:"dateCreated"`
}
type OpmlBody struct {
@ -21,10 +25,10 @@ type OpmlBody struct {
}
type OpmlOutline struct {
Title string `xml:"title,attr"`
XmlUrl string `xml:"xmlUrl,attr"`
Text string `xml:",chardata"`
AttrText string `xml:"text,attr"`
Title string `xml:"title,attr"`
Type string `xml:"type,attr"`
XmlUrl string `xml:"xmlUrl,attr"`
Outline []OpmlOutline `xml:"outline"`
}

@ -98,14 +98,15 @@ func AddOpml(content string) error {
}
func ExportOmpl() (model.OpmlModel, error) {
func ExportOmpl() ([]byte, error) {
podcasts := GetAllPodcasts("")
var outlines []model.OpmlOutline
for _, podcast := range *podcasts {
toAdd := model.OpmlOutline{
AttrText: podcast.Title,
AttrText: podcast.Summary,
Type: "rss",
XmlUrl: podcast.URL,
Title: podcast.Title,
}
outlines = append(outlines, toAdd)
}
@ -113,17 +114,21 @@ func ExportOmpl() (model.OpmlModel, error) {
toExport := model.OpmlModel{
Head: model.OpmlHead{
Title: "Podgrab Feed Export",
DateCreated: time.Now(),
},
Body: model.OpmlBody{
Outline: outlines,
},
Version: "1.0",
Version: "2.0",
}
data, err := xml.Marshal(toExport)
//return string(data), err
fmt.Println(string(data))
return toExport, err
if data, err := xml.MarshalIndent(toExport, "", " "); err == nil {
// fmt.Println(xml.Header + string(data))
data = []byte(xml.Header + string(data))
return data, err
} else {
return nil, err
}
}
func AddPodcast(url string) (db.Podcast, error) {
var podcast db.Podcast

Loading…
Cancel
Save