notify: added support for quick URLs
This commit is contained in:
parent
2380f6694d
commit
583583ae5f
1 changed files with 18 additions and 14 deletions
|
@ -9,14 +9,8 @@ import os
|
||||||
import jq
|
import jq
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# TODO(eyJhb): add the following
|
|
||||||
# - example of bash alias
|
|
||||||
# - jq filter parameter documentation
|
|
||||||
# - jq filter example
|
|
||||||
# - easy way to run it ONLY with curl
|
|
||||||
# - e.g. curl notify.fricloud.dk/notify/<simple_token>/msg
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
app.url_map.strict_slashes = False
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -175,11 +169,16 @@ def index():
|
||||||
<input type="submit" class="btn btn-primary" name="action" value="Set Default Room ID">
|
<input type="submit" class="btn btn-primary" name="action" value="Set Default Room ID">
|
||||||
<hr>
|
<hr>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Token</label>
|
<label class="form-label">Token (dashes are optional)</label>
|
||||||
<input type="text" value="{token}" placeholder="token-not-generated" readonly class="form-control" >
|
<input type="text" value="{token}" placeholder="token-not-generated" readonly class="form-control" onclick="this.select();" >
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" class="btn btn-primary" name="{generate_token_name}" value="{generate_token_value}">
|
<input type="submit" class="btn btn-primary" name="{generate_token_name}" value="{generate_token_value}">
|
||||||
</form>
|
</form>
|
||||||
|
<hr>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">Quick URL</label>
|
||||||
|
<input type="text" value="curl {CONFIG_URL}/notify/{token.replace("-", "")}/mymessage" class="form-control" onclick="this.select();" >
|
||||||
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<p>
|
<p>
|
||||||
This notification service has support for both matrix and email.
|
This notification service has support for both matrix and email.
|
||||||
|
@ -293,18 +292,23 @@ def index():
|
||||||
return tmpl
|
return tmpl
|
||||||
|
|
||||||
|
|
||||||
@app.route("/notify", methods=["GET", "POST"])
|
@app.route("/notify", methods=["GET", "POST"], defaults={"token": "", "body": ""})
|
||||||
def send_notification():
|
@app.route("/notify/<token>", methods=["GET", "POST"], defaults={"body": ""})
|
||||||
|
@app.route("/notify/<token>/<body>", methods=["GET", "POST"])
|
||||||
|
def send_notification(token: str, body: str):
|
||||||
# default to this
|
# default to this
|
||||||
ntype = request.args.get("type", "matrix")
|
ntype = request.args.get("type", "matrix")
|
||||||
title = request.args.get("title", "Notification")
|
title = request.args.get("title", "Notification")
|
||||||
body = request.args.get("body", request.get_data().decode("utf-8"))
|
body = request.args.get("body", request.get_data().decode("utf-8") or body)
|
||||||
if not body:
|
if not body:
|
||||||
body = " "
|
body = " "
|
||||||
token = request.authorization.token or request.authorization.password
|
|
||||||
|
if request.authorization:
|
||||||
|
token = request.authorization.token or request.authorization.password
|
||||||
|
|
||||||
if not token:
|
if not token:
|
||||||
return (
|
return (
|
||||||
"No token found, please either specify with Authorization: Bearer <token> or HTTPBasic",
|
"No token found, please either specify with Authorization: Bearer <token>, HTTPBasic or in the URL path",
|
||||||
401,
|
401,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue