diff --git a/__init__.py b/__init__.py index be5149f..4870562 100644 --- a/__init__.py +++ b/__init__.py @@ -27,6 +27,6 @@ from .tasks import wait_for_paid_invoices from .views import * from .views_api import * -def temp_start(): +def myextension_start(): loop = asyncio.get_event_loop() loop.create_task(catch_everything_and_restart(wait_for_paid_invoices)) \ No newline at end of file diff --git a/__pycache__/__init__.cpython-39.pyc b/__pycache__/__init__.cpython-39.pyc index 467dbcc..06b20b0 100644 Binary files a/__pycache__/__init__.cpython-39.pyc and b/__pycache__/__init__.cpython-39.pyc differ diff --git a/__pycache__/crud.cpython-39.pyc b/__pycache__/crud.cpython-39.pyc index 78b148c..d7c6ca9 100644 Binary files a/__pycache__/crud.cpython-39.pyc and b/__pycache__/crud.cpython-39.pyc differ diff --git a/__pycache__/tasks.cpython-39.pyc b/__pycache__/tasks.cpython-39.pyc index 2b6955b..1e4e1dc 100644 Binary files a/__pycache__/tasks.cpython-39.pyc and b/__pycache__/tasks.cpython-39.pyc differ diff --git a/__pycache__/views_api.cpython-39.pyc b/__pycache__/views_api.cpython-39.pyc index a2ad321..dcb8161 100644 Binary files a/__pycache__/views_api.cpython-39.pyc and b/__pycache__/views_api.cpython-39.pyc differ diff --git a/config.json b/config.json index 4a75bb2..4750a20 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "name": "MyExtension", "short_description": "Minimal extension to build on", - "tile": "/myextension/static/image/myextension.png", + "tile": "/myextension/static/myextension.png", "contributors": ["arcbtc"], "min_lnbits_version": "0.0.1" } diff --git a/crud.py b/crud.py index a6bfe88..f5fde08 100644 --- a/crud.py +++ b/crud.py @@ -8,7 +8,7 @@ from loguru import logger from fastapi import Request from lnurl import encode as lnurl_encode -async def create_myextension(wallet_id: str, data: CreateMyExtensionData) -> MyExtension: +async def create_myextension(wallet_id: str, data: CreateMyExtensionData, req: Request) -> MyExtension: myextension_id = urlsafe_short_hash() await db.execute( """ @@ -23,21 +23,23 @@ async def create_myextension(wallet_id: str, data: CreateMyExtensionData) -> MyE data.lnurlwithdrawamount ), ) - myextension = await get_myextension(myextension_id) + myextension = await get_myextension(myextension_id, req) assert myextension, "Newly created table couldn't be retrieved" return myextension -async def get_myextension(myextension_id: str, req: Request) -> Optional[MyExtension]: +async def get_myextension(myextension_id: str, req: Optional[Request] = None) -> Optional[MyExtension]: + logger.debug(myextension_id) row = await db.fetchone("SELECT * FROM myextension.maintable WHERE id = ?", (myextension_id,)) if not row: return None rowAmended = MyExtension(**row) - rowAmended.lnurlpay = lnurl_encode(req.url_for("myextension.api_lnurl_pay", myextension_id=row.id)._url) - rowAmended.lnurlwithdraw = lnurl_encode(req.url_for("myextension.api_lnurl_withdraw", myextension_id=row.id)._url) + if req: + rowAmended.lnurlpay = lnurl_encode(req.url_for("myextension.api_lnurl_pay", myextension_id=row.id)._url) + rowAmended.lnurlwithdraw = lnurl_encode(req.url_for("myextension.api_lnurl_withdraw", myextension_id=row.id)._url) return rowAmended -async def get_myextensions(wallet_ids: Union[str, List[str]], req: Request) -> List[MyExtension]: +async def get_myextensions(wallet_ids: Union[str, List[str]], req: Optional[Request] = None) -> List[MyExtension]: if isinstance(wallet_ids, str): wallet_ids = [wallet_ids] @@ -46,17 +48,19 @@ async def get_myextensions(wallet_ids: Union[str, List[str]], req: Request) -> L f"SELECT * FROM myextension.maintable WHERE wallet IN ({q})", (*wallet_ids,) ) tempRows = [MyExtension(**row) for row in rows] - for row in tempRows: - row.lnurlpay = lnurl_encode(req.url_for("myextension.api_lnurl_pay", myextension_id=row.id)._url) - row.lnurlwithdraw = lnurl_encode(req.url_for("myextension.api_lnurl_withdraw", myextension_id=row.id)._url) + if req: + for row in tempRows: + row.lnurlpay = lnurl_encode(req.url_for("myextension.api_lnurl_pay", myextension_id=row.id)._url) + row.lnurlwithdraw = lnurl_encode(req.url_for("myextension.api_lnurl_withdraw", myextension_id=row.id)._url) return tempRows -async def update_myextension(myextension_id: str, **kwargs) -> MyExtension: +async def update_myextension(myextension_id: str, req: Optional[Request] = None, **kwargs) -> MyExtension: q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) + logger.debug( kwargs.items()) await db.execute( f"UPDATE myextension.maintable SET {q} WHERE id = ?", (*kwargs.values(), myextension_id) ) - myextension = await get_myextension(myextension_id) + myextension = await get_myextension(myextension_id, req) assert myextension, "Newly updated myextension couldn't be retrieved" return myextension diff --git a/static/confetti.min.js b/static/confetti.min.js new file mode 100644 index 0000000..0a09dd0 --- /dev/null +++ b/static/confetti.min.js @@ -0,0 +1,8 @@ +/** + * Minified by jsDelivr using Terser v5.3.5. + * Original file: /npm/canvas-confetti@1.4.0/dist/confetti.browser.js + * + * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files + */ +!function(t,e){!function t(e,n,a,i){var o=!!(e.Worker&&e.Blob&&e.Promise&&e.OffscreenCanvas&&e.OffscreenCanvasRenderingContext2D&&e.HTMLCanvasElement&&e.HTMLCanvasElement.prototype.transferControlToOffscreen&&e.URL&&e.URL.createObjectURL);function r(){}function l(t){var a=n.exports.Promise,i=void 0!==a?a:e.Promise;return"function"==typeof i?new i(t):(t(r,r),null)}var c,s,u,d,f,h,g,m,b=(u=Math.floor(1e3/60),d={},f=0,"function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame?(c=function(t){var e=Math.random();return d[e]=requestAnimationFrame((function n(a){f===a||f+u-1 None: if payment.extra.get("tag") != "MyExtension": return - myextension_id = payment.extra.get("tempId") - assert myextension_id - + myextension_id = payment.extra.get("myextensionId") myextension = await get_myextension(myextension_id) - assert myextension # update something in the db @@ -45,7 +43,7 @@ async def on_invoice_paid(payment: Payment) -> None: "total": myextension.total + payment.amount } - await update_myextension(myextension_id=myextension_id, **data_to_update.dict()) + await update_myextension(myextension_id=myextension_id, **data_to_update) # here we could send some data to a websocket on wss:///api/v1/ws/ # and then listen to it on the frontend, which we do with index.html connectWebocket() diff --git a/templates/myextension/_api_docs.html b/templates/myextension/_api_docs.html index fa2b07c..70d1fd4 100644 --- a/templates/myextension/_api_docs.html +++ b/templates/myextension/_api_docs.html @@ -4,76 +4,5 @@ label="API info" :content-inset-level="0.5" > - - - - - GET /myextension/api/v1/temps -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
-
- Returns 200 OK (application/json) -
- [<temp_object>, ...] -
Curl example
- curl -X GET {{ request.base_url }}myextension/api/v1/temps -H "X-Api-Key: - <invoice_key>" - -
-
-
- - - - POST /myextension/api/v1/temps -
Headers
- {"X-Api-Key": <invoice_key>}
-
Body (application/json)
- {"name": <string>, "currency": <string*ie USD*>} -
- Returns 201 CREATED (application/json) -
- {"currency": <string>, "id": <string>, "name": - <string>, "wallet": <string>} -
Curl example
- curl -X POST {{ request.base_url }}myextension/api/v1/temps -d '{"name": - <string>, "currency": <string>}' -H "Content-type: - application/json" -H "X-Api-Key: <admin_key>" - -
-
-
- - - - - DELETE - /myextension/api/v1/temps/<myextension_id> -
Headers
- {"X-Api-Key": <admin_key>}
-
Returns 204 NO CONTENT
- -
Curl example
- curl -X DELETE {{ request.base_url - }}myextension/api/v1/temps/<myextension_id> -H "X-Api-Key: <admin_key>" - -
-
-
+ diff --git a/templates/myextension/_myextension.html b/templates/myextension/_myextension.html index a2b9679..09e4c31 100644 --- a/templates/myextension/_myextension.html +++ b/templates/myextension/_myextension.html @@ -1,11 +1,11 @@ - +

- MyExtension extension is a basic extension that you can use to get started building your own extension + Some more info about my excellent extension.

Created by + >Created by Ben Arc. + Repo + MyExtension.
diff --git a/templates/myextension/index.html b/templates/myextension/index.html index 6d6029f..d6c2738 100644 --- a/templates/myextension/index.html +++ b/templates/myextension/index.html @@ -1,6 +1,6 @@ {% extends "base.html" %} {% from "macros.jinja" import window_vars with context %} {% block page %} -
+
@@ -67,7 +67,32 @@ target="_blank" >Open public page - + + + + Edit copilot + + + + + + Delete copilot + + @@ -194,6 +219,7 @@
{% endblock %} {% block scripts %} {{ window_vars(user) }} + diff --git a/views_api.py b/views_api.py index 800ab76..19bee97 100644 --- a/views_api.py +++ b/views_api.py @@ -66,6 +66,7 @@ async def api_myextension( @myextension_ext.put("/api/v1/temps/{myextension_id}") async def api_myextension_update( + req: Request, data: CreateMyExtensionData, myextension_id: str, wallet: WalletTypeInfo = Depends(get_key_type), @@ -74,12 +75,12 @@ async def api_myextension_update( raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="MyExtension does not exist." ) - myextension = await get_myextension(myextension_id) + myextension = await get_myextension(myextension_id, req) assert myextension, "MyExtension couldn't be retrieved" if wallet.wallet.id != myextension.wallet: raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your MyExtension.") - myextension = await update_myextension(myextension_id=myextension_id, **data.dict()) + myextension = await update_myextension(myextension_id=myextension_id, **data.dict(), req=req) return myextension.dict() @@ -87,9 +88,11 @@ async def api_myextension_update( @myextension_ext.post("/api/v1/temps", status_code=HTTPStatus.CREATED) async def api_myextension_create( - data: CreateMyExtensionData, wallet: WalletTypeInfo = Depends(get_key_type) + req: Request, + data: CreateMyExtensionData, + wallet: WalletTypeInfo = Depends(get_key_type) ): - myextension = await create_myextension(wallet_id=wallet.wallet.id, data=data) + myextension = await create_myextension(wallet_id=wallet.wallet.id, data=data, req=req) return myextension.dict()