1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wa-dyn-map/wa-dyn-map.py

41 lines
1.2 KiB

from flask import Flask, jsonify, abort
from pathlib import Path
import json
app = Flask(__name__)
base_dir = Path('../Prediger-workadventure').resolve()
print(base_dir)
@app.route('/dyn/<string:code>/<path:map>')
def dyn_map(code, map):
p = (base_dir / map).resolve()
print(p)
if not base_dir < p:
abort(404)
if p.is_file() and p.suffix == ".json":
with p.open() as f:
map = json.load(f)
if "layers" in map:
for i in range(len(map["layers"])):
if "properties" in map["layers"][i]:
for j in range(len(map["layers"][i]["properties"])):
if "name" in map["layers"][i]["properties"][j] and map["layers"][i]["properties"][j]["name"] == "jitsiRoom" and "value" in map["layers"][i]["properties"][j]:
map["layers"][i]["properties"][j]["value"] = map["layers"][i]["properties"][j]["value"] + "_" + code
if "tilesets" in map:
for i in range(len(map["tilesets"])):
if "image" in map["tilesets"][i]:
map["tilesets"][i]["image"] = "../../map/" + map["tilesets"][i]["image"]
return jsonify(map)
abort(404)
if __name__ == "__main__":
app.run()