From 8d23141cf05a8984bf37495380fabce88370742b Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 25 May 2024 14:24:37 +0200 Subject: [PATCH] feat: add provisional spaceapi v15 hub endpoint --- config.yml | 10 +++++----- requirements.txt | 18 +++++++++--------- run.py | 4 ++++ src/chaostreff.js | 10 +++++++++- src/index.html | 1 + static-src/.htaccess | 8 +++++--- static-src/spaceapi.json | 19 +++++++++++++++++++ 7 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 static-src/spaceapi.json diff --git a/config.yml b/config.yml index 777dffa..8f3f2ad 100644 --- a/config.yml +++ b/config.yml @@ -10,7 +10,7 @@ jinja_environment: baseurl_abs: https://chaostreff.ch/ baseurl: / - htaccess_spaceapi_proxy: yes + htaccess_spaceapi_proxy: /spaceapi-proxy hackerspaces: @@ -27,7 +27,7 @@ jinja_environment: contact: ml: 'https://lists.chaostreff.ch/postorius/lists/basel.chaostreff.ch/' matrix: 'https://mto.kabelsalat.ch/#/#basel:kabelsalat.ch' - spaceapi: '/spaceapi-proxy/https/spaceapi.kabelsalat.ch/' + spaceapi: 'https://spaceapi.kabelsalat.ch/' - name: 'CCC Zürich' address: 'Neue Hard 12
8005 Zürich' @@ -42,7 +42,7 @@ jinja_environment: contact: ml: 'https://lists.chaostreff.ch/postorius/lists/zuerich.chaostreff.ch/' matrix: 'https://mto.kabelsalat.ch/#/#ccczh:digitale-gesellschaft.ch' - spaceapi: '/spaceapi-proxy/https/api.ccczh.space/api/v13/' + spaceapi: 'https://api.ccczh.space/api/v13/' - name: 'Chaostreff Bern' address: 'Kyburgstrasse 13
3013 Bern' @@ -56,7 +56,7 @@ jinja_environment: web: 'https://chaostreffbern.ch/' contact: ml: 'https://lists.chaostreff.ch/postorius/lists/bern.chaostreff.ch/' - spaceapi: '/spaceapi-proxy/https/www.chaosbern.ch/spaceapi.json' + spaceapi: 'https://www.chaosbern.ch/spaceapi.json' - name: 'Coredump' address: 'Eichwiesstrasse 4
8645 Jona' @@ -69,7 +69,7 @@ jinja_environment: en: 'Every Monday from 20:00' web: 'https://coredump.ch/' contact: {} - spaceapi: '/spaceapi-proxy/https/status.crdmp.ch/' + spaceapi: 'https://status.crdmp.ch/' - name: 'Eastermundingen' address: 'Steinbruchweg 16
3072 Ostermundigen' diff --git a/requirements.txt b/requirements.txt index 5da7df3..4d2a017 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -bottle==0.12.23 -certifi==2022.12.7 -charset-normalizer==2.1.1 -idna==3.4 -Jinja2==3.1.2 -MarkupSafe==2.1.1 -PyYAML==6.0 -requests==2.28.1 -urllib3==1.26.13 +bottle==0.12.25 +certifi==2024.2.2 +charset-normalizer==3.3.2 +idna==3.7 +Jinja2==3.1.4 +MarkupSafe==2.1.5 +PyYAML==6.0.1 +requests==2.32.2 +urllib3==2.2.1 diff --git a/run.py b/run.py index f2ecb59..aed2816 100755 --- a/run.py +++ b/run.py @@ -13,6 +13,10 @@ def spaceapi_proxy(schema, host, path=''): r = requests.get(url) return r.json() +@bottle.get('/spaceapi.json') +def index(): + return bottle.static_file('spaceapi.json', root='out') + @bottle.get('/static/') def static(path): return bottle.static_file(path, root='out/static') diff --git a/src/chaostreff.js b/src/chaostreff.js index a8a7d2e..d93a355 100644 --- a/src/chaostreff.js +++ b/src/chaostreff.js @@ -2,7 +2,15 @@ window.onload = (ev) => { let spaces = [ {% for space in hackerspaces %} - { name: '{{ space.name }}', address: '{{ space.address }}', lat: {{ space.lat }}, lon: {{ space.lon }}, open: '{{ space.open[lang] }}', web: '{{ space.web }}', spaceapi: {% if 'spaceapi' in space %}'{{ space.spaceapi }}'{% else %}null{% endif %} }, + {%- if 'spaceapi' in space %} + {%- if htaccess_spaceapi_proxy %} + {%- set proto, url = space.spaceapi.split('://', 1) %} + {%- set apiurl = htaccess_spaceapi_proxy + '/' + proto + '/' + url %} + {%- else %} + {%- set apiurl = space.spaceapi %} + {%- endif %} + {%- endif %} + { name: '{{ space.name }}', address: '{{ space.address }}', lat: {{ space.lat }}, lon: {{ space.lon }}, open: '{{ space.open[lang] }}', web: '{{ space.web }}', spaceapi: {% if 'spaceapi' in space %}'{{ apiurl }}'{% else %}null{% endif %} }, {% endfor %} ]; diff --git a/src/index.html b/src/index.html index 0c5c442..7c26926 100644 --- a/src/index.html +++ b/src/index.html @@ -3,6 +3,7 @@ + {{ h_pagetitle }} diff --git a/static-src/.htaccess b/static-src/.htaccess index 688ba07..eec0009 100644 --- a/static-src/.htaccess +++ b/static-src/.htaccess @@ -2,12 +2,14 @@ # Language-specific index based on Accept-Language header DirectoryIndex index.var index.html +RewriteEngine on +RewriteRule ^/.well-known/spaceapi.json$ /spaceapi.json [L] {% if htaccess_spaceapi_proxy %} # SpaceAPI proxy service workaround for missing CORS headers -RewriteEngine on {%- for space in hackerspaces %} -{%- if 'spaceapi' in space and space.spaceapi.startswith('/') %} -RewriteRule ^{{ space.spaceapi[1:] }}$ {{ space.spaceapi.split('/', 3)[2] }}://{{ space.spaceapi.split('/', 3)[3] }} [P,L] +{%- if 'spaceapi' in space %} +{%- set proto, url = space.spaceapi.split('://', 1) %} +RewriteRule ^{{ htaccess_spaceapi_proxy }}/{{ proto }}/{{ url }}$ {{ space.spaceapi }} [P,L] {%- endif %} {%- endfor %} {%- endif %} diff --git a/static-src/spaceapi.json b/static-src/spaceapi.json new file mode 100644 index 0000000..d0c5ca8 --- /dev/null +++ b/static-src/spaceapi.json @@ -0,0 +1,19 @@ +{ + "api_compatibility": ["15"], + "space": "chaostreff.ch", + "logo": "https://ccc-ch.ch/images/ccc-ch.png", + "url": "https://chaostreff.ch", + "contact": { + "irc": "ircs://irc.chaostreff.ch/#ccc", + "ml": "swiss-chaos@chaostreff.ch", + "issue_mail": "infra@ccc-basel.ch" + }, + "linked_spaces": [ +{%- for space in hackerspaces | selectattr('spaceapi') %} + { + "endpoint": "{{ space.spaceapi }}", + "website": "{{ space.website }}" + }{% if not loop.last %},{% endif %} +{%- endfor %} + ] +}