2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-11-11 14:28:29 -05:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/storage"
|
|
|
|
"miniflux.app/v2/internal/template"
|
|
|
|
"miniflux.app/v2/internal/worker"
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Serve declares all routes for the user interface.
|
2021-01-02 19:33:41 -05:00
|
|
|
func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
|
2019-06-01 21:18:09 -04:00
|
|
|
middleware := newMiddleware(router, store)
|
2021-02-19 00:33:29 -05:00
|
|
|
|
|
|
|
templateEngine := template.NewEngine(router)
|
|
|
|
if err := templateEngine.ParseTemplates(); err != nil {
|
2023-09-24 19:32:09 -04:00
|
|
|
panic(err)
|
2021-02-19 00:33:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
handler := &handler{router, store, templateEngine, pool}
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
uiRouter := router.NewRoute().Subrouter()
|
|
|
|
uiRouter.Use(middleware.handleUserSession)
|
2019-01-21 23:21:05 -05:00
|
|
|
uiRouter.Use(middleware.handleAppSession)
|
2020-09-13 20:48:14 -04:00
|
|
|
uiRouter.StrictSlash(true)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Static assets.
|
2021-06-02 22:02:38 -04:00
|
|
|
uiRouter.HandleFunc("/stylesheets/{name}.{checksum}.css", handler.showStylesheet).Name("stylesheet").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/{name}.{checksum}.js", handler.showJavascript).Name("javascript").Methods(http.MethodGet)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/favicon.ico", handler.showFavicon).Name("favicon").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/icon/{filename}", handler.showAppIcon).Name("appIcon").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/manifest.json", handler.showWebManifest).Name("webManifest").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// New subscription pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/subscribe", handler.showAddSubscriptionPage).Name("addSubscription").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/subscribe", handler.submitSubscription).Name("submitSubscription").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/subscriptions", handler.showChooseSubscriptionPage).Name("chooseSubscription").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/bookmarklet", handler.bookmarklet).Name("bookmarklet").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Unread page.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/mark-all-as-read", handler.markAllAsRead).Name("markAllAsRead").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/unread", handler.showUnreadPage).Name("unread").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/unread/entry/{entryID}", handler.showUnreadEntryPage).Name("unreadEntry").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// History pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/history", handler.showHistoryPage).Name("history").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/history/entry/{entryID}", handler.showReadEntryPage).Name("readEntry").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/history/flush", handler.flushHistory).Name("flushHistory").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Bookmark pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/starred", handler.showStarredPage).Name("starred").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/starred/entry/{entryID}", handler.showStarredEntryPage).Name("starredEntry").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Search pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/search", handler.showSearchEntriesPage).Name("searchEntries").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/search/entry/{entryID}", handler.showSearchEntryPage).Name("searchEntry").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Feed listing pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/feeds", handler.showFeedsPage).Name("feeds").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/feeds/refresh", handler.refreshAllFeeds).Name("refreshAllFeeds").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Individual feed pages.
|
2023-08-08 10:12:41 -04:00
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/refresh", handler.refreshFeed).Name("refreshFeed").Methods(http.MethodGet, http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/refresh", handler.refreshFeed).Queries("forceRefresh", "{forceRefresh:true|false}").Name("refreshFeed").Methods(http.MethodGet, http.MethodPost)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/edit", handler.showEditFeedPage).Name("editFeed").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/remove", handler.removeFeed).Name("removeFeed").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/update", handler.updateFeed).Name("updateFeed").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/entries", handler.showFeedEntriesPage).Name("feedEntries").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/entries/all", handler.showFeedEntriesAllPage).Name("feedEntriesAll").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/entry/{entryID}", handler.showFeedEntryPage).Name("feedEntry").Methods(http.MethodGet)
|
2024-01-10 00:44:25 -05:00
|
|
|
uiRouter.HandleFunc("/unread/feed/{feedID}/entry/{entryID}", handler.showUnreadFeedEntryPage).Name("unreadFeedEntry").Methods(http.MethodGet)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/feed/icon/{iconID}", handler.showIcon).Name("icon").Methods(http.MethodGet)
|
2021-03-06 20:45:25 -05:00
|
|
|
uiRouter.HandleFunc("/feed/{feedID}/mark-all-as-read", handler.markFeedAsRead).Name("markFeedAsRead").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Category pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/entry/{entryID}", handler.showCategoryEntryPage).Name("categoryEntry").Methods(http.MethodGet)
|
2024-01-10 00:44:25 -05:00
|
|
|
uiRouter.HandleFunc("/unread/category/{categoryID}/entry/{entryID}", handler.showUnreadCategoryEntryPage).Name("unreadCategoryEntry").Methods(http.MethodGet)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/categories", handler.showCategoryListPage).Name("categories").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/category/create", handler.showCreateCategoryPage).Name("createCategory").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/category/save", handler.saveCategory).Name("saveCategory").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/feeds", handler.showCategoryFeedsPage).Name("categoryFeeds").Methods(http.MethodGet)
|
2022-12-11 12:07:01 -05:00
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/feeds/refresh", handler.refreshCategoryFeedsPage).Name("refreshCategoryFeedsPage").Methods(http.MethodGet)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/entries", handler.showCategoryEntriesPage).Name("categoryEntries").Methods(http.MethodGet)
|
2022-12-11 12:07:01 -05:00
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/entries/refresh", handler.refreshCategoryEntriesPage).Name("refreshCategoryEntriesPage").Methods(http.MethodGet)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/entries/all", handler.showCategoryEntriesAllPage).Name("categoryEntriesAll").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/edit", handler.showEditCategoryPage).Name("editCategory").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/update", handler.updateCategory).Name("updateCategory").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/remove", handler.removeCategory).Name("removeCategory").Methods(http.MethodPost)
|
2021-07-01 13:25:58 -04:00
|
|
|
uiRouter.HandleFunc("/category/{categoryID}/mark-all-as-read", handler.markCategoryAsRead).Name("markCategoryAsRead").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Entry pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/entry/status", handler.updateEntriesStatus).Name("updateEntriesStatus").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/entry/save/{entryID}", handler.saveEntry).Name("saveEntry").Methods(http.MethodPost)
|
Add Media Player and resume to last playback position
In order to ease podcast listening, the player can be put on top of the feed entry as main content.
Use the `Use podcast player` option to enable that. It works on audio and video.
Also, when playing audio or video, progression will be saved in order to be able to resume listening later.
This position saving is done using the original attachement/enclosures player AND podcast player and do not rely on
the podcast player option ti be enabled.
Additionally, I made the player fill the width with the entry container to ease seeking and have a bigger video.
updateEnclosures now keep existing enclosures based on URL
When feeds get updated, enclosures entries are always wiped and re-created. This cause two issue
- enclosure progression get lost in the process
- enclosure ID changes
I used the URL as identifier of an enclosure. Not perfect but hopefully should work.
When an enclosure already exist, I simply do nothing and leave the entry as is in the database.
If anyone is listening/watching to this enclosure during the refresh, the id stay coherent and progression saving still works.
The updateEnclosures function got a bit more complex. I tried to make it the more clear I could.
Some optimisation are possible but would make the function harder to read in my opinion.
I'm not sure if this is often the case, but some feeds may include tracking or simply change the url each
time we update the feed. In those situation, enclosures ids and progression will be lost.
I have no idea how to handle this last situation. Use the size instead/alongside url to define the identity of an enclosure ?
Translation: english as placeholder for every language except French
Aside, I tested a video feed and fixed a few things for it. In fact, the MimeType was not working
at all on my side, and found a pretty old stackoverflow discussion that suggest to use an Apple non-standard MimeType for
m4v video format. I only did one substitution because I only have one feed to test. Any new video feed can make this go away
or evolve depending on the situation. Real video feeds does not tend to be easy to find and test extensively this.
Co-authored-by: toastal
2023-04-13 05:46:43 -04:00
|
|
|
uiRouter.HandleFunc("/entry/enclosure/{enclosureID}/save-progression", handler.saveEnclosureProgression).Name("saveEnclosureProgression").Methods(http.MethodPost)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/entry/download/{entryID}", handler.fetchContent).Name("fetchContent").Methods(http.MethodPost)
|
2023-02-25 03:36:19 -05:00
|
|
|
uiRouter.HandleFunc("/proxy/{encodedDigest}/{encodedURL}", handler.mediaProxy).Name("proxy").Methods(http.MethodGet)
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/entry/bookmark/{entryID}", handler.toggleBookmark).Name("toggleBookmark").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
2019-10-05 07:30:25 -04:00
|
|
|
// Share pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/entry/share/{entryID}", handler.createSharedEntry).Name("shareEntry").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/entry/unshare/{entryID}", handler.unshareEntry).Name("unshareEntry").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/share/{shareCode}", handler.sharedEntry).Name("sharedEntry").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/shares", handler.sharedEntries).Name("sharedEntries").Methods(http.MethodGet)
|
2019-10-05 07:30:25 -04:00
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
// User pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/users", handler.showUsersPage).Name("users").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/user/create", handler.showCreateUserPage).Name("createUser").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/user/save", handler.saveUser).Name("saveUser").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/users/{userID}/edit", handler.showEditUserPage).Name("editUser").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/users/{userID}/update", handler.updateUser).Name("updateUser").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/users/{userID}/remove", handler.removeUser).Name("removeUser").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Settings pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/settings", handler.showSettingsPage).Name("settings").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/settings", handler.updateSettings).Name("updateSettings").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/integrations", handler.showIntegrationPage).Name("integrations").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/integration", handler.updateIntegration).Name("updateIntegration").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/integration/pocket/authorize", handler.pocketAuthorize).Name("pocketAuthorize").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/integration/pocket/callback", handler.pocketCallback).Name("pocketCallback").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/about", handler.showAboutPage).Name("about").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// Session pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/sessions", handler.showSessionsPage).Name("sessions").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/sessions/{sessionID}/remove", handler.removeSession).Name("removeSession").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
2020-03-01 20:38:29 -05:00
|
|
|
// API Keys pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/keys", handler.showAPIKeysPage).Name("apiKeys").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/keys/{keyID}/remove", handler.removeAPIKey).Name("removeAPIKey").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/keys/create", handler.showCreateAPIKeyPage).Name("createAPIKey").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/keys/save", handler.saveAPIKey).Name("saveAPIKey").Methods(http.MethodPost)
|
2020-03-01 20:38:29 -05:00
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
// OPML pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/export", handler.exportFeeds).Name("export").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/import", handler.showImportPage).Name("import").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/upload", handler.uploadOPML).Name("uploadOPML").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/fetch", handler.fetchOPML).Name("fetchOPML").Methods(http.MethodPost)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
|
|
|
// OAuth2 flow.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/oauth2/{provider}/unlink", handler.oauth2Unlink).Name("oauth2Unlink").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/oauth2/{provider}/redirect", handler.oauth2Redirect).Name("oauth2Redirect").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/oauth2/{provider}/callback", handler.oauth2Callback).Name("oauth2Callback").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
2021-03-07 18:25:34 -05:00
|
|
|
// Offline page
|
|
|
|
uiRouter.HandleFunc("/offline", handler.showOfflinePage).Name("offline").Methods(http.MethodGet)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
// Authentication pages.
|
2020-06-22 00:13:00 -04:00
|
|
|
uiRouter.HandleFunc("/login", handler.checkLogin).Name("checkLogin").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/logout", handler.logout).Name("logout").Methods(http.MethodGet)
|
|
|
|
uiRouter.Handle("/", middleware.handleAuthProxy(http.HandlerFunc(handler.showLoginPage))).Name("login").Methods(http.MethodGet)
|
2018-11-11 14:28:29 -05:00
|
|
|
|
2023-11-05 12:57:35 -05:00
|
|
|
// WebAuthn flow
|
|
|
|
uiRouter.HandleFunc("/webauthn/register/begin", handler.beginRegistration).Name("webauthnRegisterBegin").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/webauthn/register/finish", handler.finishRegistration).Name("webauthnRegisterFinish").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/webauthn/login/begin", handler.beginLogin).Name("webauthnLoginBegin").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/webauthn/login/finish", handler.finishLogin).Name("webauthnLoginFinish").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/webauthn/deleteall", handler.deleteAllCredentials).Name("webauthnDeleteAll").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/webauthn/{credentialHandle}/delete", handler.deleteCredential).Name("webauthnDelete").Methods(http.MethodPost)
|
|
|
|
uiRouter.HandleFunc("/webauthn/{credentialHandle}/rename", handler.renameCredential).Name("webauthnRename").Methods(http.MethodGet)
|
|
|
|
uiRouter.HandleFunc("/webauthn/{credentialHandle}/save", handler.saveCredential).Name("webauthnSave").Methods(http.MethodPost)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
router.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
|
|
w.Write([]byte("User-agent: *\nDisallow: /"))
|
|
|
|
}).Name("robots")
|
|
|
|
}
|