miniflux/server/ui/controller/opml.go

65 lines
1.5 KiB
Go
Raw Normal View History

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) {
2017-11-22 03:37:08 +01:00
user := ctx.LoggedUser()
2017-11-20 06:10:04 +01:00
opml, err := c.opmlHandler.Export(user.ID)
if err != nil {
2017-11-22 03:30:16 +01:00
response.HTML().ServerError(err)
2017-11-20 06:10:04 +01:00
return
}
2017-11-22 03:30:16 +01:00
response.XML().Download("feeds.opml", opml)
2017-11-20 06:10:04 +01:00
}
func (c *Controller) Import(ctx *core.Context, request *core.Request, response *core.Response) {
args, err := c.getCommonTemplateArgs(ctx)
if err != nil {
2017-11-22 03:30:16 +01:00
response.HTML().ServerError(err)
2017-11-20 06:10:04 +01:00
return
}
2017-11-22 03:30:16 +01:00
response.HTML().Render("import", args.Merge(tplParams{
2017-11-20 06:10:04 +01:00
"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)
2017-11-22 03:37:08 +01:00
response.Redirect(ctx.Route("import"))
2017-11-20 06:10:04 +01:00
return
}
defer file.Close()
2017-11-22 03:37:08 +01:00
user := ctx.LoggedUser()
2017-11-20 06:10:04 +01: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-22 03:30:16 +01:00
response.HTML().ServerError(err)
2017-11-20 06:10:04 +01:00
return
}
2017-11-22 03:30:16 +01:00
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
}
2017-11-22 03:37:08 +01:00
response.Redirect(ctx.Route("feeds"))
2017-11-20 06:10:04 +01:00
}