Multiple improvements
Sonarqube Scanner / Prepare environment (push) Successful in 10s
Sonarqube Scanner / Build and test (push) Successful in 28s
Sonarqube Scanner / SonarQube analysis (push) Successful in 1m8s
Sonarqube Scanner / Deploy to Server (push) Successful in 8s

This commit is contained in:
2026-10-05 01:18:14 +02:00
parent 2b07e9bc47
commit 49a9de0355
27 changed files with 797 additions and 80 deletions
+36 -7
View File
@@ -12,6 +12,7 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
const MEDIA_STORE_NAME = 'media';
let mediaDatabasePromise = null;
let poiCounter = 0;
const objectUrls = new Set();
function storage() {
const target = globalThis.localStorage;
@@ -195,7 +196,9 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
const blob = await mediaBlob(media, options);
if (!blob) return { ...media, unavailable: true };
if (typeof globalThis.URL?.createObjectURL === 'function') {
return { ...media, url: globalThis.URL.createObjectURL(blob), unavailable: false };
const url = globalThis.URL.createObjectURL(blob);
objectUrls.add(url);
return { ...media, url, unavailable: false };
}
const fallback = await fileToDataUrl(blob);
return { ...media, dataUrl: fallback.dataUrl, unavailable: false };
@@ -204,16 +207,39 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
}
}
async function withMedia(routePackage, options = {}) {
if (!routePackage) return null;
const pois = await Promise.all((routePackage.pois || []).map(async poi => ({
async function poiWithMedia(poi, options = {}) {
if (!poi) return null;
return {
...poi,
audio: await mediaForUse(poi.audio, options),
images: await Promise.all((poi.images || []).map(media => mediaForUse(media, options)))
})));
};
}
function releasePoiMedia(poi) {
const urls = [poi?.audio?.url, poi?.audioUrl, ...(poi?.images || []).map(image => image.url)];
for (const url of urls) {
if (!objectUrls.delete(url)) continue;
globalThis.URL?.revokeObjectURL?.(url);
}
}
async function withMedia(routePackage, options = {}) {
if (!routePackage) return null;
const pois = await Promise.all((routePackage.pois || []).map(poi => poiWithMedia(poi, options)));
return { ...routePackage, pois };
}
async function getPoiWithMedia(id, poiId, options = {}) {
const poi = readPackage(id)?.pois.find(item => String(item.id) === String(poiId));
return poiWithMedia(poi, options);
}
async function getAppPoi(id, poiId, options = {}) {
const poi = await getPoiWithMedia(id, poiId, options);
return poi ? appPoi(poi) : null;
}
function mediaForStorage(media) {
if (!media) return null;
const stored = { ...media };
@@ -709,8 +735,8 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
return listPackages().map(toAppRoute);
}
async function getAppRoute(id, options = {}) {
const routePackage = await withMedia(readPackage(id), options);
async function getAppRoute(id) {
const routePackage = readPackage(id);
if (!routePackage) throw new Error(ns.I18n.t("local.error.route-missing"));
return toAppRoute(routePackage);
}
@@ -762,6 +788,9 @@ globalThis.Wegwichtel = globalThis.Wegwichtel || {};
get: readPackage,
getAppRoute,
getWithMedia,
getPoiWithMedia,
getAppPoi,
releasePoiMedia,
gpxForUpload,
list: listPackages,
listAppRoutes,