Skip to content

Commit 4d3273f

Browse files
committed
refactor
1 parent ff1a9f4 commit 4d3273f

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

modules/setting/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
761761
}
762762

763763
AbsoluteAssetURL = MakeAbsoluteAssetURL(AppURL, StaticURLPrefix)
764-
AssetVersion = url.QueryEscape(AppVer)
764+
AssetVersion = strings.ReplaceAll(AppVer, "+", "~") // make sure the version string is clear (no real escaping is needed)
765765

766766
manifestBytes := MakeManifestData(AppName, AppURL, AbsoluteAssetURL)
767767
ManifestData = `application/json;base64,` + base64.StdEncoding.EncodeToString(manifestBytes)

templates/base/head_script.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly.
99
appVer: '{{AppVer}}',
1010
appUrl: '{{AppUrl}}',
1111
appSubUrl: '{{AppSubUrl}}',
12-
assetVersion: '{{AssetVersion}}',
12+
assetVersionEncoded: encodeURIComponent('{{AssetVersion}}'), // will be used in URL construction directly
1313
assetUrlPrefix: '{{AssetUrlPrefix}}',
1414
runModeIsProd: {{.RunModeIsProd}},
1515
customEmojis: {{CustomEmojis}},

web_src/js/features/notification.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import $ from 'jquery';
22

3-
const {appSubUrl, csrfToken, notificationSettings, assetVersion} = window.config;
3+
const {appSubUrl, csrfToken, notificationSettings, assetVersionEncoded} = window.config;
44
let notificationSequenceNumber = 0;
55

66
export function initNotificationsTable() {
@@ -57,7 +57,7 @@ export function initNotificationCount() {
5757

5858
if (notificationSettings.EventSourceUpdateTime > 0 && window.EventSource && window.SharedWorker) {
5959
// Try to connect to the event source via the shared worker first
60-
const worker = new SharedWorker(`${__webpack_public_path__}js/eventsource.sharedworker.js?v=${assetVersion}`, 'notification-worker');
60+
const worker = new SharedWorker(`${__webpack_public_path__}js/eventsource.sharedworker.js?v=${assetVersionEncoded}`, 'notification-worker');
6161
worker.addEventListener('error', (event) => {
6262
console.error('worker error', event);
6363
});

web_src/js/features/serviceworker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {joinPaths, parseUrl} from '../utils.js';
22

3-
const {useServiceWorker, assetUrlPrefix, appVer, assetVersion} = window.config;
3+
const {useServiceWorker, assetUrlPrefix, appVer, assetVersionEncoded} = window.config;
44
const cachePrefix = 'static-cache-v'; // actual version is set in the service worker script
5-
const workerUrl = `${joinPaths(assetUrlPrefix, 'serviceworker.js')}?v=${assetVersion}`;
5+
const workerUrl = `${joinPaths(assetUrlPrefix, 'serviceworker.js')}?v=${assetVersionEncoded}`;
66

77
async function unregisterAll() {
88
for (const registration of await navigator.serviceWorker.getRegistrations()) {

web_src/js/features/stopwatch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import $ from 'jquery';
22
import prettyMilliseconds from 'pretty-ms';
33
import {createTippy} from '../modules/tippy.js';
44

5-
const {appSubUrl, csrfToken, notificationSettings, enableTimeTracking, assetVersion} = window.config;
5+
const {appSubUrl, csrfToken, notificationSettings, enableTimeTracking, assetVersionEncoded} = window.config;
66

77
export function initStopwatch() {
88
if (!enableTimeTracking) {
@@ -42,7 +42,7 @@ export function initStopwatch() {
4242
// if the browser supports EventSource and SharedWorker, use it instead of the periodic poller
4343
if (notificationSettings.EventSourceUpdateTime > 0 && window.EventSource && window.SharedWorker) {
4444
// Try to connect to the event source via the shared worker first
45-
const worker = new SharedWorker(`${__webpack_public_path__}js/eventsource.sharedworker.js?v=${assetVersion}`, 'notification-worker');
45+
const worker = new SharedWorker(`${__webpack_public_path__}js/eventsource.sharedworker.js?v=${assetVersionEncoded}`, 'notification-worker');
4646
worker.addEventListener('error', (event) => {
4747
console.error('worker error', event);
4848
});

0 commit comments

Comments
 (0)