2017-11-20 06:10:04 +01:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2017-11-20 23:35:11 +01:00
|
|
|
|
|
|
|
"github.com/miniflux/miniflux2/server/core"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Controller) Export(ctx *core.Context, request *core.Request, response *core.Response) {
|
|
|
|
user := ctx.GetLoggedUser()
|
|
|
|
opml, err := c.opmlHandler.Export(user.ID)
|
|
|
|
if err != nil {
|
|
|
|
response.Html().ServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
response.Xml().Download("feeds.opml", opml)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Controller) Import(ctx *core.Context, request *core.Request, response *core.Response) {
|
|
|
|
args, err := c.getCommonTemplateArgs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
response.Html().ServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
response.Html().Render("import", args.Merge(tplParams{
|
|
|
|
"menu": "feeds",
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Controller) UploadOPML(ctx *core.Context, request *core.Request, response *core.Response) {
|
2017-11-22 03:14:45 +01:00
|
|
|
file, fileHeader, err := request.File("file")
|
2017-11-20 06:10:04 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
response.Redirect(ctx.GetRoute("import"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
user := ctx.GetLoggedUser()
|
|
|
|
log.Printf("[UI:UploadOPML] User #%d uploaded this file: %s (%d bytes)\n", user.ID, fileHeader.Filename, fileHeader.Size)
|
|
|
|
|
|
|
|
if impErr := c.opmlHandler.Import(user.ID, file); impErr != nil {
|
|
|
|
args, err := c.getCommonTemplateArgs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
response.Html().ServerError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
response.Html().Render("import", args.Merge(tplParams{
|
2017-11-20 23:35:11 +01:00
|
|
|
"errorMessage": impErr,
|
2017-11-20 06:10:04 +01:00
|
|
|
"menu": "feeds",
|
|
|
|
}))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
response.Redirect(ctx.GetRoute("feeds"))
|
|
|
|
}
|