From d90babebc8a9b405b97324dd4bec904f0b96c74d Mon Sep 17 00:00:00 2001 From: benarc Date: Fri, 19 Jan 2024 17:40:43 +0000 Subject: [PATCH] added confetti --- __init__.py | 2 +- __pycache__/__init__.cpython-39.pyc | Bin 1045 -> 1052 bytes __pycache__/crud.cpython-39.pyc | Bin 2915 -> 3027 bytes __pycache__/tasks.cpython-39.pyc | Bin 1358 -> 1373 bytes __pycache__/views_api.cpython-39.pyc | Bin 3679 -> 3731 bytes config.json | 2 +- crud.py | 26 ++++---- static/confetti.min.js | 8 +++ static/{image => }/myextension.png | Bin tasks.py | 14 ++-- templates/myextension/_api_docs.html | 73 +-------------------- templates/myextension/_myextension.html | 15 ++++- templates/myextension/index.html | 82 ++++++++++++++++++++---- templates/myextension/myextension.html | 79 +++++++++++++++++------ views_api.py | 11 ++-- 15 files changed, 177 insertions(+), 135 deletions(-) create mode 100644 static/confetti.min.js rename static/{image => }/myextension.png (100%) 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 467dbcca859d1a73d84a176b8723a8e0b66c6fe0..06b20b08db9a0cf26ca6293d018046006a0dfde9 100644 GIT binary patch delta 40 wcmbQrF^7XUk(ZZ?fq{X6#c@^Yla0LJnRoQgaJ73o!FA0sw_p2tWV; diff --git a/__pycache__/crud.cpython-39.pyc b/__pycache__/crud.cpython-39.pyc index 78b148c45943d6c5f1775669919ec4b988efb84f..d7c6ca969092ef39e093c7a1efde628487c3a71f 100644 GIT binary patch delta 1312 zcmaDXc3E6Ik(ZZ?fq{Xcanq_)eQpMZ#~==jlt_w1s&Fb(s-Pr8DpM-2Btr`C9Oe|h6#f?0DA5$jRO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DW-1d5UAQM2@1nfX?G=MDut3z@Y#Qe!ixz#v?M8r6i_yjls!dl$1 diff --git a/__pycache__/tasks.cpython-39.pyc b/__pycache__/tasks.cpython-39.pyc index 2b6955b8e1597736fdeb6aa8952773b0b686c95c..1e4e1dcbd333f50492d5bd8562fb76545425872f 100644 GIT binary patch delta 566 zcmX@db(f1Tk(ZZ?fq{Wx&8AhU0_+p{WEd+ZYDdcD@<;JAGNf>(aJ4W*38b>5Fs5+N zVM^gi;ca1w5}Y`1vJ}%T{`Az6_}t3Wijvg4;>`TKTSBD;DTyVilg$~`>YW%E7)lrx zFqSYiGc06eWGG=?z_O5`mZ5~Th5;nj%*4o0!?1vDA%iDF3WEnjEn^9L4P!GSgvZEG zsF1=C%%I8Wr^!*o#K6FCi!~)RsWiQa9mHl&EUwH;&dk5X8d#cInp(sG5@b$KExE;? zpBJB*SC&8d2%{>a@Z?vFu`;3z3=G9!KQi(#axn5R@i7*G#59?TgeE64sWSFWZfDXB zDq%rbU(1xjTEmpZTEmdVCeDz_Sj$|(p2m>ER>PRdSi`)8u@COd8m24`kg6JnEY2E+ zEUpyxIV`m-CEPWPB|MX*m_vAYkpgIPF|&;?FW5UpJRm2trdE^`B^L2BFfbH>Tv#Lt zV#$CAZV(|2B4j~?9Ee~8>0vG|Dbi#u5&{WGO%`S`aTEqI!Gs8iCBVSIpaAkS$Q%Yn zE=B=H7A77>K31OpEG!aiER10IhmE}mq*7C;h<9=iOOrg>H-0|P@b z2gpf`9E?27e2hiH3=9mKOhp2dCo`!sE}FcPNjI&AvDnCqp^34C1z~P2Qw>wG2S_x9 zwT3B+wT2;!O`IWhQpWO3CnWO1jk z&ta)$DdDMMEa9DO!5qTMR+5@qFnI>EO$uKT69WUoE!LFOq|)?Ttf>_xMTtec3=9lK zpb#t)2eG6;DuhZ4QW8s2<8v!hD@s!HiZk=`Zn30fCYKaRg49TZ2pJH;22#yjTvDXT zS|k7xkeIBH&>#lZ~#89i!s diff --git a/__pycache__/views_api.cpython-39.pyc b/__pycache__/views_api.cpython-39.pyc index a2ad3213922a49e408ddaf33b94862ac38d11c03..dcb8161a48bbc1b778c00334f714aaf53f7e7250 100644 GIT binary patch delta 463 zcmcaFGg+25k(ZZ?fq{Wx)23Ca3n%i*GG5uJ?ZC**o~o9rohp$cHHT$#38Nw>h%b>M zJBNAm9L5hU^(;lw3=9mnSW*&85{on$7#NCV85kInSwJR1F)ITD0|*~xU|=XNV_;yY zVJa3XVJKnDVoG65Vd`aSVk}{tjn{f$Gy`Ph&`7tzpV!tYKWhv5;X2V+vahLnh-A#y&=bVIY}c22J+K zn(SUoMbeWC*e%&u!499iirrO_orRH!k?lVlvj8Ix6CWcVqY7h@5d#B*CNo$~k^bbV zY)aM&3=9k<3^hzyj9E-Ij5Q1?jJ?cIE0}AT7cehm2xib^^3!C##aW)1lapE!pP5pm z4+;_K$%!0N9FUMI(x1GMT~8>vC^fMpH4+pe;GklY*u0N}jgc{R^HEM0CdTT`Ts*HC z8FMCo0>X zY4ZZc4=kL_w^&jVOA?DTC+l)3+2t@WFw`&>3zaaGFlI5OFs3l|GBq)lFxN0PGkP+l zFnBQ3GS@H{>v%DwFgG(cG1f3;v1GB-hp@gA^F^e&asfHniv6l(z45k{U1f*CZK{4|+vah50MB7WVvDt#>H6vr%WEDO; nZ5Fn_OpIXomrsO`iS0iVBg=n2P7WALl#hw$KNBMxBhx 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()