-
Notifications
You must be signed in to change notification settings - Fork 7
/
__init__.py
59 lines (45 loc) · 1.34 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import asyncio
from fastapi import APIRouter
from loguru import logger
from .client_manager import client_manager
from .crud import db
from .tasks import wait_for_paid_invoices
from .views import nostrrelay_generic_router
from .views_api import nostrrelay_api_router
nostrrelay_ext: APIRouter = APIRouter(prefix="/nostrrelay", tags=["NostrRelay"])
nostrrelay_ext.include_router(nostrrelay_generic_router)
nostrrelay_ext.include_router(nostrrelay_api_router)
nostrrelay_static_files = [
{
"path": "/nostrrelay/static",
"name": "nostrrelay_static",
}
]
nostrrelay_redirect_paths = [
{
"from_path": "/",
"redirect_to_path": "/api/v1/relay-info",
"header_filters": {"accept": "application/nostr+json"},
}
]
scheduled_tasks: list[asyncio.Task] = []
async def nostrrelay_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)
try:
await client_manager.stop()
except Exception as ex:
logger.warning(ex)
def nostrrelay_start():
from lnbits.tasks import create_permanent_unique_task
task = create_permanent_unique_task("ext_nostrrelay", wait_for_paid_invoices)
scheduled_tasks.append(task)
__all__ = [
"db",
"nostrrelay_ext",
"nostrrelay_start",
"nostrrelay_stop",
]