mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-22 14:22:55 +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.helpers import template_renderer
|
||||
from lnbits.tasks import catch_everything_and_restart
|
||||
|
||||
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 import * # noqa
|
||||
from .tasks import wait_for_paid_invoices
|
||||
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
|
||||
from typing import NamedTuple
|
||||
import time
|
||||
from quart import url_for
|
||||
from lnurl import Lnurl, encode as lnurl_encode # type: ignore
|
||||
import json
|
||||
from urllib.parse import urlparse, urlunparse, parse_qs, urlencode, ParseResult
|
||||
from starlette.requests import Request
|
||||
from fastapi.param_functions import Query
|
||||
from typing import Optional, Dict
|
||||
from lnbits.lnurl import encode as lnurl_encode # 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
|
||||
user: str
|
||||
title: str
|
||||
|
@ -35,7 +63,6 @@ class Copilots(NamedTuple):
|
|||
def from_row(cls, row: Row) -> "Copilots":
|
||||
return cls(**dict(row))
|
||||
|
||||
@property
|
||||
def lnurl(self) -> Lnurl:
|
||||
url = url_for("copilot.lnurl_response", cp_id=self.id, _external=True)
|
||||
def lnurl(self, req: Request) -> str:
|
||||
url = req.url_for("copilot.lnurl_response", link_id=self.id)
|
||||
return lnurl_encode(url)
|
||||
|
|
|
@ -1,32 +1,45 @@
|
|||
from quart import g, abort, render_template, jsonify, websocket
|
||||
from http import HTTPStatus
|
||||
import httpx
|
||||
from collections import defaultdict
|
||||
from lnbits.decorators import check_user_exists, validate_uuids
|
||||
from . import copilot_ext
|
||||
|
||||
from .crud import get_copilot
|
||||
from quart import g, abort, render_template, jsonify, websocket
|
||||
|
||||
from functools import wraps
|
||||
import trio
|
||||
import shortuuid
|
||||
from . import copilot_ext
|
||||
|
||||
from lnbits.decorators import check_user_exists
|
||||
|
||||
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("/")
|
||||
@validate_uuids(["usr"], required=True)
|
||||
@check_user_exists()
|
||||
async def index():
|
||||
return await render_template("copilot/index.html", user=g.user)
|
||||
@copilot_ext.route("/", 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.route("/cp/")
|
||||
async def compose():
|
||||
return await render_template("copilot/compose.html")
|
||||
@copilot_ext.route("/cp/", response_class=HTMLResponse)
|
||||
async def compose(request: Request):
|
||||
return copilot_renderer().TemplateResponse(
|
||||
"copilot/compose.html", {"request": request}
|
||||
)
|
||||
|
||||
|
||||
@copilot_ext.route("/pn/")
|
||||
async def panel():
|
||||
return await render_template("copilot/panel.html")
|
||||
@copilot_ext.route("/pn/", response_class=HTMLResponse)
|
||||
async def panel(request: Request):
|
||||
return copilot_renderer().TemplateResponse(
|
||||
"copilot/panel.html", {"request": request}
|
||||
)
|
||||
|
||||
|
||||
##################WEBSOCKET ROUTES########################
|
||||
|
|
Loading…
Add table
Reference in a new issue