mirror of
https://github.com/navidrome/navidrome.git
synced 2026-01-01 11:28:04 -05:00
Compare commits
3 Commits
new-plugin
...
v0.41.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43bb075849 | ||
|
|
e8d409e7c0 | ||
|
|
8e1982c633 |
@@ -6,6 +6,7 @@ import (
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
@@ -19,6 +20,11 @@ import (
|
||||
func serveIndex(ds model.DataStore, fs fs.FS) http.HandlerFunc {
|
||||
policy := bluemonday.UGCPolicy()
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
base := path.Join(conf.Server.BaseURL, consts.URLPathUI)
|
||||
if r.URL.Path == base {
|
||||
http.Redirect(w, r, base+"/", 302)
|
||||
}
|
||||
|
||||
c, err := ds.User(r.Context()).CountAll()
|
||||
firstTime := c == 0 && err == nil
|
||||
|
||||
|
||||
@@ -26,6 +26,16 @@ var _ = Describe("serveIndex", func() {
|
||||
conf.Server.UILoginBackgroundURL = ""
|
||||
})
|
||||
|
||||
It("redirects bare /app path to /app/", func() {
|
||||
r := httptest.NewRequest("GET", "/app", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
serveIndex(ds, fs)(w, r)
|
||||
|
||||
Expect(w.Code).To(Equal(302))
|
||||
Expect(w.Header().Get("Location")).To(Equal("/app/"))
|
||||
})
|
||||
|
||||
It("adds app_config to index.html", func() {
|
||||
r := httptest.NewRequest("GET", "/index.html", nil)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -61,7 +61,7 @@ func (a *Server) initRoutes() {
|
||||
r.Use(injectLogger)
|
||||
r.Use(robotsTXT(ui.Assets()))
|
||||
|
||||
indexHtml := path.Join(conf.Server.BaseURL, consts.URLPathUI, "index.html")
|
||||
indexHtml := path.Join(conf.Server.BaseURL, consts.URLPathUI)
|
||||
r.Get("/*", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, indexHtml, 302)
|
||||
})
|
||||
|
||||
48
ui/public/navidrome-service-worker.js
Normal file
48
ui/public/navidrome-service-worker.js
Normal file
@@ -0,0 +1,48 @@
|
||||
// documentation: https://developers.google.com/web/tools/workbox/modules/workbox-sw
|
||||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/6.1.2/workbox-sw.js");
|
||||
|
||||
workbox.loadModule('workbox-core');
|
||||
workbox.loadModule('workbox-strategies');
|
||||
workbox.loadModule('workbox-routing');
|
||||
workbox.loadModule('workbox-navigation-preload');
|
||||
|
||||
workbox.core.clientsClaim();
|
||||
self.skipWaiting();
|
||||
|
||||
addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'SKIP_WAITING') {
|
||||
skipWaiting();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
const CACHE_NAME = 'offline-html';
|
||||
// This assumes /offline.html is a URL for your self-contained
|
||||
// (no external images or styles) offline page.
|
||||
const FALLBACK_HTML_URL = './offline.html';
|
||||
// Populate the cache with the offline HTML page when the
|
||||
// service worker is installed.
|
||||
self.addEventListener('install', async (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then((cache) => cache.add(FALLBACK_HTML_URL))
|
||||
);
|
||||
});
|
||||
|
||||
const networkOnly = new workbox.strategies.NetworkOnly();
|
||||
const navigationHandler = async (params) => {
|
||||
try {
|
||||
// Attempt a network request.
|
||||
return await networkOnly.handle(params);
|
||||
} catch (error) {
|
||||
// If it fails, return the cached HTML.
|
||||
return caches.match(FALLBACK_HTML_URL, {
|
||||
cacheName: CACHE_NAME,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Register this strategy to handle all navigations.
|
||||
workbox.routing.registerRoute(
|
||||
new workbox.routing.NavigationRoute(navigationHandler)
|
||||
);
|
||||
10
ui/public/offline.html
Normal file
10
ui/public/offline.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head><title>Navidrome</title></head>
|
||||
<body style="margin:0">
|
||||
<p id="errorMessageDescription" style="text-align:center;font-size:21px;font-family:arial;margin-top:28px">
|
||||
It looks like we are having trouble connecting.
|
||||
<br/>
|
||||
Please check your internet connection and try again.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -99,9 +99,10 @@ const removeItems = () => {
|
||||
}
|
||||
|
||||
const clearServiceWorkerCache = () => {
|
||||
caches.keys().then(function (keyList) {
|
||||
for (let key of keyList) caches.delete(key)
|
||||
})
|
||||
window.caches &&
|
||||
caches.keys().then(function (keyList) {
|
||||
for (let key of keyList) caches.delete(key)
|
||||
})
|
||||
}
|
||||
|
||||
const generateSubsonicSalt = () => {
|
||||
|
||||
@@ -32,7 +32,7 @@ export function register(config) {
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`
|
||||
const swUrl = `${process.env.PUBLIC_URL}/navidrome-service-worker.js`
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
|
||||
Reference in New Issue
Block a user