luci-base: package update based cache-busting string

Problem:
After updating the JS-part of any package, the user is forced to clear
the browser cache.

Fix:
Each time a package is removed or installed, the contents of the
"/lib/apk/db/installed" file are changed.
This fix add the modification time of the "/lib/apk/db/installed" file
to the version of the main LuCI package (for each js-file).

Signed-off-by: Oleg S <remittor@gmail.com>
This commit is contained in:
Oleg S 2025-04-14 16:08:45 +03:00 committed by Paul Donald
parent 0f119d57f2
commit f6f82b52eb
2 changed files with 3 additions and 2 deletions

View File

@ -1,7 +1,7 @@
// Copyright 2022 Jo-Philipp Wich <jo@mein.io>
// Licensed to the public under the Apache License 2.0.
import { access, basename } from 'fs';
import { access, basename, stat } from 'fs';
import { cursor } from 'uci';
const template_directory = '/usr/share/ucode/luci/template';
@ -179,6 +179,7 @@ export default function(env) {
self.env.media = media;
self.env.theme = basename(media);
self.env.resource = uci.get('luci', 'main', 'resourcebase');
self.env.pkgs_update_time = stat('/lib/apk/db/installed')?.mtime ?? stat('/usr/lib/opkg/status')?.mtime ?? 0;
self.env.include = (...args) => self.render_any(...args);
return self;

View File

@ -7,7 +7,7 @@
include(`themes/${theme}/header`);
-%}
<script src="{{ resource }}/luci.js"></script>
<script src="{{ resource }}/luci.js?v={# PKG_VERSION #}-{{ pkgs_update_time }}"></script>
<script>
L = new LuCI({{ replace(`${ {
media : media,