From d882bbca85b801ed408644800364ec0a5bdcffd4 Mon Sep 17 00:00:00 2001 From: Peter De Wachter Date: Thu, 15 Aug 2019 09:48:07 +0200 Subject: [PATCH] Import OPML from URL --- locale/translations.go | 27 ++++++++++++++------- locale/translations/de_DE.json | 1 + locale/translations/en_US.json | 1 + locale/translations/es_ES.json | 1 + locale/translations/fr_FR.json | 1 + locale/translations/it_IT.json | 1 + locale/translations/nl_NL.json | 1 + locale/translations/pl_PL.json | 1 + locale/translations/ru_RU.json | 1 + locale/translations/zh_CN.json | 1 + template/html/import.html | 11 +++++++++ template/views.go | 13 +++++++++- ui/opml_upload.go | 44 ++++++++++++++++++++++++++++++++++ ui/ui.go | 1 + 14 files changed, 95 insertions(+), 10 deletions(-) diff --git a/locale/translations.go b/locale/translations.go index 7eae8aa8..6267ca79 100644 --- a/locale/translations.go +++ b/locale/translations.go @@ -223,6 +223,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Neueste Artikel zuerst", "form.prefs.label.keyboard_shortcuts": "Tastaturkürzel aktivieren", "form.import.label.file": "OPML Datei", + "form.import.label.url": "URL", "form.integration.fever_activate": "Fever API aktivieren", "form.integration.fever_username": "Fever Benutzername", "form.integration.fever_password": "Fever Passwort", @@ -518,6 +519,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Recent entries first", "form.prefs.label.keyboard_shortcuts": "Enable keyboard shortcuts", "form.import.label.file": "OPML file", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activate Fever API", "form.integration.fever_username": "Fever Username", "form.integration.fever_password": "Fever Password", @@ -793,6 +795,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Entradas recientes primero", "form.prefs.label.keyboard_shortcuts": "Habilitar atajos de teclado", "form.import.label.file": "Archivo OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activar API de Fever", "form.integration.fever_username": "Nombre de usuario de Fever", "form.integration.fever_password": "Contraseña de Fever", @@ -1068,6 +1071,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Éléments récents en premier", "form.prefs.label.keyboard_shortcuts": "Activer les raccourcis clavier", "form.import.label.file": "Fichier OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activer l'API de Fever", "form.integration.fever_username": "Nom d'utilisateur pour l'API de Fever", "form.integration.fever_password": "Mot de passe pour l'API de Fever", @@ -1363,6 +1367,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Prima i più vecchi", "form.prefs.label.keyboard_shortcuts": "Abilita le scorciatoie da tastiera", "form.import.label.file": "File OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Abilita l'API di Fever", "form.integration.fever_username": "Nome utente dell'account Fever", "form.integration.fever_password": "Password dell'account Fever", @@ -1638,6 +1643,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Recente items eerst", "form.prefs.label.keyboard_shortcuts": "Schakel sneltoetsen in", "form.import.label.file": "OPML-bestand", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activeer Fever API", "form.integration.fever_username": "Fever gebruikersnaam", "form.integration.fever_password": "Fever wachtwoord", @@ -1933,6 +1939,7 @@ var translations = map[string]string{ "form.prefs.label.keyboard_shortcuts": "Włącz skróty klawiaturowe", "form.prefs.select.recent_first": "Najnowsze wpisy jako pierwsze", "form.import.label.file": "Plik OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Aktywuj Fever API", "form.integration.fever_username": "Login do Fever", "form.integration.fever_password": "Hasło do Fever", @@ -2234,6 +2241,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "Сначала последние записи", "form.prefs.label.keyboard_shortcuts": "Включить сочетания клавиш", "form.import.label.file": "OPML файл", + "form.import.label.url": "URL", "form.integration.fever_activate": "Активировать Fever API", "form.integration.fever_username": "Имя пользователя Fever", "form.integration.fever_password": "Пароль Fever", @@ -2513,6 +2521,7 @@ var translations = map[string]string{ "form.prefs.select.recent_first": "新->旧", "form.prefs.label.keyboard_shortcuts": "启用键盘快捷键", "form.import.label.file": "OPML 文件", + "form.import.label.url": "URL", "form.integration.fever_activate": "启用 Fever API", "form.integration.fever_username": "Fever 用户名", "form.integration.fever_password": "Fever 密码", @@ -2583,13 +2592,13 @@ var translations = map[string]string{ } var translationsChecksums = map[string]string{ - "de_DE": "d8679b1026dffcdefe9afe519562ec52078f072cedd64f589bddb2b083fe5887", - "en_US": "7333eb884f4b98b238e07730187342dbc17149c68fabcc73c60478d75b7aa3c8", - "es_ES": "32d094110fd92971fe20a0ac2c3cb15db6a6fb06dba94815d75cab00cf4b73e3", - "fr_FR": "dda1c84e1b970efa8c564d459365ee17ad256ce684d7a036b31da70b50266ab2", - "it_IT": "b9e7ec9ad3ddd3a439ce238b5dd189000501bf26905d24fbb84ee77703999543", - "nl_NL": "04fa292f0ee9d4e98c39ecb1df11965881034f26685afb0081026850347a3b1c", - "pl_PL": "734173b0ceadcb1386dfc98e730fef40282f45dd45c02ac918ae1bb4b7ec0c39", - "ru_RU": "d50e95a88aec5ff8d43d197eeaa294e3ed2009181901e9deaffe48f7aa560a26", - "zh_CN": "b27685df8ed3accb573ca1401f25077e5c26f1e3e98d96e07353876821d53835", + "de_DE": "2ca6c01934316256bf3f06bd1d40fb7700834b285ac87a24692389e4f39de7c2", + "en_US": "547bca5fe9062da289f6d8ab0d3c3f6156d6ae5c3718fa6c0fdbb3853e4c7a8a", + "es_ES": "eb01f7a1fd73cdc54468435887f1c1201489aeceda25f852a63ce6aa80e54e52", + "fr_FR": "76f0555737a9b5c7ec5e40e6242e24b74ebb9457290a3924a9fc2058b5b6da1c", + "it_IT": "335d2a9b3eda6313a9521abf4b7fd8597575a5aa0a664cebe54a467ac5db944d", + "nl_NL": "f30abf2bf7eddd499a012beee07f47da8633788ebf6db5ff685922a6ec66f5fd", + "pl_PL": "a664bd0d472818557d98de50ed8f04f96c2b9307a66c24c04e589dc07c465a8b", + "ru_RU": "7d4c82d2c3710bbf3b9ea07ed2cfcc32e7c7b45836539b5ce0ab10ec1290e615", + "zh_CN": "dc68f7d06b360ada0fed620522cec80baf7ed417fb54a3c3271849ccdaa69086", } diff --git a/locale/translations/de_DE.json b/locale/translations/de_DE.json index de9ada34..9bb5282e 100644 --- a/locale/translations/de_DE.json +++ b/locale/translations/de_DE.json @@ -218,6 +218,7 @@ "form.prefs.select.recent_first": "Neueste Artikel zuerst", "form.prefs.label.keyboard_shortcuts": "Tastaturkürzel aktivieren", "form.import.label.file": "OPML Datei", + "form.import.label.url": "URL", "form.integration.fever_activate": "Fever API aktivieren", "form.integration.fever_username": "Fever Benutzername", "form.integration.fever_password": "Fever Passwort", diff --git a/locale/translations/en_US.json b/locale/translations/en_US.json index 72ec06d2..a1f74742 100644 --- a/locale/translations/en_US.json +++ b/locale/translations/en_US.json @@ -218,6 +218,7 @@ "form.prefs.select.recent_first": "Recent entries first", "form.prefs.label.keyboard_shortcuts": "Enable keyboard shortcuts", "form.import.label.file": "OPML file", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activate Fever API", "form.integration.fever_username": "Fever Username", "form.integration.fever_password": "Fever Password", diff --git a/locale/translations/es_ES.json b/locale/translations/es_ES.json index dbfa9f4f..a0d381ed 100644 --- a/locale/translations/es_ES.json +++ b/locale/translations/es_ES.json @@ -218,6 +218,7 @@ "form.prefs.select.recent_first": "Entradas recientes primero", "form.prefs.label.keyboard_shortcuts": "Habilitar atajos de teclado", "form.import.label.file": "Archivo OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activar API de Fever", "form.integration.fever_username": "Nombre de usuario de Fever", "form.integration.fever_password": "Contraseña de Fever", diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index cea78a22..697c5d3a 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -218,6 +218,7 @@ "form.prefs.select.recent_first": "Éléments récents en premier", "form.prefs.label.keyboard_shortcuts": "Activer les raccourcis clavier", "form.import.label.file": "Fichier OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activer l'API de Fever", "form.integration.fever_username": "Nom d'utilisateur pour l'API de Fever", "form.integration.fever_password": "Mot de passe pour l'API de Fever", diff --git a/locale/translations/it_IT.json b/locale/translations/it_IT.json index c926c267..cffa2262 100644 --- a/locale/translations/it_IT.json +++ b/locale/translations/it_IT.json @@ -218,6 +218,7 @@ "form.prefs.select.recent_first": "Prima i più vecchi", "form.prefs.label.keyboard_shortcuts": "Abilita le scorciatoie da tastiera", "form.import.label.file": "File OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Abilita l'API di Fever", "form.integration.fever_username": "Nome utente dell'account Fever", "form.integration.fever_password": "Password dell'account Fever", diff --git a/locale/translations/nl_NL.json b/locale/translations/nl_NL.json index 4cd3252e..d663f55f 100644 --- a/locale/translations/nl_NL.json +++ b/locale/translations/nl_NL.json @@ -218,6 +218,7 @@ "form.prefs.select.recent_first": "Recente items eerst", "form.prefs.label.keyboard_shortcuts": "Schakel sneltoetsen in", "form.import.label.file": "OPML-bestand", + "form.import.label.url": "URL", "form.integration.fever_activate": "Activeer Fever API", "form.integration.fever_username": "Fever gebruikersnaam", "form.integration.fever_password": "Fever wachtwoord", diff --git a/locale/translations/pl_PL.json b/locale/translations/pl_PL.json index f3b9b958..ffee6bde 100644 --- a/locale/translations/pl_PL.json +++ b/locale/translations/pl_PL.json @@ -220,6 +220,7 @@ "form.prefs.label.keyboard_shortcuts": "Włącz skróty klawiaturowe", "form.prefs.select.recent_first": "Najnowsze wpisy jako pierwsze", "form.import.label.file": "Plik OPML", + "form.import.label.url": "URL", "form.integration.fever_activate": "Aktywuj Fever API", "form.integration.fever_username": "Login do Fever", "form.integration.fever_password": "Hasło do Fever", diff --git a/locale/translations/ru_RU.json b/locale/translations/ru_RU.json index 17b28421..9bc3b43c 100644 --- a/locale/translations/ru_RU.json +++ b/locale/translations/ru_RU.json @@ -220,6 +220,7 @@ "form.prefs.select.recent_first": "Сначала последние записи", "form.prefs.label.keyboard_shortcuts": "Включить сочетания клавиш", "form.import.label.file": "OPML файл", + "form.import.label.url": "URL", "form.integration.fever_activate": "Активировать Fever API", "form.integration.fever_username": "Имя пользователя Fever", "form.integration.fever_password": "Пароль Fever", diff --git a/locale/translations/zh_CN.json b/locale/translations/zh_CN.json index baca60a9..5db3ea25 100644 --- a/locale/translations/zh_CN.json +++ b/locale/translations/zh_CN.json @@ -216,6 +216,7 @@ "form.prefs.select.recent_first": "新->旧", "form.prefs.label.keyboard_shortcuts": "启用键盘快捷键", "form.import.label.file": "OPML 文件", + "form.import.label.url": "URL", "form.integration.fever_activate": "启用 Fever API", "form.integration.fever_username": "Fever 用户名", "form.integration.fever_password": "Fever 密码", diff --git a/template/html/import.html b/template/html/import.html index 0668f255..3a2b987a 100644 --- a/template/html/import.html +++ b/template/html/import.html @@ -31,4 +31,15 @@ +
+ + + + + +
+ +
+
+ {{ end }} diff --git a/template/views.go b/template/views.go index 4f51dc23..86da9c59 100644 --- a/template/views.go +++ b/template/views.go @@ -955,6 +955,17 @@ var templateViewsMap = map[string]string{ +
+ + + + + +
+ +
+
+ {{ end }} `, "integrations": `{{ define "title"}}{{ t "page.integrations.title" }}{{ end }} @@ -1469,7 +1480,7 @@ var templateViewsMapChecksums = map[string]string{ "feed_entries": "4bb6b96ba4d13dbaf22dcf6dd95ae36b6e5a0c99175d502865a164dc68fd4bae", "feeds": "d11fb629921e22bbf6d9ecb1adcc38922fafcee84f81c437abf47209544bd1c5", "history_entries": "9763d2120cfaeb78d406fdc029197fed2f7cfa7682970eeedae82ae79be65519", - "import": "8349e47a783bb40d8e9248b4771656e5f006185e11079e1c4680dd52633420ed", + "import": "d7abfdc2cd4db38ed695d5fecd140e2e736d3633127589e1292736224dc23798", "integrations": "f85b4a48ab1fc13b8ca94bfbbc44bd5e8784f35b26a63ec32cbe82b96b45e008", "login": "2e72d2d4b9786641b696bedbed5e10b04bdfd68254ddbbdb0a53cca621d200c7", "search_entries": "d71849a4f2b0573c7c76ad0ea941812009e9f022de60895987a781d3e6f08a01", diff --git a/ui/opml_upload.go b/ui/opml_upload.go index e5a9391c..4c94db65 100644 --- a/ui/opml_upload.go +++ b/ui/opml_upload.go @@ -7,6 +7,7 @@ package ui // import "miniflux.app/ui" import ( "net/http" + "miniflux.app/http/client" "miniflux.app/http/request" "miniflux.app/http/response/html" "miniflux.app/http/route" @@ -59,3 +60,46 @@ func (h *handler) uploadOPML(w http.ResponseWriter, r *http.Request) { html.Redirect(w, r, route.Path(h.router, "feeds")) } + +func (h *handler) fetchOPML(w http.ResponseWriter, r *http.Request) { + user, err := h.store.UserByID(request.UserID(r)) + if err != nil { + html.ServerError(w, r, err) + return + } + + url := r.FormValue("url") + if url == "" { + html.Redirect(w, r, route.Path(h.router, "import")) + return + } + + logger.Debug( + "[UI:FetchOPML] User #%d fetching this URL: %s", + user.ID, + url, + ) + + sess := session.New(h.store, request.SessionID(r)) + view := view.New(h.tpl, r, sess) + view.Set("menu", "feeds") + view.Set("user", user) + view.Set("countUnread", h.store.CountUnreadEntries(user.ID)) + view.Set("countErrorFeeds", h.store.CountErrorFeeds(user.ID)) + + clt := client.New(url) + resp, err := clt.Get() + if err != nil { + view.Set("errorMessage", err) + html.OK(w, r, view.Render("import")) + return + } + + if impErr := opml.NewHandler(h.store).Import(user.ID, resp.Body); impErr != nil { + view.Set("errorMessage", impErr) + html.OK(w, r, view.Render("import")) + return + } + + html.Redirect(w, r, route.Path(h.router, "feeds")) +} diff --git a/ui/ui.go b/ui/ui.go index 4a608076..dd1a9d84 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -112,6 +112,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHa uiRouter.HandleFunc("/export", handler.exportFeeds).Name("export").Methods("GET") uiRouter.HandleFunc("/import", handler.showImportPage).Name("import").Methods("GET") uiRouter.HandleFunc("/upload", handler.uploadOPML).Name("uploadOPML").Methods("POST") + uiRouter.HandleFunc("/fetch", handler.fetchOPML).Name("fetchOPML").Methods("POST") // OAuth2 flow. uiRouter.HandleFunc("/oauth2/{provider}/unlink", handler.oauth2Unlink).Name("oauth2Unlink").Methods("GET")