feat: add provisional spaceapi v15 hub endpoint
Some checks failed
/ build (push) Failing after 29s
/ upload (push) Failing after 48s

This commit is contained in:
s3lph 2024-05-25 14:24:37 +02:00
parent 73ae0427bf
commit 8d23141cf0
Signed by: s3lph
GPG key ID: 0AA29A52FB33CFB5
7 changed files with 52 additions and 18 deletions

View file

@ -10,7 +10,7 @@ jinja_environment:
baseurl_abs: https://chaostreff.ch/ baseurl_abs: https://chaostreff.ch/
baseurl: / baseurl: /
htaccess_spaceapi_proxy: yes htaccess_spaceapi_proxy: /spaceapi-proxy
hackerspaces: hackerspaces:
@ -27,7 +27,7 @@ jinja_environment:
contact: contact:
ml: 'https://lists.chaostreff.ch/postorius/lists/basel.chaostreff.ch/' ml: 'https://lists.chaostreff.ch/postorius/lists/basel.chaostreff.ch/'
matrix: 'https://mto.kabelsalat.ch/#/#basel:kabelsalat.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' - name: 'CCC Zürich'
address: 'Neue Hard 12<br/>8005 Zürich' address: 'Neue Hard 12<br/>8005 Zürich'
@ -42,7 +42,7 @@ jinja_environment:
contact: contact:
ml: 'https://lists.chaostreff.ch/postorius/lists/zuerich.chaostreff.ch/' ml: 'https://lists.chaostreff.ch/postorius/lists/zuerich.chaostreff.ch/'
matrix: 'https://mto.kabelsalat.ch/#/#ccczh:digitale-gesellschaft.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' - name: 'Chaostreff Bern'
address: 'Kyburgstrasse 13<br/>3013 Bern' address: 'Kyburgstrasse 13<br/>3013 Bern'
@ -56,7 +56,7 @@ jinja_environment:
web: 'https://chaostreffbern.ch/' web: 'https://chaostreffbern.ch/'
contact: contact:
ml: 'https://lists.chaostreff.ch/postorius/lists/bern.chaostreff.ch/' 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' - name: 'Coredump'
address: 'Eichwiesstrasse 4<br/>8645 Jona' address: 'Eichwiesstrasse 4<br/>8645 Jona'
@ -69,7 +69,7 @@ jinja_environment:
en: 'Every Monday from 20:00' en: 'Every Monday from 20:00'
web: 'https://coredump.ch/' web: 'https://coredump.ch/'
contact: {} contact: {}
spaceapi: '/spaceapi-proxy/https/status.crdmp.ch/' spaceapi: 'https://status.crdmp.ch/'
- name: 'Eastermundingen' - name: 'Eastermundingen'
address: 'Steinbruchweg 16<br/>3072 Ostermundigen' address: 'Steinbruchweg 16<br/>3072 Ostermundigen'

View file

@ -1,9 +1,9 @@
bottle==0.12.23 bottle==0.12.25
certifi==2022.12.7 certifi==2024.2.2
charset-normalizer==2.1.1 charset-normalizer==3.3.2
idna==3.4 idna==3.7
Jinja2==3.1.2 Jinja2==3.1.4
MarkupSafe==2.1.1 MarkupSafe==2.1.5
PyYAML==6.0 PyYAML==6.0.1
requests==2.28.1 requests==2.32.2
urllib3==1.26.13 urllib3==2.2.1

4
run.py
View file

@ -13,6 +13,10 @@ def spaceapi_proxy(schema, host, path=''):
r = requests.get(url) r = requests.get(url)
return r.json() return r.json()
@bottle.get('/spaceapi.json')
def index():
return bottle.static_file('spaceapi.json', root='out')
@bottle.get('/static/<path:path>') @bottle.get('/static/<path:path>')
def static(path): def static(path):
return bottle.static_file(path, root='out/static') return bottle.static_file(path, root='out/static')

View file

@ -2,7 +2,15 @@ window.onload = (ev) => {
let spaces = [ let spaces = [
{% for space in hackerspaces %} {% 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 %} {% endfor %}
]; ];

View file

@ -3,6 +3,7 @@
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="encoding" charset="utf-8" /> <meta http-equiv="encoding" charset="utf-8" />
<meta name="spaceapi" content="{{ baseurl }}/.well-known/spaceapi.json" />
<title>{{ h_pagetitle }}</title> <title>{{ h_pagetitle }}</title>
<link rel="stylesheet" href="{{ baseurl }}static/css/bootstrap.min.css" /> <link rel="stylesheet" href="{{ baseurl }}static/css/bootstrap.min.css" />
<link rel="stylesheet" href="{{ baseurl }}static/css/leaflet.css" /> <link rel="stylesheet" href="{{ baseurl }}static/css/leaflet.css" />

View file

@ -2,12 +2,14 @@
# Language-specific index based on Accept-Language header # Language-specific index based on Accept-Language header
DirectoryIndex index.var index.html DirectoryIndex index.var index.html
RewriteEngine on
RewriteRule ^/.well-known/spaceapi.json$ /spaceapi.json [L]
{% if htaccess_spaceapi_proxy %} {% if htaccess_spaceapi_proxy %}
# SpaceAPI proxy service workaround for missing CORS headers # SpaceAPI proxy service workaround for missing CORS headers
RewriteEngine on
{%- for space in hackerspaces %} {%- for space in hackerspaces %}
{%- if 'spaceapi' in space and space.spaceapi.startswith('/') %} {%- if 'spaceapi' in space %}
RewriteRule ^{{ space.spaceapi[1:] }}$ {{ space.spaceapi.split('/', 3)[2] }}://{{ space.spaceapi.split('/', 3)[3] }} [P,L] {%- set proto, url = space.spaceapi.split('://', 1) %}
RewriteRule ^{{ htaccess_spaceapi_proxy }}/{{ proto }}/{{ url }}$ {{ space.spaceapi }} [P,L]
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}
{%- endif %} {%- endif %}

19
static-src/spaceapi.json Normal file
View file

@ -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 %}
]
}