mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-23 06:35:23 +01:00
converted models
This commit is contained in:
parent
c749b7d11e
commit
aeee469c64
3 changed files with 100 additions and 33 deletions
|
@ -1,17 +1,44 @@
|
||||||
from quart import Blueprint
|
import asyncio
|
||||||
|
|
||||||
|
from fastapi import APIRouter, FastAPI
|
||||||
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
from starlette.routing import Mount
|
||||||
|
|
||||||
from lnbits.db import Database
|
from lnbits.db import Database
|
||||||
|
from lnbits.helpers import template_renderer
|
||||||
|
from lnbits.tasks import catch_everything_and_restart
|
||||||
|
|
||||||
db = Database("ext_copilot")
|
db = Database("ext_copilot")
|
||||||
|
|
||||||
copilot_ext: Blueprint = Blueprint(
|
|
||||||
"copilot", __name__, static_folder="static", template_folder="templates"
|
copilot_static_files = [
|
||||||
|
{
|
||||||
|
"path": "/copilot/static",
|
||||||
|
"app": StaticFiles(directory="lnbits/extensions/copilot/static"),
|
||||||
|
"name": "copilot_static",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
copilot_ext: APIRouter = APIRouter(
|
||||||
|
prefix="/copilot",
|
||||||
|
tags=["copilot"]
|
||||||
|
# "lnurlp", __name__, static_folder="static", template_folder="templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def copilot_renderer():
|
||||||
|
return template_renderer(
|
||||||
|
[
|
||||||
|
"lnbits/extensions/copilot/templates",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
from .views_api import * # noqa
|
from .views_api import * # noqa
|
||||||
from .views import * # noqa
|
from .views import * # noqa
|
||||||
|
from .tasks import wait_for_paid_invoices
|
||||||
from .lnurl import * # noqa
|
from .lnurl import * # noqa
|
||||||
from .tasks import register_listeners
|
|
||||||
|
|
||||||
from lnbits.tasks import record_async
|
|
||||||
|
|
||||||
copilot_ext.record(record_async(register_listeners))
|
def copilot_start():
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
loop.create_task(catch_everything_and_restart(wait_for_paid_invoices))
|
||||||
|
|
|
@ -1,13 +1,41 @@
|
||||||
from sqlite3 import Row
|
import json
|
||||||
from typing import NamedTuple
|
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
|
||||||
import time
|
from starlette.requests import Request
|
||||||
from quart import url_for
|
from fastapi.param_functions import Query
|
||||||
from lnurl import Lnurl, encode as lnurl_encode # type: ignore
|
from typing import Optional, Dict
|
||||||
|
from lnbits.lnurl import encode as lnurl_encode # type: ignore
|
||||||
from lnurl.types import LnurlPayMetadata # type: ignore
|
from lnurl.types import LnurlPayMetadata # type: ignore
|
||||||
from lnurl.models import LnurlPaySuccessAction, UrlAction # type: ignore
|
from sqlite3 import Row
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class Copilots(NamedTuple):
|
class CreateCopilots(BaseModel):
|
||||||
|
id: str = Query(None)
|
||||||
|
user: str = Query(None)
|
||||||
|
title: str = Query(None)
|
||||||
|
lnurl_toggle: int = Query(None)
|
||||||
|
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(None)
|
||||||
|
show_ack: int = Query(None)
|
||||||
|
show_price: int = Query(None)
|
||||||
|
amount_made: int = Query(None)
|
||||||
|
timestamp: int = Query(None)
|
||||||
|
fullscreen_cam: int = Query(None)
|
||||||
|
iframe_url: str = Query(None)
|
||||||
|
success_url: str = Query(None)
|
||||||
|
|
||||||
|
|
||||||
|
class Copilots(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
user: str
|
user: str
|
||||||
title: str
|
title: str
|
||||||
|
@ -35,7 +63,6 @@ class Copilots(NamedTuple):
|
||||||
def from_row(cls, row: Row) -> "Copilots":
|
def from_row(cls, row: Row) -> "Copilots":
|
||||||
return cls(**dict(row))
|
return cls(**dict(row))
|
||||||
|
|
||||||
@property
|
def lnurl(self, req: Request) -> str:
|
||||||
def lnurl(self) -> Lnurl:
|
url = req.url_for("copilot.lnurl_response", link_id=self.id)
|
||||||
url = url_for("copilot.lnurl_response", cp_id=self.id, _external=True)
|
|
||||||
return lnurl_encode(url)
|
return lnurl_encode(url)
|
||||||
|
|
|
@ -1,32 +1,45 @@
|
||||||
from quart import g, abort, render_template, jsonify, websocket
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import httpx
|
import httpx
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from lnbits.decorators import check_user_exists, validate_uuids
|
from lnbits.decorators import check_user_exists, validate_uuids
|
||||||
from . import copilot_ext
|
|
||||||
from .crud import get_copilot
|
from .crud import get_copilot
|
||||||
from quart import g, abort, render_template, jsonify, websocket
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import trio
|
|
||||||
import shortuuid
|
from lnbits.decorators import check_user_exists
|
||||||
from . import copilot_ext
|
|
||||||
|
from . import copilot_ext, copilot_renderer
|
||||||
|
from fastapi import FastAPI, Request
|
||||||
|
from fastapi.params import Depends
|
||||||
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
|
from starlette.exceptions import HTTPException
|
||||||
|
from starlette.responses import HTMLResponse
|
||||||
|
from lnbits.core.models import User
|
||||||
|
|
||||||
|
templates = Jinja2Templates(directory="templates")
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/")
|
@copilot_ext.route("/", response_class=HTMLResponse)
|
||||||
@validate_uuids(["usr"], required=True)
|
async def index(request: Request, user: User = Depends(check_user_exists)):
|
||||||
@check_user_exists()
|
return copilot_renderer().TemplateResponse(
|
||||||
async def index():
|
"copilot/index.html", {"request": request, "user": user.dict()}
|
||||||
return await render_template("copilot/index.html", user=g.user)
|
)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/cp/")
|
@copilot_ext.route("/cp/", response_class=HTMLResponse)
|
||||||
async def compose():
|
async def compose(request: Request):
|
||||||
return await render_template("copilot/compose.html")
|
return copilot_renderer().TemplateResponse(
|
||||||
|
"copilot/compose.html", {"request": request}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/pn/")
|
@copilot_ext.route("/pn/", response_class=HTMLResponse)
|
||||||
async def panel():
|
async def panel(request: Request):
|
||||||
return await render_template("copilot/panel.html")
|
return copilot_renderer().TemplateResponse(
|
||||||
|
"copilot/panel.html", {"request": request}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
##################WEBSOCKET ROUTES########################
|
##################WEBSOCKET ROUTES########################
|
||||||
|
|
Loading…
Add table
Reference in a new issue