diff --git a/lnbits/core/templates/core/install.html b/lnbits/core/templates/core/install.html index ac3a0392..6a109518 100644 --- a/lnbits/core/templates/core/install.html +++ b/lnbits/core/templates/core/install.html @@ -62,8 +62,8 @@
@@ -114,7 +114,9 @@ style="font-size: 9px; height: 34px" > {{ extension.shortDescription }} +
+ {{ extension }} {% endraw %}
diff --git a/lnbits/extensions/copilot/README.md b/lnbits/extensions/copilot/README.md deleted file mode 100644 index 323aeddc..00000000 --- a/lnbits/extensions/copilot/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# StreamerCopilot - -Tool to help streamers accept sats for tips diff --git a/lnbits/extensions/copilot/__init__.py b/lnbits/extensions/copilot/__init__.py deleted file mode 100644 index 806801ce..00000000 --- a/lnbits/extensions/copilot/__init__.py +++ /dev/null @@ -1,34 +0,0 @@ -import asyncio - -from fastapi import APIRouter -from fastapi.staticfiles import StaticFiles - -from lnbits.db import Database -from lnbits.helpers import template_renderer -from lnbits.tasks import catch_everything_and_restart - -db = Database("ext_copilot") - -copilot_static_files = [ - { - "path": "/copilot/static", - "app": StaticFiles(packages=[("lnbits", "extensions/copilot/static")]), - "name": "copilot_static", - } -] -copilot_ext: APIRouter = APIRouter(prefix="/copilot", tags=["copilot"]) - - -def copilot_renderer(): - return template_renderer(["lnbits/extensions/copilot/templates"]) - - -from .lnurl import * # noqa -from .tasks import wait_for_paid_invoices -from .views import * # noqa -from .views_api import * # noqa - - -def copilot_start(): - loop = asyncio.get_event_loop() - loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) diff --git a/lnbits/extensions/copilot/config.json b/lnbits/extensions/copilot/config.json deleted file mode 100644 index fc754999..00000000 --- a/lnbits/extensions/copilot/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "Streamer Copilot", - "short_description": "Video tips/animations/webhooks", - "tile": "/copilot/static/bitcoin-streaming.png", - "contributors": [ - "arcbtc" - ] -} diff --git a/lnbits/extensions/copilot/crud.py b/lnbits/extensions/copilot/crud.py deleted file mode 100644 index 5ecb5cd4..00000000 --- a/lnbits/extensions/copilot/crud.py +++ /dev/null @@ -1,97 +0,0 @@ -from typing import List, Optional, Union - -from lnbits.helpers import urlsafe_short_hash - -from . import db -from .models import Copilots, CreateCopilotData - -###############COPILOTS########################## - - -async def create_copilot( - data: CreateCopilotData, inkey: Optional[str] = "" -) -> Optional[Copilots]: - copilot_id = urlsafe_short_hash() - await db.execute( - """ - INSERT INTO copilot.newer_copilots ( - id, - "user", - lnurl_toggle, - wallet, - title, - animation1, - animation2, - animation3, - animation1threshold, - animation2threshold, - animation3threshold, - animation1webhook, - animation2webhook, - animation3webhook, - lnurl_title, - show_message, - show_ack, - show_price, - fullscreen_cam, - iframe_url, - amount_made - ) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) - """, - ( - copilot_id, - data.user, - int(data.lnurl_toggle), - data.wallet, - data.title, - data.animation1, - data.animation2, - data.animation3, - data.animation1threshold, - data.animation2threshold, - data.animation3threshold, - data.animation1webhook, - data.animation2webhook, - data.animation3webhook, - data.lnurl_title, - int(data.show_message), - int(data.show_ack), - data.show_price, - 0, - None, - 0, - ), - ) - return await get_copilot(copilot_id) - - -async def update_copilot( - data: CreateCopilotData, copilot_id: str -) -> Optional[Copilots]: - q = ", ".join([f"{field[0]} = ?" for field in data]) - items = [f"{field[1]}" for field in data] - items.append(copilot_id) - await db.execute(f"UPDATE copilot.newer_copilots SET {q} WHERE id = ?", (items,)) - row = await db.fetchone( - "SELECT * FROM copilot.newer_copilots WHERE id = ?", (copilot_id,) - ) - return Copilots(**row) if row else None - - -async def get_copilot(copilot_id: str) -> Optional[Copilots]: - row = await db.fetchone( - "SELECT * FROM copilot.newer_copilots WHERE id = ?", (copilot_id,) - ) - return Copilots(**row) if row else None - - -async def get_copilots(user: str) -> List[Copilots]: - rows = await db.fetchall( - 'SELECT * FROM copilot.newer_copilots WHERE "user" = ?', (user,) - ) - return [Copilots(**row) for row in rows] - - -async def delete_copilot(copilot_id: str) -> None: - await db.execute("DELETE FROM copilot.newer_copilots WHERE id = ?", (copilot_id,)) diff --git a/lnbits/extensions/copilot/lnurl.py b/lnbits/extensions/copilot/lnurl.py deleted file mode 100644 index b0bc83bc..00000000 --- a/lnbits/extensions/copilot/lnurl.py +++ /dev/null @@ -1,82 +0,0 @@ -import hashlib -import json -from http import HTTPStatus - -from fastapi import Request -from fastapi.param_functions import Query -from lnurl.types import LnurlPayMetadata -from starlette.exceptions import HTTPException -from starlette.responses import HTMLResponse - -from lnbits.core.services import create_invoice - -from . import copilot_ext -from .crud import get_copilot - - -@copilot_ext.get( - "/lnurl/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_response" -) -async def lnurl_response(req: Request, cp_id: str = Query(None)): - cp = await get_copilot(cp_id) - if not cp: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" - ) - - payResponse = { - "tag": "payRequest", - "callback": req.url_for("copilot.lnurl_callback", cp_id=cp_id), - "metadata": LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])), - "maxSendable": 50000000, - "minSendable": 10000, - } - - if cp.show_message: - payResponse["commentAllowed"] = 300 - return json.dumps(payResponse) - - -@copilot_ext.get( - "/lnurl/cb/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_callback" -) -async def lnurl_callback( - cp_id: str = Query(None), amount: str = Query(None), comment: str = Query(None) -): - cp = await get_copilot(cp_id) - if not cp: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" - ) - amount_received = int(amount) - - if amount_received < 10000: - raise HTTPException( - status_code=HTTPStatus.FORBIDDEN, - detail="Amount {round(amount_received / 1000)} is smaller than minimum 10 sats.", - ) - elif amount_received / 1000 > 10000000: - raise HTTPException( - status_code=HTTPStatus.FORBIDDEN, - detail="Amount {round(amount_received / 1000)} is greater than maximum 50000.", - ) - comment = "" - if comment: - if len(comment or "") > 300: - raise HTTPException( - status_code=HTTPStatus.FORBIDDEN, - detail="Got a comment with {len(comment)} characters, but can only accept 300", - ) - if len(comment) < 1: - comment = "none" - _, payment_request = await create_invoice( - wallet_id=cp.wallet, - amount=int(amount_received / 1000), - memo=cp.lnurl_title, - unhashed_description=( - LnurlPayMetadata(json.dumps([["text/plain", str(cp.lnurl_title)]])) - ).encode(), - extra={"tag": "copilot", "copilotid": cp.id, "comment": comment}, - ) - payResponse = {"pr": payment_request, "routes": []} - return json.dumps(payResponse) diff --git a/lnbits/extensions/copilot/migrations.py b/lnbits/extensions/copilot/migrations.py deleted file mode 100644 index b1c16dcc..00000000 --- a/lnbits/extensions/copilot/migrations.py +++ /dev/null @@ -1,79 +0,0 @@ -async def m001_initial(db): - """ - Initial copilot table. - """ - - await db.execute( - f""" - CREATE TABLE copilot.copilots ( - id TEXT NOT NULL PRIMARY KEY, - "user" TEXT, - title TEXT, - lnurl_toggle INTEGER, - wallet TEXT, - animation1 TEXT, - animation2 TEXT, - animation3 TEXT, - animation1threshold INTEGER, - animation2threshold INTEGER, - animation3threshold INTEGER, - animation1webhook TEXT, - animation2webhook TEXT, - animation3webhook TEXT, - lnurl_title TEXT, - show_message INTEGER, - show_ack INTEGER, - show_price INTEGER, - amount_made INTEGER, - fullscreen_cam INTEGER, - iframe_url TEXT, - timestamp TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} - ); - """ - ) - - -async def m002_fix_data_types(db): - """ - Fix data types. - """ - - if db.type != "SQLITE": - await db.execute( - "ALTER TABLE copilot.copilots ALTER COLUMN show_price TYPE TEXT;" - ) - - -async def m003_fix_data_types(db): - await db.execute( - f""" - CREATE TABLE copilot.newer_copilots ( - id TEXT NOT NULL PRIMARY KEY, - "user" TEXT, - title TEXT, - lnurl_toggle INTEGER, - wallet TEXT, - animation1 TEXT, - animation2 TEXT, - animation3 TEXT, - animation1threshold INTEGER, - animation2threshold INTEGER, - animation3threshold INTEGER, - animation1webhook TEXT, - animation2webhook TEXT, - animation3webhook TEXT, - lnurl_title TEXT, - show_message INTEGER, - show_ack INTEGER, - show_price TEXT, - amount_made INTEGER, - fullscreen_cam INTEGER, - iframe_url TEXT, - timestamp TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} - ); - """ - ) - - await db.execute( - "INSERT INTO copilot.newer_copilots SELECT * FROM copilot.copilots" - ) diff --git a/lnbits/extensions/copilot/models.py b/lnbits/extensions/copilot/models.py deleted file mode 100644 index 7ca2fc96..00000000 --- a/lnbits/extensions/copilot/models.py +++ /dev/null @@ -1,66 +0,0 @@ -import json -from sqlite3 import Row -from typing import Dict, Optional -from urllib.parse import ParseResult, parse_qs, urlencode, urlparse, urlunparse - -from fastapi.param_functions import Query -from lnurl.types import LnurlPayMetadata -from pydantic import BaseModel -from starlette.requests import Request - -from lnbits.lnurl import encode as lnurl_encode - - -class CreateCopilotData(BaseModel): - user: str = Query(None) - title: str = Query(None) - lnurl_toggle: int = Query(0) - wallet: str = Query(None) - animation1: str = Query(None) - animation2: str = Query(None) - animation3: str = Query(None) - animation1threshold: int = Query(None) - animation2threshold: int = Query(None) - animation3threshold: int = Query(None) - animation1webhook: str = Query(None) - animation2webhook: str = Query(None) - animation3webhook: str = Query(None) - lnurl_title: str = Query(None) - show_message: int = Query(0) - show_ack: int = Query(0) - show_price: str = Query(None) - amount_made: int = Query(0) - timestamp: int = Query(0) - fullscreen_cam: int = Query(0) - iframe_url: str = Query(None) - success_url: str = Query(None) - - -class Copilots(BaseModel): - id: str - user: str = Query(None) - title: str = Query(None) - lnurl_toggle: int = Query(0) - wallet: str = Query(None) - animation1: str = Query(None) - animation2: str = Query(None) - animation3: str = Query(None) - animation1threshold: int = Query(None) - animation2threshold: int = Query(None) - animation3threshold: int = Query(None) - animation1webhook: str = Query(None) - animation2webhook: str = Query(None) - animation3webhook: str = Query(None) - lnurl_title: str = Query(None) - show_message: int = Query(0) - show_ack: int = Query(0) - show_price: str = Query(None) - amount_made: int = Query(0) - timestamp: int = Query(0) - fullscreen_cam: int = Query(0) - iframe_url: str = Query(None) - success_url: str = Query(None) - - def lnurl(self, req: Request) -> str: - url = req.url_for("copilot.lnurl_response", cp_id=self.id) - return lnurl_encode(url) diff --git a/lnbits/extensions/copilot/static/bitcoin-streaming.png b/lnbits/extensions/copilot/static/bitcoin-streaming.png deleted file mode 100644 index 1022baf2..00000000 Binary files a/lnbits/extensions/copilot/static/bitcoin-streaming.png and /dev/null differ diff --git a/lnbits/extensions/copilot/static/bitcoin.gif b/lnbits/extensions/copilot/static/bitcoin.gif deleted file mode 100644 index ef8c2ecd..00000000 Binary files a/lnbits/extensions/copilot/static/bitcoin.gif and /dev/null differ diff --git a/lnbits/extensions/copilot/static/confetti.gif b/lnbits/extensions/copilot/static/confetti.gif deleted file mode 100644 index a3fec971..00000000 Binary files a/lnbits/extensions/copilot/static/confetti.gif and /dev/null differ diff --git a/lnbits/extensions/copilot/static/face.gif b/lnbits/extensions/copilot/static/face.gif deleted file mode 100644 index 3e70d779..00000000 Binary files a/lnbits/extensions/copilot/static/face.gif and /dev/null differ diff --git a/lnbits/extensions/copilot/static/lnurl.png b/lnbits/extensions/copilot/static/lnurl.png deleted file mode 100644 index ad2c9715..00000000 Binary files a/lnbits/extensions/copilot/static/lnurl.png and /dev/null differ diff --git a/lnbits/extensions/copilot/static/martijn.gif b/lnbits/extensions/copilot/static/martijn.gif deleted file mode 100644 index e410677d..00000000 Binary files a/lnbits/extensions/copilot/static/martijn.gif and /dev/null differ diff --git a/lnbits/extensions/copilot/static/rick.gif b/lnbits/extensions/copilot/static/rick.gif deleted file mode 100644 index c36c7e19..00000000 Binary files a/lnbits/extensions/copilot/static/rick.gif and /dev/null differ diff --git a/lnbits/extensions/copilot/static/rocket.gif b/lnbits/extensions/copilot/static/rocket.gif deleted file mode 100644 index 6f19597d..00000000 Binary files a/lnbits/extensions/copilot/static/rocket.gif and /dev/null differ diff --git a/lnbits/extensions/copilot/tasks.py b/lnbits/extensions/copilot/tasks.py deleted file mode 100644 index 4975b5a3..00000000 --- a/lnbits/extensions/copilot/tasks.py +++ /dev/null @@ -1,84 +0,0 @@ -import asyncio -import json -from http import HTTPStatus - -import httpx -from starlette.exceptions import HTTPException - -from lnbits.core import db as core_db -from lnbits.core.models import Payment -from lnbits.core.services import websocketUpdater -from lnbits.helpers import get_current_extension_name -from lnbits.tasks import register_invoice_listener - -from .crud import get_copilot - - -async def wait_for_paid_invoices(): - invoice_queue = asyncio.Queue() - register_invoice_listener(invoice_queue, get_current_extension_name()) - - while True: - payment = await invoice_queue.get() - await on_invoice_paid(payment) - - -async def on_invoice_paid(payment: Payment) -> None: - if payment.extra.get("tag") != "copilot": - # not an copilot invoice - return - - webhook = None - data = None - copilot = await get_copilot(payment.extra.get("copilotid", -1)) - - if not copilot: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Copilot does not exist" - ) - if copilot.animation1threshold: - if int(payment.amount / 1000) >= copilot.animation1threshold: - data = copilot.animation1 - webhook = copilot.animation1webhook - if copilot.animation2threshold: - if int(payment.amount / 1000) >= copilot.animation2threshold: - data = copilot.animation2 - webhook = copilot.animation1webhook - if copilot.animation3threshold: - if int(payment.amount / 1000) >= copilot.animation3threshold: - data = copilot.animation3 - webhook = copilot.animation1webhook - if webhook: - async with httpx.AsyncClient() as client: - try: - r = await client.post( - webhook, - json={ - "payment_hash": payment.payment_hash, - "payment_request": payment.bolt11, - "amount": payment.amount, - "comment": payment.extra.get("comment"), - }, - timeout=40, - ) - await mark_webhook_sent(payment, r.status_code) - except (httpx.ConnectError, httpx.RequestError): - await mark_webhook_sent(payment, -1) - if payment.extra.get("comment"): - await websocketUpdater( - copilot.id, str(data) + "-" + str(payment.extra.get("comment")) - ) - - await websocketUpdater(copilot.id, str(data) + "-none") - - -async def mark_webhook_sent(payment: Payment, status: int) -> None: - if payment.extra: - payment.extra["wh_status"] = status - await core_db.execute( - """ - UPDATE apipayments SET extra = ? - WHERE hash = ? - """, - (json.dumps(payment.extra), payment.payment_hash), - ) diff --git a/lnbits/extensions/copilot/templates/copilot/_api_docs.html b/lnbits/extensions/copilot/templates/copilot/_api_docs.html deleted file mode 100644 index 72edc176..00000000 --- a/lnbits/extensions/copilot/templates/copilot/_api_docs.html +++ /dev/null @@ -1,178 +0,0 @@ - - -

- StreamerCopilot: get tips via static QR (lnurl-pay) and show an - animation
- - Created by, - Ben Arc -

-
- - - - - - POST /copilot/api/v1/copilot -
Headers
- {"X-Api-Key": <admin_key>}
-
- Body (application/json) -
-
- Returns 200 OK (application/json) -
- [<copilot_object>, ...] -
Curl example
- curl -X POST {{ request.base_url }}copilot/api/v1/copilot -d - '{"title": <string>, "animation": <string>, - "show_message":<string>, "amount": <integer>, - "lnurl_title": <string>}' -H "Content-type: application/json" - -H "X-Api-Key: {{user.wallets[0].adminkey }}" - -
-
-
- - - - PUT - /copilot/api/v1/copilot/<copilot_id> -
Headers
- {"X-Api-Key": <admin_key>}
-
- Body (application/json) -
-
- Returns 200 OK (application/json) -
- [<copilot_object>, ...] -
Curl example
- curl -X POST {{ request.base_url - }}copilot/api/v1/copilot/<copilot_id> -d '{"title": - <string>, "animation": <string>, - "show_message":<string>, "amount": <integer>, - "lnurl_title": <string>}' -H "Content-type: application/json" - -H "X-Api-Key: {{user.wallets[0].adminkey }}" - -
-
-
- - - - - GET - /copilot/api/v1/copilot/<copilot_id> -
Headers
- {"X-Api-Key": <invoice_key>}
-
- Body (application/json) -
-
- Returns 200 OK (application/json) -
- [<copilot_object>, ...] -
Curl example
- curl -X GET {{ request.base_url - }}copilot/api/v1/copilot/<copilot_id> -H "X-Api-Key: {{ - user.wallets[0].inkey }}" - -
-
-
- - - - GET /copilot/api/v1/copilots -
Headers
- {"X-Api-Key": <invoice_key>}
-
- Body (application/json) -
-
- Returns 200 OK (application/json) -
- [<copilot_object>, ...] -
Curl example
- curl -X GET {{ request.base_url }}copilot/api/v1/copilots -H - "X-Api-Key: {{ user.wallets[0].inkey }}" - -
-
-
- - - - DELETE - /copilot/api/v1/copilot/<copilot_id> -
Headers
- {"X-Api-Key": <admin_key>}
-
Returns 204 NO CONTENT
- -
Curl example
- curl -X DELETE {{ request.base_url - }}copilot/api/v1/copilot/<copilot_id> -H "X-Api-Key: {{ - user.wallets[0].adminkey }}" - -
-
-
- - - - GET - /api/v1/copilot/ws/<copilot_id>/<comment>/<data> -
Headers
- {"X-Api-Key": <admin_key>}
-
Returns 200
- -
Curl example
- curl -X GET {{ request.base_url - }}copilot/api/v1/copilot/ws/<string, copilot_id>/<string, - comment>/<string, gif name> -H "X-Api-Key: {{ - user.wallets[0].adminkey }}" - -
-
-
-
-
diff --git a/lnbits/extensions/copilot/templates/copilot/compose.html b/lnbits/extensions/copilot/templates/copilot/compose.html deleted file mode 100644 index 2ec4c4f7..00000000 --- a/lnbits/extensions/copilot/templates/copilot/compose.html +++ /dev/null @@ -1,305 +0,0 @@ -{% extends "public.html" %} {% block page %} - - - - -
-
- -
- {% raw %}{{ copilot.lnurl_title }}{% endraw %} -
-
-
- -

- {% raw %}{{ price }}{% endraw %} -

- -

- Powered by LNbits/StreamerCopilot -

-
-{% endblock %} {% block scripts %} - - - - -{% endblock %} diff --git a/lnbits/extensions/copilot/templates/copilot/index.html b/lnbits/extensions/copilot/templates/copilot/index.html deleted file mode 100644 index 95c08bae..00000000 --- a/lnbits/extensions/copilot/templates/copilot/index.html +++ /dev/null @@ -1,660 +0,0 @@ -{% extends "base.html" %} {% from "macros.jinja" import window_vars with context -%} {% block page %} - -
-
- - - {% raw %} - New copilot instance - - - - - - -
-
-
Copilots
-
- -
- - - - Export to CSV -
-
- - - - - {% endraw %} - -
-
-
- -
- - -
- {{SITE_TITLE}} StreamCopilot Extension -
-
- - - {% include "copilot/_api_docs.html" %} - -
-
- - - - -
- -
- -
- - - - - - - -
-
- -
- -
- - -
-
- - -
-
-
-
-
- - - - -
-
- -
- -
- - -
-
- - -
-
-
-
-
- - - - -
-
- -
- -
- - -
-
- - -
-
-
-
-
- - - -
- -
- -
-
-
- -
-
-
- Update Copilot - Create Copilot - Cancel -
-
-
-
-
-{% endblock %} {% block scripts %} {{ window_vars(user) }} - -{% endblock %} diff --git a/lnbits/extensions/copilot/templates/copilot/panel.html b/lnbits/extensions/copilot/templates/copilot/panel.html deleted file mode 100644 index f17bf34c..00000000 --- a/lnbits/extensions/copilot/templates/copilot/panel.html +++ /dev/null @@ -1,156 +0,0 @@ -{% extends "public.html" %} {% block page %} -
- -
-
-
- -
-
-
-
- Title: {% raw %} {{ copilot.title }} {% endraw %} -
-
- -
-
-
- - -
-
-
-
- -
-
- -
-
- -
-
-
-
- -
-
- -
-
- -
-
-
-
-
-
- -{% endblock %} {% block scripts %} - -{% endblock %} diff --git a/lnbits/extensions/copilot/views.py b/lnbits/extensions/copilot/views.py deleted file mode 100644 index ff69dfba..00000000 --- a/lnbits/extensions/copilot/views.py +++ /dev/null @@ -1,33 +0,0 @@ -from typing import List - -from fastapi import Depends, Request -from fastapi.templating import Jinja2Templates -from starlette.responses import HTMLResponse - -from lnbits.core.models import User -from lnbits.decorators import check_user_exists - -from . import copilot_ext, copilot_renderer - -templates = Jinja2Templates(directory="templates") - - -@copilot_ext.get("/", response_class=HTMLResponse) -async def index(request: Request, user: User = Depends(check_user_exists)): - return copilot_renderer().TemplateResponse( - "copilot/index.html", {"request": request, "user": user.dict()} - ) - - -@copilot_ext.get("/cp/", response_class=HTMLResponse) -async def compose(request: Request): - return copilot_renderer().TemplateResponse( - "copilot/compose.html", {"request": request} - ) - - -@copilot_ext.get("/pn/", response_class=HTMLResponse) -async def panel(request: Request): - return copilot_renderer().TemplateResponse( - "copilot/panel.html", {"request": request} - ) diff --git a/lnbits/extensions/copilot/views_api.py b/lnbits/extensions/copilot/views_api.py deleted file mode 100644 index f0621202..00000000 --- a/lnbits/extensions/copilot/views_api.py +++ /dev/null @@ -1,94 +0,0 @@ -from http import HTTPStatus - -from fastapi import Depends, Query, Request -from starlette.exceptions import HTTPException - -from lnbits.core.services import websocketUpdater -from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key - -from . import copilot_ext -from .crud import ( - create_copilot, - delete_copilot, - get_copilot, - get_copilots, - update_copilot, -) -from .models import CreateCopilotData - -#######################COPILOT########################## - - -@copilot_ext.get("/api/v1/copilot") -async def api_copilots_retrieve(wallet: WalletTypeInfo = Depends(get_key_type)): - wallet_user = wallet.wallet.user - copilots = [copilot.dict() for copilot in await get_copilots(wallet_user)] - try: - return copilots - except: - raise HTTPException(status_code=HTTPStatus.NO_CONTENT, detail="No copilots") - - -@copilot_ext.get("/api/v1/copilot/{copilot_id}") -async def api_copilot_retrieve( - req: Request, - copilot_id: str = Query(None), - wallet: WalletTypeInfo = Depends(get_key_type), -): - copilot = await get_copilot(copilot_id) - if not copilot: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Copilot not found" - ) - if not copilot.lnurl_toggle: - return copilot.dict() - return {**copilot.dict(), **{"lnurl": copilot.lnurl(req)}} - - -@copilot_ext.post("/api/v1/copilot") -@copilot_ext.put("/api/v1/copilot/{juke_id}") -async def api_copilot_create_or_update( - data: CreateCopilotData, - copilot_id: str = Query(None), - wallet: WalletTypeInfo = Depends(require_admin_key), -): - data.user = wallet.wallet.user - data.wallet = wallet.wallet.id - if copilot_id: - copilot = await update_copilot(data, copilot_id=copilot_id) - else: - copilot = await create_copilot(data, inkey=wallet.wallet.inkey) - return copilot - - -@copilot_ext.delete("/api/v1/copilot/{copilot_id}") -async def api_copilot_delete( - copilot_id: str = Query(None), - wallet: WalletTypeInfo = Depends(require_admin_key), -): - copilot = await get_copilot(copilot_id) - - if not copilot: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Copilot does not exist" - ) - - await delete_copilot(copilot_id) - - return "", HTTPStatus.NO_CONTENT - - -@copilot_ext.get("/api/v1/copilot/ws/{copilot_id}/{comment}/{data}") -async def api_copilot_ws_relay( - copilot_id: str = Query(None), comment: str = Query(None), data: str = Query(None) -): - copilot = await get_copilot(copilot_id) - if not copilot: - raise HTTPException( - status_code=HTTPStatus.NOT_FOUND, detail="Copilot does not exist" - ) - try: - await websocketUpdater(copilot_id, str(data) + "-" + str(comment)) - except: - raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your copilot") - return ""