1
0
Fork 0
miniflux/server/ui/controller/opml.go

68 lines
1.7 KiB
Go
Raw Normal View History

2017-11-20 00:10:04 -05: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 17:35:11 -05:00
"github.com/miniflux/miniflux2/server/core"
2017-11-20 00:10:04 -05:00
)
2017-11-28 00:30:04 -05:00
// Export generates the OPML file.
2017-11-20 00:10:04 -05:00
func (c *Controller) Export(ctx *core.Context, request *core.Request, response *core.Response) {
2017-11-21 21:37:08 -05:00
user := ctx.LoggedUser()
2017-11-20 00:10:04 -05:00
opml, err := c.opmlHandler.Export(user.ID)
if err != nil {
2017-11-21 21:30:16 -05:00
response.HTML().ServerError(err)
2017-11-20 00:10:04 -05:00
return
}
2017-11-21 21:30:16 -05:00
response.XML().Download("feeds.opml", opml)
2017-11-20 00:10:04 -05:00
}
2017-11-28 00:30:04 -05:00
// Import shows the import form.
2017-11-20 00:10:04 -05:00
func (c *Controller) Import(ctx *core.Context, request *core.Request, response *core.Response) {
args, err := c.getCommonTemplateArgs(ctx)
if err != nil {
2017-11-21 21:30:16 -05:00
response.HTML().ServerError(err)
2017-11-20 00:10:04 -05:00
return
}
2017-11-21 21:30:16 -05:00
response.HTML().Render("import", args.Merge(tplParams{
2017-11-20 00:10:04 -05:00
"menu": "feeds",
}))
}
2017-11-28 00:30:04 -05:00
// UploadOPML handles OPML file importation.
2017-11-20 00:10:04 -05:00
func (c *Controller) UploadOPML(ctx *core.Context, request *core.Request, response *core.Response) {
2017-11-21 21:14:45 -05:00
file, fileHeader, err := request.File("file")
2017-11-20 00:10:04 -05:00
if err != nil {
log.Println(err)
2017-11-21 21:37:08 -05:00
response.Redirect(ctx.Route("import"))
2017-11-20 00:10:04 -05:00
return
}
defer file.Close()
2017-11-21 21:37:08 -05:00
user := ctx.LoggedUser()
2017-11-20 00:10:04 -05:00
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 {
2017-11-21 21:30:16 -05:00
response.HTML().ServerError(err)
2017-11-20 00:10:04 -05:00
return
}
2017-11-21 21:30:16 -05:00
response.HTML().Render("import", args.Merge(tplParams{
2017-11-20 17:35:11 -05:00
"errorMessage": impErr,
2017-11-20 00:10:04 -05:00
"menu": "feeds",
}))
return
}
2017-11-21 21:37:08 -05:00
response.Redirect(ctx.Route("feeds"))
2017-11-20 00:10:04 -05:00
}