From 4d5c7133bc773b5ecac99663035195334c6c722f Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 9 Jan 2023 12:30:21 +0000 Subject: [PATCH 1/6] create smaller base64 image in UI --- lnbits/extensions/market/templates/market/index.html | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lnbits/extensions/market/templates/market/index.html b/lnbits/extensions/market/templates/market/index.html index ffcb612b..c9542bc1 100644 --- a/lnbits/extensions/market/templates/market/index.html +++ b/lnbits/extensions/market/templates/market/index.html @@ -831,14 +831,8 @@ let canvas = document.createElement('canvas') canvas.setAttribute('width', fit.width) canvas.setAttribute('height', fit.height) - await pica.resize(image, canvas, { - quality: 0, - alpha: true, - unsharpAmount: 95, - unsharpRadius: 0.9, - unsharpThreshold: 70 - }) - this.productDialog.data.image = canvas.toDataURL() + output = await pica.resize(image, canvas) + this.productDialog.data.image = output.toDataURL('image/jpeg', 0.4) this.productDialog = {...this.productDialog} } }, From 44fa30fdc3e4b9e14ae8230561688098f8567b49 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 9 Jan 2023 12:31:12 +0000 Subject: [PATCH 2/6] check uploaded image size in API --- lnbits/extensions/market/views_api.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lnbits/extensions/market/views_api.py b/lnbits/extensions/market/views_api.py index 045bc0fc..31703e8d 100644 --- a/lnbits/extensions/market/views_api.py +++ b/lnbits/extensions/market/views_api.py @@ -113,6 +113,23 @@ async def api_market_product_create( if stall.currency != "sat": data.price *= settings.fiat_base_multiplier + if data.image: + image_is_url = data.image.startswith("https://") or data.image.startswith( + "http://" + ) + + if not image_is_url: + + def size(b64string): + return int((len(b64string) * 3) / 4 - b64string.count("=", -2)) + + image_size = size(data.image) / 1024 + if image_size > 100: + raise HTTPException( + status_code=HTTPStatus.BAD_REQUEST, + detail=f"Image size is too big, {int(image_size)}Kb. Max: 100kb, Compress the image at https://tinypng.com, or use an URL.", + ) + if product_id: product = await get_market_product(product_id) if not product: From ab73698a456d11e7d715169131dc7ef9ca820d4e Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 9 Jan 2023 19:11:16 +0000 Subject: [PATCH 3/6] add product image with url --- .../market/templates/market/_dialogs.html | 14 +++++++++++++- .../extensions/market/templates/market/index.html | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/market/templates/market/_dialogs.html b/lnbits/extensions/market/templates/market/_dialogs.html index d2a8dd0a..a0ab84b3 100644 --- a/lnbits/extensions/market/templates/market/_dialogs.html +++ b/lnbits/extensions/market/templates/market/_dialogs.html @@ -55,8 +55,16 @@ > - + + Date: Tue, 10 Jan 2023 14:20:46 +0000 Subject: [PATCH 4/6] fix error when no categories are defined --- lnbits/extensions/market/templates/market/index.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lnbits/extensions/market/templates/market/index.html b/lnbits/extensions/market/templates/market/index.html index c6227023..77e3acce 100644 --- a/lnbits/extensions/market/templates/market/index.html +++ b/lnbits/extensions/market/templates/market/index.html @@ -802,9 +802,11 @@ var link = _.findWhere(self.products, {id: linkId}) self.productDialog.data = _.clone(link._data) - self.productDialog.data.categories = self.productDialog.data.categories.split( - ',' - ) + if (self.productDialog.data.categories) { + self.productDialog.data.categories = self.productDialog.data.categories.split( + ',' + ) + } if (self.productDialog.data.image.startsWith('data:')) { self.productDialog.url = false } From a85cd942340163459a573e6d70e34b047fd40b96 Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 10 Jan 2023 18:30:09 +0000 Subject: [PATCH 5/6] Elaborated nostr reference --- lnbits/extensions/market/templates/market/_tables.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/market/templates/market/_tables.html b/lnbits/extensions/market/templates/market/_tables.html index c6fd665b..b6abcb58 100644 --- a/lnbits/extensions/market/templates/market/_tables.html +++ b/lnbits/extensions/market/templates/market/_tables.html @@ -200,7 +200,7 @@ :href="props.row.wallet" target="_blank" > - Link to pass to stall relay + Disabled: link to pass to stall relays when using nostr {{ col.value }} From 2602f044dabb45c0fbfa718b0870103bc2afb7ab Mon Sep 17 00:00:00 2001 From: ben Date: Tue, 10 Jan 2023 18:37:54 +0000 Subject: [PATCH 6/6] format --- lnbits/extensions/market/templates/market/_tables.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/market/templates/market/_tables.html b/lnbits/extensions/market/templates/market/_tables.html index b6abcb58..280bb9f1 100644 --- a/lnbits/extensions/market/templates/market/_tables.html +++ b/lnbits/extensions/market/templates/market/_tables.html @@ -200,7 +200,10 @@ :href="props.row.wallet" target="_blank" > - Disabled: link to pass to stall relays when using nostr + Disabled: link to pass to stall relays when using + nostr {{ col.value }}