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.
|
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
package ui
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
import (
|
2018-01-03 07:04:48 +01:00
|
|
|
"github.com/miniflux/miniflux/http/handler"
|
2017-12-16 03:55:57 +01:00
|
|
|
"github.com/miniflux/miniflux/logger"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// Export generates the OPML file.
|
2018-01-03 07:04:48 +01:00
|
|
|
func (c *Controller) Export(ctx *handler.Context, request *handler.Request, response *handler.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
|
|
|
}
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// Import shows the import form.
|
2018-01-03 07:04:48 +01:00
|
|
|
func (c *Controller) Import(ctx *handler.Context, request *handler.Request, response *handler.Response) {
|
2017-11-20 06:10:04 +01:00
|
|
|
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",
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2017-11-28 06:30:04 +01:00
|
|
|
// UploadOPML handles OPML file importation.
|
2018-01-03 07:04:48 +01:00
|
|
|
func (c *Controller) UploadOPML(ctx *handler.Context, request *handler.Request, response *handler.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 {
|
2017-12-16 03:55:57 +01:00
|
|
|
logger.Error("[Controller:UploadOPML] %v", 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-12-16 03:55:57 +01:00
|
|
|
logger.Info(
|
|
|
|
"[Controller:UploadOPML] User #%d uploaded this file: %s (%d bytes)",
|
|
|
|
user.ID,
|
|
|
|
fileHeader.Filename,
|
|
|
|
fileHeader.Size,
|
|
|
|
)
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|