|
|
@@ -1,7 +1,29 @@
|
|
|
|
|
|
|
|
"""Bot-side client for the musician's share-list / share-link endpoints.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This module used to hardcode the musician's LAN address and send no auth
|
|
|
|
|
|
|
|
header, which broke the file-share feature in two ways:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* the musician's ``/get_share_list`` and ``/get_share_links`` both call
|
|
|
|
|
|
|
|
``_authorize_request()``, so every request 401'd on any deployment that set
|
|
|
|
|
|
|
|
``CONJURER_API_KEY`` — which the deployment guides tell you to do; and
|
|
|
|
|
|
|
|
* the hardcoded IP ignored ``CONJURER_FILE_SERVICE``, so a musician running on
|
|
|
|
|
|
|
|
another host (the Proxmox/docker split) was unreachable.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It now follows the same convention as the other service clients
|
|
|
|
|
|
|
|
(``music_functions``): address from ``constants``, shared auth headers, and an
|
|
|
|
|
|
|
|
explicit timeout so a wedged musician can't hang the bot.
|
|
|
|
|
|
|
|
"""
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
# Base URL for Flask service
|
|
|
|
from constants import (
|
|
|
|
BASE_URL = 'http://192.168.1.15:5000'
|
|
|
|
FILE_SERVICE_ADDRESS,
|
|
|
|
|
|
|
|
GET_SHARE_LINKS,
|
|
|
|
|
|
|
|
GET_SHARE_LIST,
|
|
|
|
|
|
|
|
service_headers,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SERVICE_HEADERS = service_headers()
|
|
|
|
|
|
|
|
REQUEST_TIMEOUT = 60
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_matches(entries, keywords):
|
|
|
|
def find_matches(entries, keywords):
|
|
|
@@ -12,7 +34,12 @@ def find_matches(entries, keywords):
|
|
|
|
Returns: list of file paths
|
|
|
|
Returns: list of file paths
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
payload = {'entries': entries, 'keywords': keywords}
|
|
|
|
payload = {'entries': entries, 'keywords': keywords}
|
|
|
|
response = requests.post(f"{BASE_URL}/get_share_list", json=payload)
|
|
|
|
response = requests.post(
|
|
|
|
|
|
|
|
f"{FILE_SERVICE_ADDRESS}{GET_SHARE_LIST}",
|
|
|
|
|
|
|
|
json=payload,
|
|
|
|
|
|
|
|
headers=SERVICE_HEADERS,
|
|
|
|
|
|
|
|
timeout=REQUEST_TIMEOUT,
|
|
|
|
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
|
|
|
data = response.json()
|
|
|
|
return data.get('files', [])
|
|
|
|
return data.get('files', [])
|
|
|
@@ -25,7 +52,12 @@ def publish(file_paths):
|
|
|
|
Returns: list of published URLs
|
|
|
|
Returns: list of published URLs
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
payload = {'file_paths': file_paths}
|
|
|
|
payload = {'file_paths': file_paths}
|
|
|
|
response = requests.post(f"{BASE_URL}/get_share_links", json=payload)
|
|
|
|
response = requests.post(
|
|
|
|
|
|
|
|
f"{FILE_SERVICE_ADDRESS}{GET_SHARE_LINKS}",
|
|
|
|
|
|
|
|
json=payload,
|
|
|
|
|
|
|
|
headers=SERVICE_HEADERS,
|
|
|
|
|
|
|
|
timeout=REQUEST_TIMEOUT,
|
|
|
|
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
response.raise_for_status()
|
|
|
|
data = response.json()
|
|
|
|
data = response.json()
|
|
|
|
return data.get('links', [])
|
|
|
|
return data.get('links', [])
|
|
|
|