ui.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "miniflux.app/config"
  8. "miniflux.app/reader/feed"
  9. "miniflux.app/storage"
  10. "miniflux.app/template"
  11. "miniflux.app/worker"
  12. "github.com/gorilla/mux"
  13. )
  14. // Serve declares all routes for the user interface.
  15. func Serve(router *mux.Router, cfg *config.Config, store *storage.Storage, pool *worker.Pool, feedHandler *feed.Handler) {
  16. middleware := newMiddleware(router, cfg, store)
  17. handler := &handler{router, cfg, store, template.NewEngine(cfg, router), pool, feedHandler}
  18. uiRouter := router.NewRoute().Subrouter()
  19. uiRouter.Use(middleware.handleAppSession)
  20. uiRouter.Use(middleware.handleUserSession)
  21. // Static assets.
  22. uiRouter.HandleFunc("/stylesheets/{name}.css", handler.showStylesheet).Name("stylesheet").Methods("GET")
  23. uiRouter.HandleFunc("/{name}.js", handler.showJavascript).Name("javascript").Methods("GET")
  24. uiRouter.HandleFunc("/favicon.ico", handler.showFavicon).Name("favicon").Methods("GET")
  25. uiRouter.HandleFunc("/icon/{filename}", handler.showAppIcon).Name("appIcon").Methods("GET")
  26. uiRouter.HandleFunc("/manifest.json", handler.showWebManifest).Name("webManifest").Methods("GET")
  27. // New subscription pages.
  28. uiRouter.HandleFunc("/subscribe", handler.showAddSubscriptionPage).Name("addSubscription").Methods("GET")
  29. uiRouter.HandleFunc("/subscribe", handler.submitSubscription).Name("submitSubscription").Methods("POST")
  30. uiRouter.HandleFunc("/subscriptions", handler.showChooseSubscriptionPage).Name("chooseSubscription").Methods("POST")
  31. uiRouter.HandleFunc("/bookmarklet", handler.bookmarklet).Name("bookmarklet").Methods("GET")
  32. // Unread page.
  33. uiRouter.HandleFunc("/mark-all-as-read", handler.markAllAsRead).Name("markAllAsRead").Methods("GET")
  34. uiRouter.HandleFunc("/unread", handler.showUnreadPage).Name("unread").Methods("GET")
  35. uiRouter.HandleFunc("/unread/entry/{entryID}", handler.showUnreadEntryPage).Name("unreadEntry").Methods("GET")
  36. // History pages.
  37. uiRouter.HandleFunc("/history", handler.showHistoryPage).Name("history").Methods("GET")
  38. uiRouter.HandleFunc("/history/entry/{entryID}", handler.showReadEntryPage).Name("readEntry").Methods("GET")
  39. uiRouter.HandleFunc("/history/flush", handler.flushHistory).Name("flushHistory").Methods("GET")
  40. // Bookmark pages.
  41. uiRouter.HandleFunc("/starred", handler.showStarredPage).Name("starred").Methods("GET")
  42. uiRouter.HandleFunc("/starred/entry/{entryID}", handler.showStarredEntryPage).Name("starredEntry").Methods("GET")
  43. // Search pages.
  44. uiRouter.HandleFunc("/search", handler.showSearchEntriesPage).Name("searchEntries").Methods("GET")
  45. uiRouter.HandleFunc("/search/entry/{entryID}", handler.showSearchEntryPage).Name("searchEntry").Methods("GET")
  46. // Feed listing pages.
  47. uiRouter.HandleFunc("/feeds", handler.showFeedsPage).Name("feeds").Methods("GET")
  48. uiRouter.HandleFunc("/feeds/refresh", handler.refreshAllFeeds).Name("refreshAllFeeds").Methods("GET")
  49. // Individual feed pages.
  50. uiRouter.HandleFunc("/feed/{feedID}/refresh", handler.refreshFeed).Name("refreshFeed").Methods("GET")
  51. uiRouter.HandleFunc("/feed/{feedID}/edit", handler.showEditFeedPage).Name("editFeed").Methods("GET")
  52. uiRouter.HandleFunc("/feed/{feedID}/remove", handler.removeFeed).Name("removeFeed").Methods("POST")
  53. uiRouter.HandleFunc("/feed/{feedID}/update", handler.updateFeed).Name("updateFeed").Methods("POST")
  54. uiRouter.HandleFunc("/feed/{feedID}/entries", handler.showFeedEntriesPage).Name("feedEntries").Methods("GET")
  55. uiRouter.HandleFunc("/feed/{feedID}/entry/{entryID}", handler.showFeedEntryPage).Name("feedEntry").Methods("GET")
  56. uiRouter.HandleFunc("/feed/icon/{iconID}", handler.showIcon).Name("icon").Methods("GET")
  57. // Category pages.
  58. uiRouter.HandleFunc("/category/{categoryID}/entry/{entryID}", handler.showCategoryEntryPage).Name("categoryEntry").Methods("GET")
  59. uiRouter.HandleFunc("/categories", handler.showCategoryListPage).Name("categories").Methods("GET")
  60. uiRouter.HandleFunc("/category/create", handler.showCreateCategoryPage).Name("createCategory").Methods("GET")
  61. uiRouter.HandleFunc("/category/save", handler.saveCategory).Name("saveCategory").Methods("POST")
  62. uiRouter.HandleFunc("/category/{categoryID}/entries", handler.showCategoryEntriesPage).Name("categoryEntries").Methods("GET")
  63. uiRouter.HandleFunc("/category/{categoryID}/edit", handler.showEditCategoryPage).Name("editCategory").Methods("GET")
  64. uiRouter.HandleFunc("/category/{categoryID}/update", handler.updateCategory).Name("updateCategory").Methods("POST")
  65. uiRouter.HandleFunc("/category/{categoryID}/remove", handler.removeCategory).Name("removeCategory").Methods("POST")
  66. // Entry pages.
  67. uiRouter.HandleFunc("/entry/status", handler.updateEntriesStatus).Name("updateEntriesStatus").Methods("POST")
  68. uiRouter.HandleFunc("/entry/save/{entryID}", handler.saveEntry).Name("saveEntry").Methods("POST")
  69. uiRouter.HandleFunc("/entry/download/{entryID}", handler.fetchContent).Name("fetchContent").Methods("POST")
  70. uiRouter.HandleFunc("/proxy/{encodedURL}", handler.imageProxy).Name("proxy").Methods("GET")
  71. uiRouter.HandleFunc("/entry/bookmark/{entryID}", handler.toggleBookmark).Name("toggleBookmark").Methods("POST")
  72. // User pages.
  73. uiRouter.HandleFunc("/users", handler.showUsersPage).Name("users").Methods("GET")
  74. uiRouter.HandleFunc("/user/create", handler.showCreateUserPage).Name("createUser").Methods("GET")
  75. uiRouter.HandleFunc("/user/save", handler.saveUser).Name("saveUser").Methods("POST")
  76. uiRouter.HandleFunc("/users/{userID}/edit", handler.showEditUserPage).Name("editUser").Methods("GET")
  77. uiRouter.HandleFunc("/users/{userID}/update", handler.updateUser).Name("updateUser").Methods("POST")
  78. uiRouter.HandleFunc("/users/{userID}/remove", handler.removeUser).Name("removeUser").Methods("POST")
  79. // Settings pages.
  80. uiRouter.HandleFunc("/settings", handler.showSettingsPage).Name("settings").Methods("GET")
  81. uiRouter.HandleFunc("/settings", handler.updateSettings).Name("updateSettings").Methods("POST")
  82. uiRouter.HandleFunc("/integrations", handler.showIntegrationPage).Name("integrations").Methods("GET")
  83. uiRouter.HandleFunc("/integration", handler.updateIntegration).Name("updateIntegration").Methods("POST")
  84. uiRouter.HandleFunc("/integration/pocket/authorize", handler.pocketAuthorize).Name("pocketAuthorize").Methods("GET")
  85. uiRouter.HandleFunc("/integration/pocket/callback", handler.pocketCallback).Name("pocketCallback").Methods("GET")
  86. uiRouter.HandleFunc("/about", handler.showAboutPage).Name("about").Methods("GET")
  87. // Session pages.
  88. uiRouter.HandleFunc("/sessions", handler.showSessionsPage).Name("sessions").Methods("GET")
  89. uiRouter.HandleFunc("/sessions/{sessionID}/remove", handler.removeSession).Name("removeSession").Methods("POST")
  90. // OPML pages.
  91. uiRouter.HandleFunc("/export", handler.exportFeeds).Name("export").Methods("GET")
  92. uiRouter.HandleFunc("/import", handler.showImportPage).Name("import").Methods("GET")
  93. uiRouter.HandleFunc("/upload", handler.uploadOPML).Name("uploadOPML").Methods("POST")
  94. // OAuth2 flow.
  95. uiRouter.HandleFunc("/oauth2/{provider}/unlink", handler.oauth2Unlink).Name("oauth2Unlink").Methods("GET")
  96. uiRouter.HandleFunc("/oauth2/{provider}/redirect", handler.oauth2Redirect).Name("oauth2Redirect").Methods("GET")
  97. uiRouter.HandleFunc("/oauth2/{provider}/callback", handler.oauth2Callback).Name("oauth2Callback").Methods("GET")
  98. // Authentication pages.
  99. uiRouter.HandleFunc("/login", handler.checkLogin).Name("checkLogin").Methods("POST")
  100. uiRouter.HandleFunc("/logout", handler.logout).Name("logout").Methods("GET")
  101. uiRouter.HandleFunc("/", handler.showLoginPage).Name("login").Methods("GET")
  102. router.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {
  103. w.Write([]byte("OK"))
  104. }).Name("healthcheck")
  105. router.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
  106. w.Header().Set("Content-Type", "text/plain")
  107. w.Write([]byte("User-agent: *\nDisallow: /"))
  108. }).Name("robots")
  109. }