genericity: send any text
This commit is contained in:
parent
09cb1566bf
commit
c54e5da19d
2 changed files with 4 additions and 4 deletions
|
@ -30,5 +30,5 @@ docker-compose up -d
|
|||
## Test
|
||||
|
||||
```
|
||||
curl -d '{"name":"toto", "url":"http://radio.localhost/map/#44", "key": "secret"}' wwm.localhost
|
||||
curl -d '{"text":"new contrib from toto: http://radio.localhost/map/#44", "key": "secret"}' wwm.localhost
|
||||
```
|
||||
|
|
6
main.py
6
main.py
|
@ -42,12 +42,12 @@ class WWMBotForwarder(BaseHTTPRequestHandler):
|
|||
"""
|
||||
length = int(self.headers.get('Content-Length'))
|
||||
data = json.loads(self.rfile.read(length).decode())
|
||||
status = 'I need a json dict with name, url, key'
|
||||
if all(key in data for key in ['name', 'url', 'key']):
|
||||
status = 'I need a json dict with text & key'
|
||||
if all(key in data for key in ['text', 'key']):
|
||||
status = 'wrong key'
|
||||
if data['key'] == API_KEY:
|
||||
status = 'OK'
|
||||
self.server.room.send_text(f'Nouvelle demande de {data["name"]}: {data["url"]}')
|
||||
self.server.room.send_text(data['text'])
|
||||
|
||||
self.send_response(200 if status == 'OK' else 401)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
|
|
Loading…
Reference in a new issue