Export OPML

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

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

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

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

@ -202,7 +202,8 @@ func GetOmpl(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"message": "Invalid request"}) c.JSON(http.StatusBadRequest, gin.H{"message": "Invalid request"})
return 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) { func UploadOpml(c *gin.Context) {
file, _, err := c.Request.FormFile("file") file, _, err := c.Request.FormFile("file")

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

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

Loading…
Cancel
Save