document and add manage commands
This commit is contained in:
parent
8bb5d7c2cf
commit
0620b67bd3
42
README.md
42
README.md
|
@ -24,6 +24,46 @@ Run the relay setup to configure it
|
|||
|
||||
~/.local/share/venv/uncia/bin/python -m uncia.manage setup
|
||||
|
||||
### Running
|
||||
## Running
|
||||
|
||||
You can run either `make run` or `~/.local/share/venv/uncia/bin/python -m uncia`
|
||||
|
||||
## Manage Commands
|
||||
|
||||
There are a number of commands that can be ran to manage various parts of the relay. Some require the relay to be running in order to work.
|
||||
|
||||
~/.local/share/venv/uncia/bin/python -m uncia.manage <command> [*args]
|
||||
|
||||
### Command List
|
||||
|
||||
get current settings
|
||||
|
||||
config
|
||||
|
||||
change a setting
|
||||
|
||||
set <key> <value>
|
||||
|
||||
list current requests
|
||||
|
||||
request
|
||||
|
||||
accept a request (relay has to be running)
|
||||
|
||||
accept [actor, inbox, or domain]
|
||||
|
||||
reject a request (relay has to be running)
|
||||
|
||||
reject [actor, inbox, or domain]
|
||||
|
||||
list all subscribed instances
|
||||
|
||||
list
|
||||
|
||||
add an instance to the database (relay has to be running)
|
||||
|
||||
add [actor or domain]
|
||||
|
||||
remove an instance from the database
|
||||
|
||||
remove [actor, inbox, or domain]
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import json
|
||||
|
||||
from functools import wraps
|
||||
from izzylib import HttpRequestsClient, LruCache, logging
|
||||
|
||||
|
@ -65,10 +67,16 @@ def fetch_auth(url):
|
|||
headers = {'accept': 'application/activity+json'}
|
||||
)
|
||||
|
||||
return response.json
|
||||
try:
|
||||
return response.json
|
||||
except json.decoder.JSONDecodeError:
|
||||
return {}
|
||||
|
||||
|
||||
def get_inbox(actor):
|
||||
if not actor:
|
||||
return
|
||||
|
||||
try:
|
||||
return actor.endpoints.sharedInbox
|
||||
except:
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import sys
|
||||
|
||||
from izzylib import logging
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from . import __version__
|
||||
from .database import db
|
||||
from .functions import fetch_actor, get_inbox
|
||||
from .messages import Message
|
||||
|
||||
|
||||
|
@ -80,6 +82,9 @@ python3 -m uncia.manage config [key] [value]:
|
|||
if row.followid:
|
||||
instances.append(row.domain)
|
||||
|
||||
if not instances:
|
||||
return 'No requests'
|
||||
|
||||
text = 'Awaiting Requests:\n'
|
||||
text += '\n'.join([f'- {domain}' for domain in instances])
|
||||
return text
|
||||
|
@ -106,10 +111,43 @@ python3 -m uncia.manage config [key] [value]:
|
|||
def cmd_accept(self, url):
|
||||
cmd_request('accept', url)
|
||||
|
||||
|
||||
def cmd_reject(self, url):
|
||||
cmd_request('reject', url)
|
||||
|
||||
|
||||
def cmd_list(self):
|
||||
instance_list = 'Connected Instances:\n'
|
||||
|
||||
with db.session as s:
|
||||
instance_list += '\n'.join([f'- {domain}' for domain in s.get.instance_list('domain')])
|
||||
|
||||
return instance_list
|
||||
|
||||
|
||||
def cmd_add(self, actor_url):
|
||||
if not actor_url.startswith('https://'):
|
||||
actor_url = f'https://{actor_url}/actor'
|
||||
|
||||
actor = fetch_actor(actor_url)
|
||||
inbox = get_inbox(actor)
|
||||
|
||||
if not actor:
|
||||
return f'Failed to fetch actor at {actor_url}'
|
||||
|
||||
with db.session as s:
|
||||
if s.get.instance(actor_url):
|
||||
return f'Instance already added to the relay'
|
||||
|
||||
instance = s.put.instance(inbox, actor_url)
|
||||
|
||||
if instance:
|
||||
return f'Added {instance.domain} to the relay'
|
||||
|
||||
else:
|
||||
return f'Failed to add {actor_url} to the relay'
|
||||
|
||||
|
||||
def cmd_remove(self, data):
|
||||
with db.session as s:
|
||||
if s.delete.instance(data):
|
||||
|
|
Loading…
Reference in a new issue