mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-03 06:55:09 -04:00
Implement receive mode webhooks in CLI
This commit is contained in:
parent
f4d71182d6
commit
29970d38ff
3 changed files with 54 additions and 4 deletions
|
@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
import os
|
||||
import tempfile
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from flask import Request, request, render_template, make_response, flash, redirect
|
||||
from werkzeug.utils import secure_filename
|
||||
|
@ -101,6 +102,14 @@ class ReceiveModeWeb:
|
|||
)
|
||||
print(f"\nReceived: {local_path}")
|
||||
|
||||
# Send webhook if configured
|
||||
if (
|
||||
self.web.settings.get("receive", "webhook_url")
|
||||
and not request.upload_error
|
||||
and len(files) > 0
|
||||
):
|
||||
self.send_websocket_notification(f"{len(files)} files uploaded")
|
||||
|
||||
if request.upload_error:
|
||||
self.common.log(
|
||||
"ReceiveModeWeb",
|
||||
|
@ -172,6 +181,22 @@ class ReceiveModeWeb:
|
|||
return self.web.error403()
|
||||
return upload(ajax=True)
|
||||
|
||||
def send_websocket_notification(self, data):
|
||||
self.common.log("ReceiveModeWeb", "send_websocket_notification", data)
|
||||
try:
|
||||
requests.post(
|
||||
self.web.settings.get("receive", "webhook_url"),
|
||||
data=data,
|
||||
timeout=5,
|
||||
proxies=self.web.proxies,
|
||||
)
|
||||
except Exception as e:
|
||||
self.common.log(
|
||||
"ReceiveModeWeb",
|
||||
"send_websocket_notification",
|
||||
f"sending failed: {e}",
|
||||
)
|
||||
|
||||
|
||||
class ReceiveModeWSGIMiddleware(object):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue