Update new file-locations and load scripts and styles from the settings.json

This commit is contained in:
Lukas Rieger (Blue) 2022-12-13 16:48:12 +01:00
parent df59cdfc78
commit e6059e9051
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
3 changed files with 102 additions and 44 deletions

@ -1 +1 @@
Subproject commit 5bfb7754739b24f223ac14564c5e5fa965b4ef41
Subproject commit bdf89ed5b289d821f37a920923bbf80947673714

View File

@ -33,10 +33,61 @@ function startsWith($haystack, $needle) {
return substr($haystack, 0, strlen($needle)) === $needle;
}
// mime-types for meta-files
$mimeDefault = "application/octet-stream";
$mimeTypes = [
"txt" => "text/plain",
"css" => "text/css",
"csv" => "text/csv",
"htm" => "text/html",
"html" => "text/html",
"js" => "text/javascript",
"xml" => "text/xml",
"png" => "image/png",
"jpg" => "image/jpeg",
"jpeg" => "image/jpeg",
"gif" => "image/gif",
"webp" => "image/webp",
"tif" => "image/tiff",
"tiff" => "image/tiff",
"svg" => "image/svg+xml",
"json" => "application/json",
"mp3" => "audio/mpeg",
"oga" => "audio/ogg",
"wav" => "audio/wav",
"weba" => "audio/webm",
"mp4" => "video/mp4",
"mpeg" => "video/mpeg",
"webm" => "video/webm",
"ttf" => "font/ttf",
"woff" => "font/woff",
"woff2" => "font/woff2"
];
function getMimeType($path) {
global $mimeDefault, $mimeTypes;
$i = strrpos($path, ".");
if ($i === false) return $mimeDefault;
$s = strrpos($path, "/");
if ($s !== false && $i < $s) return $mimeDefault;
$suffix = substr($path, $i + 1);
if (isset($mimeTypes[$suffix]))
return $mimeTypes[$suffix];
return $mimeDefault;
}
// determine relative request-path
$root = dirname($_SERVER['PHP_SELF']);
if ($root === "/") $root = "";
if ($root === "/" || $root === "\\") $root = "";
$uriPath = $_SERVER['REQUEST_URI'];
$path = substr($uriPath, strlen($root));
@ -64,38 +115,6 @@ if (startsWith($path, "/maps/")) {
$sql = new mysqli($hostname, $username, $password, $database, $port);
if ($sql->errno) error(500, "Failed to connect to Database!");
// meta-files
$metaFiles = [
"textures.json" => "textures",
"settings.json" => "settings",
"live/markers" => "markers",
"live/players" => "players"
];
// provide meta-files
foreach ($metaFiles as $metaFilePath => $metaKey) {
if (startsWith($mapPath, $metaFilePath)) {
$statement = $sql->prepare("
SELECT t.`value`
FROM `bluemap_map_meta` t
INNER JOIN `bluemap_map` m
ON t.`map` = m.`id`
WHERE m.`map_id` = ?
AND t.`key` = ?
");
$statement->bind_param("ss", $mapId, $metaKey);
$statement->execute();
if ($statement->errno) error(500, "Database query failed!");
$result = $statement->get_result();
if ($result && $line = $result->fetch_assoc()) {
header("Content-Type: application/json");
echo $line["value"];
exit;
}
}
}
// provide map-tiles
if (startsWith($mapPath, "tiles/")) {
@ -140,12 +159,32 @@ if (startsWith($path, "/maps/")) {
exit;
}
// empty json response if nothing found
header("Content-Type: application/json");
echo "{}";
exit;
}
// empty json response if nothing found
header("Content-Type: application/json");
echo "{}";
exit;
// provide meta-files
$statement = $sql->prepare("
SELECT t.`value`
FROM `bluemap_map_meta` t
INNER JOIN `bluemap_map` m
ON t.`map` = m.`id`
WHERE m.`map_id` = ?
AND t.`key` = ?
");
$statement->bind_param("ss", $mapId, $mapPath);
$statement->execute();
if ($statement->errno) error(500, "Database query failed!");
$result = $statement->get_result();
if ($result && $line = $result->fetch_assoc()) {
header("Content-Type: ".getMimeType($mapPath));
echo $line["value"];
exit;
}
}

View File

@ -34,7 +34,8 @@ import {PopupMarker} from "@/js/PopupMarker";
import {MarkerSet} from "bluemap/src/markers/MarkerSet";
import {getLocalStorage, round, setLocalStorage} from "@/js/Utils";
import i18n from "../i18n";
import {MarkerManager, MarkerFileType} from "bluemap/src/markers/MarkerManager";
import {PlayerMarkerManager} from "bluemap/src/markers/PlayerMarkerManager";
import {NormalMarkerManager} from "bluemap/src/markers/NormalMarkerManager";
export class BlueMapApp {
@ -49,9 +50,9 @@ export class BlueMapApp {
this.mapControls = new MapControls(this.mapViewer.renderer.domElement);
this.freeFlightControls = new FreeFlightControls(this.mapViewer.renderer.domElement);
/** @type {MarkerManager} */
/** @type {PlayerMarkerManager} */
this.playerMarkerManager = null;
/** @type {MarkerManager} */
/** @type {NormalMarkerManager} */
this.markerFileManager = null;
/** @type {{
@ -68,7 +69,9 @@ export class BlueMapApp {
* lowresSliderDefault: number,
* lowresSliderMin: number,
* startLocation: string,
* maps: string[]
* maps: string[],
* scripts: string[],
* styles: string[]
* }}
**/
this.settings = null;
@ -134,6 +137,14 @@ export class BlueMapApp {
this.mapControls.maxDistance = this.settings.maxZoomDistance;
this.appState.controls.enableFreeFlight = this.settings.enableFreeFlight;
// load settings-styles
if (this.settings.styles) for (let styleUrl of this.settings.styles) {
let styleElement = document.createElement("link");
styleElement.rel = "stylesheet";
styleElement.href = styleUrl;
document.head.appendChild(styleElement);
}
// unload loaded maps
await this.mapViewer.switchMap(null);
oldMaps.forEach(map => map.dispose());
@ -165,6 +176,14 @@ export class BlueMapApp {
// save user settings
this.saveUserSettings();
// load settings-scripts
if (this.settings.scripts) for (let scriptUrl of this.settings.scripts) {
let scriptElement = document.createElement("script");
scriptElement.src = scriptUrl;
document.body.appendChild(scriptElement);
}
}
update = async () => {
@ -336,7 +355,7 @@ export class BlueMapApp {
const map = this.mapViewer.map;
if (!map) return;
this.playerMarkerManager = new MarkerManager(this.mapViewer.markers, map.data.dataUrl + "live/players", MarkerFileType.PLAYER, this.events);
this.playerMarkerManager = new PlayerMarkerManager(this.mapViewer.markers, map.data.dataUrl + "live/players.json", map.data.dataUrl + "live/assets/playerheads/", this.events);
this.playerMarkerManager.setAutoUpdateInterval(0);
return this.playerMarkerManager.update()
.then(() => {
@ -358,7 +377,7 @@ export class BlueMapApp {
const map = this.mapViewer.map;
if (!map) return;
this.markerFileManager = new MarkerManager(this.mapViewer.markers, map.data.dataUrl + "live/markers", MarkerFileType.NORMAL, this.events);
this.markerFileManager = new NormalMarkerManager(this.mapViewer.markers, map.data.dataUrl + "live/markers.json", this.events);
return this.markerFileManager.update()
.then(() => {
this.markerFileManager.setAutoUpdateInterval(1000 * 10);