1
0
Fork 0
miniflux/ui/opml.go

72 lines
1.8 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 ui
2017-11-20 00:10:04 -05:00
import (
"github.com/miniflux/miniflux/http/handler"
2017-12-15 21:55:57 -05:00
"github.com/miniflux/miniflux/logger"
2017-11-20 00:10:04 -05:00
)
2017-11-28 00:30:04 -05:00
// Export generates the OPML file.
func (c *Controller) Export(ctx *handler.Context, request *handler.Request, response *handler.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.
func (c *Controller) Import(ctx *handler.Context, request *handler.Request, response *handler.Response) {
2017-11-20 00:10:04 -05:00
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.
func (c *Controller) UploadOPML(ctx *handler.Context, request *handler.Request, response *handler.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 {
2017-12-15 21:55:57 -05:00
logger.Error("[Controller:UploadOPML] %v", 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-12-15 21:55:57 -05:00
logger.Info(
"[Controller:UploadOPML] User #%d uploaded this file: %s (%d bytes)",
user.ID,
fileHeader.Filename,
fileHeader.Size,
)
2017-11-20 00:10:04 -05:00
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
}