refactor: add t parameter for plugin bundle resources (#4804)

#### What type of PR is this?

/area console
/kind improvement
/milestone 2.11.x

#### What this PR does / why we need it:

为插件的 bundle.css 和 bundle.js 重定向请求添加时间戳参数,防止被浏览器、Nginx、CDN 服务缓存,导致插件的资源不能及时更新。

#### Which issue(s) this PR fixes:

Fixes #4803 

#### Special notes for your reviewer:

测试方式:

1. 在 Firefox 浏览器测试启动和停止若干插件,观察插件提供的 UI 样式是否正常即可。

#### Does this PR introduce a user-facing change?

```release-note
优化 Console 端插件捆绑资源的请求,防止在操作插件状态之后无法及时更新资源。
```
pull/4819/head
Ryan Wang 2023-11-02 15:44:48 +08:00 committed by GitHub
parent 2d743123bf
commit a8a5413460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -21,7 +21,7 @@ export async function setupPluginModules(app: App) {
const { load } = useScriptTag( const { load } = useScriptTag(
`${ `${
import.meta.env.VITE_API_URL import.meta.env.VITE_API_URL
}/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js` }/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.js?t=${Date.now()}`
); );
await load(); await load();
@ -45,7 +45,7 @@ export async function setupPluginModules(app: App) {
await loadStyle( await loadStyle(
`${ `${
import.meta.env.VITE_API_URL import.meta.env.VITE_API_URL
}/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.css` }/apis/api.console.halo.run/v1alpha1/plugins/-/bundle.css?t=${Date.now()}`
); );
} catch (e) { } catch (e) {
const message = i18n.global.t("core.plugin.loader.toast.style_load_failed"); const message = i18n.global.t("core.plugin.loader.toast.style_load_failed");

View File

@ -2,7 +2,7 @@ export function loadStyle(href: string) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
let shouldAppend = false; let shouldAppend = false;
let el: HTMLLinkElement | null = document.querySelector( let el: HTMLLinkElement | null = document.querySelector(
'script[src="' + href + '"]' 'link[href="' + href + '"]'
); );
if (!el) { if (!el) {
el = document.createElement("link"); el = document.createElement("link");