dev: invalidate cache for gui static files when they change
Massimo Melina committed
Apr 24, 2024 at 11:28 UTC
23c8d34f68a76e02211154c40feabdeab0e544cf
1 file changed
+4
-6
src/serveGuiFiles.ts
+4
-6
@@ -9,7 +9,7 @@ import { getPluginConfigFields, getPluginInfo, mapPlugins, pluginsConfig } from
9
import { refresh_session } from './api.auth'
10
import { ApiError } from './apiMiddleware'
11
import { join, extname } from 'path'
12
-import { CFG, debounceAsync, FRONTEND_OPTIONS, getOrSet, newObj, onlyTruthy, repeat } from './misc'
12
+import { CFG, debounceAsync, FRONTEND_OPTIONS, newObj, onlyTruthy, parseFile } from './misc'
13
import { favicon, title } from './adminApis'
14
import { subscribe } from 'valtio/vanilla'
15
import { customHtmlState, getSection } from './customHtml'
@@ -40,11 +40,9 @@ function serveStatic(uri: string): Koa.Middleware {
40
return ctx.status = HTTP_METHOD_NOT_ALLOWED
41
const serveApp = shouldServeApp(ctx)
42
const fullPath = join(__dirname, '..', DEV_STATIC, folder, serveApp ? '/index.html': ctx.path)
43
- const content = await getOrSet(cache, ctx.path, async () => {
44
- const data = await fs.readFile(fullPath).catch(() => null)
45
- return serveApp || !data ? data
46
- : adjustBundlerLinks(ctx, uri, data)
47
- })
43
+ const content = await parseFile(fullPath,
44
+ raw => serveApp || !raw.length ? raw : adjustBundlerLinks(ctx, uri, raw) )
45
+ .catch(() => null)
46
if (content === null)
47
return ctx.status = HTTP_NOT_FOUND
48
if (!serveApp)