mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-14 02:10:04 +00:00
opml file import/export handlers
This commit is contained in:
@@ -8,11 +8,13 @@ import (
|
||||
"os"
|
||||
"log"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"strings"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"math"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
@@ -348,3 +350,29 @@ func SettingsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func OPMLImportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "POST" {
|
||||
file, _, err := req.FormFile("opml")
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
content, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return
|
||||
}
|
||||
fmt.Println(string(content))
|
||||
} else {
|
||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func OPMLExportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "GET" {
|
||||
rw.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||
rw.Header().Set("Content-Disposition", `attachment; filename="subscriptions.opml"`)
|
||||
rw.Write([]byte("content"))
|
||||
}
|
||||
}
|
||||
|
@@ -79,6 +79,8 @@ var routes []Route = []Route{
|
||||
p("/api/items", ItemListHandler),
|
||||
p("/api/items/:id", ItemHandler),
|
||||
p("/api/settings", SettingsHandler),
|
||||
p("/opml/import", OPMLImportHandler),
|
||||
p("/opml/export", OPMLExportHandler),
|
||||
}
|
||||
|
||||
func Vars(req *http.Request) map[string]string {
|
||||
|
Reference in New Issue
Block a user