What changed, and why it matters
This commit is a routine code-quality and tooling update for the LNbits Paywall extension. It adds linting/formatting configuration (Black, Ruff, Prettier, mypy, pyright), restructures how FastAPI routers are registered, renames a shadowing built-in variable 'id' to 'paywall_id', and adds a basic test. There is no security fix or vulnerability patch in the diff.
No security action required. Treat as normal maintenance; review the refactor for functional regressions during routine QA.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a refactor: init.py now imports routers from views.py/views_api.py instead of using wildcard imports; views.py and views_api.py define their own APIRouter instances that are included under the /paywall prefix. crud.py moves the Database instance locally and renames the update_paywall parameter from ‘id’ to ‘paywall_id’. Exception handling is updated to use ‘from exc’ for chaining. A lint CI workflow, Makefile, pyproject.toml, package.json, and a minimal pytest are added. No access-control, cryptographic, input-validation, or injection-related logic is changed.
Changed components
LNbits Paywall extensionFastAPI router registration (__init__.py, views.py, views_api.py)CRUD module (crud.py)Development tooling (Makefile, pyproject.toml, .github/workflows/lint.yml, package.json)Inspect captured patch +2850 / −76
### .github/workflows/lint.yml
@@ -0,0 +1,10 @@
+name: lint
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+
+jobs:
+ lint:
+ uses: lnbits/lnbits/.github/workflows/lint.yml@dev
### .github/workflows/release.yml
@@ -1,10 +1,9 @@
on:
push:
tags:
- - "v[0-9]+.[0-9]+.[0-9]+"
+ - 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
-
release:
runs-on: ubuntu-latest
steps:
@@ -34,12 +33,12 @@ jobs:
- name: Create pull request in extensions repo
env:
GH_TOKEN: ${{ secrets.EXT_GITHUB }}
- repo_name: "${{ github.event.repository.name }}"
- tag: "${{ github.ref_name }}"
- branch: "update-${{ github.event.repository.name }}-${{ github.ref_name }}"
- title: "[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}"
- body: "https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}"
- archive: "https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip"
+ repo_name: '${{ github.event.repository.name }}'
+ tag: '${{ github.ref_name }}'
+ branch: 'update-${{ github.event.repository.name }}-${{ github.ref_name }}'
+ title: '[UPDATE] ${{ github.event.repository.name }} to ${{ github.ref_name }}'
+ body: 'https://github.com/lnbits/${{ github.event.repository.name }}/releases/${{ github.ref_name }}'
+ archive: 'https://github.com/lnbits/${{ github.event.repository.name }}/archive/refs/tags/${{ github.ref_name }}.zip'
run: |
cd lnbits-extensions
git checkout -b $branch
### .gitignore
@@ -1 +1,4 @@
__pycache__
+node_modules
+.mypy_cache
+.venv
### .prettierrc
@@ -0,0 +1,12 @@
+{
+ "semi": false,
+ "arrowParens": "avoid",
+ "insertPragma": false,
+ "printWidth": 80,
+ "proseWrap": "preserve",
+ "singleQuote": true,
+ "trailingComma": "none",
+ "useTabs": false,
+ "bracketSameLine": false,
+ "bracketSpacing": false
+}
### Makefile
@@ -0,0 +1,47 @@
+all: format check
+
+format: prettier black ruff
+
+check: mypy pyright checkblack checkruff checkprettier
+
+prettier:
+ poetry run ./node_modules/.bin/prettier --write .
+pyright:
+ poetry run ./node_modules/.bin/pyright
+
+mypy:
+ poetry run mypy .
+
+black:
+ poetry run black .
+
+ruff:
+ poetry run ruff check . --fix
+
+checkruff:
+ poetry run ruff check .
+
+checkprettier:
+ poetry run ./node_modules/.bin/prettier --check .
+
+checkblack:
+ poetry run black --check .
+
+checkeditorconfig:
+ editorconfig-checker
+
+test:
+ PYTHONUNBUFFERED=1 \
+ DEBUG=true \
+ poetry run pytest
+install-pre-commit-hook:
+ @echo "Installing pre-commit hook to git"
+ @echo "Uninstall the hook with poetry run pre-commit uninstall"
+ poetry run pre-commit install
+
+pre-commit:
+ poetry run pre-commit run --all-files
+
+
+checkbundle:
+ @echo "skipping checkbundle"
### README.md
@@ -24,6 +24,7 @@ A Paywall is a way of restricting to content via a purchase or paid subscription

### File Paywall
+
It is possible to also protect a file behind a paywall.
https://github.com/lnbits/paywall/assets/2951406/527c176c-38ff-4198-a4c1-6d07807e7443
### __init__.py
@@ -1,43 +1,38 @@
import asyncio
-from typing import List
-from fastapi import APIRouter
-from asyncio import Task
-from loguru import logger
-from lnbits.db import Database
-from lnbits.helpers import template_renderer
+from fastapi import APIRouter
from lnbits.tasks import create_permanent_unique_task
+from loguru import logger
-db = Database("ext_paywall")
+from .crud import db
+from .tasks import wait_for_paid_invoices
+from .views import paywall_generic_router
+from .views_api import paywall_api_router
paywall_ext: APIRouter = APIRouter(prefix="/paywall", tags=["Paywall"])
+paywall_ext.include_router(paywall_generic_router)
+paywall_ext.include_router(paywall_api_router)
paywall_static_files = [
{
"path": "/paywall/static",
"name": "paywall_static",
}
]
-
-
-def paywall_renderer():
- return template_renderer(["paywall/templates"])
-
-
-from .tasks import wait_for_paid_invoices, paid_invoices # noqa: F401,F403,E402
-from .views import * # noqa: F401,F403,E402
-from .views_api import * # noqa: F401,F403,E402
-
-
scheduled_tasks: list[asyncio.Task] = []
+
def paywall_stop():
for task in scheduled_tasks:
try:
task.cancel()
except Exception as ex:
logger.warning(ex)
+
def paywall_start():
task = create_permanent_unique_task("ext_paywall", wait_for_paid_invoices)
scheduled_tasks.append(task)
+
+
+__all__ = ["db", "paywall_ext", "paywall_static_files", "paywall_start", "paywall_stop"]
### crud.py
@@ -1,11 +1,13 @@
import json
from typing import List, Optional, Union
+from lnbits.db import Database
from lnbits.helpers import urlsafe_short_hash
-from . import db
from .models import CreatePaywall, Paywall
+db = Database("ext_paywall")
+
async def create_paywall(wallet_id: str, data: CreatePaywall) -> Paywall:
paywall_id = urlsafe_short_hash()
@@ -32,7 +34,9 @@ async def create_paywall(wallet_id: str, data: CreatePaywall) -> Paywall:
return paywall
-async def update_paywall(id: str, wallet_id: str, data: CreatePaywall) -> Paywall:
+async def update_paywall(
+ paywall_id: str, wallet_id: str, data: CreatePaywall
+) -> Paywall:
await db.execute(
"""
UPDATE paywall.paywalls
@@ -48,12 +52,12 @@ async def update_paywall(id: str, wallet_id: str, data: CreatePaywall) -> Paywal
data.amount,
int(data.remembers),
json.dumps(data.extras.dict()) if data.extras else None,
- id,
+ paywall_id,
wallet_id,
),
)
- paywall = await get_paywall(id)
+ paywall = await get_paywall(paywall_id)
assert paywall, "Updated paywall couldn't be retrieved"
return paywall
### description.md
@@ -1,3 +1,3 @@
Hide content behind a paywall, a user has to pay some amount to access your hidden content.
-A Paywall is a way of restricting to content via a purchase or paid subscription. For example to read a determined blog post, or to continue reading further, to access a downloads area, etc...
\ No newline at end of file
+A Paywall is a way of restricting to content via a purchase or paid subscription. For example to read a determined blog post, or to continue reading further, to access a downloads area, etc...
### package-lock.json
@@ -0,0 +1,59 @@
+{
+ "name": "paywall",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "paywall",
+ "version": "1.0.0",
+ "license": "ISC",
+ "dependencies": {
+ "prettier": "^3.2.5",
+ "pyright": "^1.1.358"
+ }
+ },
+ "node_modules/fsevents": {
+ "version": "2.3.3",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
+ "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
+ "hasInstallScript": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/prettier": {
+ "version": "3.3.3",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz",
+ "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==",
+ "bin": {
+ "prettier": "bin/prettier.cjs"
+ },
+ "engines": {
+ "node": ">=14"
+ },
+ "funding": {
+ "url": "https://github.com/prettier/prettier?sponsor=1"
+ }
+ },
+ "node_modules/pyright": {
+ "version": "1.1.374",
+ "resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.374.tgz",
+ "integrity": "sha512-ISbC1YnYDYrEatoKKjfaA5uFIp0ddC/xw9aSlN/EkmwupXUMVn41Jl+G6wHEjRhC+n4abHZeGpEvxCUus/K9dA==",
+ "bin": {
+ "pyright": "index.js",
+ "pyright-langserver": "langserver.index.js"
+ },
+ "engines": {
+ "node": ">=14.0.0"
+ },
+ "optionalDependencies": {
+ "fsevents": "~2.3.3"
+ }
+ }
+ }
+}
### package.json
@@ -0,0 +1,15 @@
+{
+ "name": "paywall",
+ "version": "1.0.0",
+ "description": "",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "",
+ "license": "ISC",
+ "dependencies": {
+ "prettier": "^3.2.5",
+ "pyright": "^1.1.358"
+ }
+}
### poetry.lock
[binary or diff unavailable]
### pyproject.toml
@@ -0,0 +1,94 @@
+[tool.poetry]
+name = "lnbits-paywall"
+version = "0.0.0"
+description = "LNbits, free and open-source Lightning wallet and accounts system."
+authors = ["Alan Bits <alan@lnbits.com>"]
+
+[tool.poetry.dependencies]
+python = "^3.10 | ^3.9"
+lnbits = "*"
+
+[tool.poetry.group.dev.dependencies]
+black = "^24.3.0"
+pytest-asyncio = "^0.21.0"
+pytest = "^7.3.2"
+mypy = "^1.5.1"
+pre-commit = "^3.2.2"
+ruff = "^0.3.2"
+
+[build-system]
+requires = ["poetry-core>=1.0.0"]
+build-backend = "poetry.core.masonry.api"
+
+[tool.mypy]
+exclude = "(nostr/*)"
+[[tool.mypy.overrides]]
+module = [
+ "lnbits.*",
+ "lnurl.*",
+ "loguru.*",
+ "fastapi.*",
+ "pydantic.*",
+ "pyqrcode.*",
+ "shortuuid.*",
+ "httpx.*",
+]
+ignore_missing_imports = "True"
+
+[tool.pytest.ini_options]
+log_cli = false
+testpaths = [
+ "tests"
+]
+
+[tool.black]
+line-length = 88
+
+[tool.ruff]
+# Same as Black. + 10% rule of black
+line-length = 88
+exclude = [
+ "nostr",
+]
+
+[tool.ruff.lint]
+# Enable:
+# F - pyflakes
+# E - pycodestyle errors
+# W - pycodestyle warnings
+# I - isort
+# A - flake8-builtins
+# C - mccabe
+# N - naming
+# UP - pyupgrade
+# RUF - ruff
+# B - bugbear
+select = ["F", "E", "W", "I", "A", "C", "N", "UP", "RUF", "B"]
+ignore = ["C901"]
+
+# Allow autofix for all enabled rules (when `--fix`) is provided.
+fixable = ["ALL"]
+unfixable = []
+
+# Allow unused variables when underscore-prefixed.
+dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
+
+# needed for pydantic
+[tool.ruff.lint.pep8-naming]
+classmethod-decorators = [
+ "root_validator",
+]
+
+# Ignore unused imports in __init__.py files.
+# [tool.ruff.lint.extend-per-file-ignores]
+# "__init__.py" = ["F401", "F403"]
+
+# [tool.ruff.lint.mccabe]
+# max-complexity = 10
+
+[tool.ruff.lint.flake8-bugbear]
+# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`.
+extend-immutable-calls = [
+ "fastapi.Depends",
+ "fastapi.Query",
+]
### tasks.py
@@ -1,6 +1,5 @@
from asyncio import Queue
-
from lnbits.core.models import Payment
from lnbits.tasks import register_invoice_listener
### templates/paywall/display.html
@@ -53,7 +53,9 @@ <h5 class="text-subtitle1 q-mt-none q-mb-sm">{{ paywall.memo }}</h5>
<q-separator class="q-my-lg"></q-separator>
<p>
You can access the URL behind this paywall:<br />
- <strong style="word-break: break-all;">{% raw %}{{ redirectUrl }}{% endraw %}</strong>
+ <strong style="word-break: break-all"
+ >{% raw %}{{ redirectUrl }}{% endraw %}</strong
+ >
</p>
<div class="row q-mt-lg">
<q-btn outline color="grey" type="a" :href="redirectUrl"
### tests/__init__.py
[binary or diff unavailable]
### tests/test_init.py
@@ -0,0 +1,11 @@
+import pytest
+from fastapi import APIRouter
+
+from .. import paywall_ext
+
+
+# just import router and add it to a test router
+@pytest.mark.asyncio
+async def test_router():
+ router = APIRouter()
+ router.include_router(paywall_ext)
### toc.md
@@ -1,22 +1,29 @@
# Terms and Conditions for LNbits Extension
## 1. Acceptance of Terms
+
By installing and using the LNbits extension ("Extension"), you agree to be bound by these terms and conditions ("Terms"). If you do not agree to these Terms, do not use the Extension.
## 2. License
+
The Extension is free and open-source software, released under [specify the FOSS license here, e.g., GPL-3.0, MIT, etc.]. You are permitted to use, copy, modify, and distribute the Extension under the terms of that license.
## 3. No Warranty
+
The Extension is provided "as is" and with all faults, and the developer expressly disclaims all warranties of any kind, whether express, implied, statutory, or otherwise, including but not limited to warranties of merchantability, fitness for a particular purpose, non-infringement, and any warranties arising out of course of dealing or usage of trade. No advice or information, whether oral or written, obtained from the developer or elsewhere will create any warranty not expressly stated in this Terms.
## 4. Limitation of Liability
+
In no event will the developer be liable to you or any third party for any direct, indirect, incidental, special, consequential, or punitive damages, including lost profit, lost revenue, loss of data, or other damages arising out of or in connection with your use of the Extension, even if the developer has been advised of the possibility of such damages. The foregoing limitation of liability shall apply to the fullest extent permitted by law in the applicable jurisdiction.
## 5. Modification of Terms
+
The developer reserves the right to modify these Terms at any time. You are advised to review these Terms periodically for any changes. Changes to these Terms are effective when they are posted on the appropriate location within or associated with the Extension.
## 6. General Provisions
+
If any provision of these Terms is held to be invalid or unenforceable, that provision will be enforced to the maximum extent permissible, and the other provisions of these Terms will remain in full force and effect. These Terms constitute the entire agreement between you and the developer regarding the use of the Extension.
## 7. Contact Information
-If you have any questions about these Terms, please contact the developer at [developer's contact information].
\ No newline at end of file
+
+If you have any questions about these Terms, please contact the developer at [developer's contact information].
### views.py
@@ -1,24 +1,29 @@
from http import HTTPStatus
-from fastapi import Depends
+from fastapi import APIRouter, Depends
from fastapi.exceptions import HTTPException
from fastapi.requests import Request
-
from lnbits.core.models import User
from lnbits.decorators import check_user_exists
+from lnbits.helpers import template_renderer
-from . import paywall_ext, paywall_renderer
from .crud import get_paywall
+paywall_generic_router = APIRouter()
+
+
+def paywall_renderer():
+ return template_renderer(["paywall/templates"])
+
-@paywall_ext.get("/")
+@paywall_generic_router.get("/")
async def index(request: Request, user: User = Depends(check_user_exists)):
return paywall_renderer().TemplateResponse(
"paywall/index.html", {"request": request, "user": user.dict()}
)
-@paywall_ext.get("/{paywall_id}")
+@paywall_generic_router.get("/{paywall_id}")
async def display(request: Request, paywall_id: str):
paywall = await get_paywall(paywall_id)
if not paywall:
### views_api.py
@@ -1,23 +1,29 @@
+import json
from asyncio import Queue
from http import HTTPStatus
-import json
from typing import Optional
from urllib import request
-from fastapi import Depends, Query, Request, Response, WebSocket, WebSocketDisconnect
+from fastapi import (
+ APIRouter,
+ Depends,
+ Query,
+ Request,
+ Response,
+ WebSocket,
+ WebSocketDisconnect,
+)
from fastapi.exceptions import HTTPException
from fastapi.responses import StreamingResponse
-from loguru import logger
-
from lnbits.core.crud import get_standalone_payment, get_user
+from lnbits.core.models import WalletTypeInfo
from lnbits.core.services import check_transaction_status, create_invoice
from lnbits.decorators import (
- WalletTypeInfo,
get_key_type,
require_admin_key,
)
+from loguru import logger
-from . import paywall_ext, paid_invoices
from .crud import (
create_paywall,
delete_paywall,
@@ -26,9 +32,12 @@
update_paywall,
)
from .models import CheckPaywallInvoice, CreatePaywall, CreatePaywallInvoice, Paywall
+from .tasks import paid_invoices
+paywall_api_router = APIRouter()
-@paywall_ext.get("/api/v1/paywalls")
+
+@paywall_api_router.get("/api/v1/paywalls")
async def api_paywalls(
wallet: WalletTypeInfo = Depends(get_key_type), all_wallets: bool = Query(False)
):
@@ -41,24 +50,28 @@ async def api_paywalls(
return [paywall.dict() for paywall in await get_paywalls(wallet_ids)]
-@paywall_ext.post("/api/v1/paywalls")
+@paywall_api_router.post("/api/v1/paywalls")
async def api_paywall_create(
data: CreatePaywall, wallet: WalletTypeInfo = Depends(require_admin_key)
):
paywall = await create_paywall(wallet_id=wallet.wallet.id, data=data)
return paywall.dict()
-@paywall_ext.patch("/api/v1/paywalls/{id}")
-@paywall_ext.put("/api/v1/paywalls/{id}")
+@paywall_api_router.patch("/api/v1/paywalls/{id}")
+@paywall_api_router.put("/api/v1/paywalls/{id}")
async def api_paywall_update(
- id: str, data: CreatePaywall, wallet: WalletTypeInfo = Depends(require_admin_key)
+ paywall_id: str,
+ data: CreatePaywall,
+ wallet: WalletTypeInfo = Depends(require_admin_key),
):
- paywall = await update_paywall(id=id, wallet_id=wallet.wallet.id, data=data)
+ paywall = await update_paywall(
+ paywall_id=paywall_id, wallet_id=wallet.wallet.id, data=data
+ )
return paywall.dict()
-@paywall_ext.delete("/api/v1/paywalls/{paywall_id}")
+@paywall_api_router.delete("/api/v1/paywalls/{paywall_id}")
async def api_paywall_delete(
paywall_id: str, wallet: WalletTypeInfo = Depends(require_admin_key)
):
@@ -78,19 +91,21 @@ async def api_paywall_delete(
return "", HTTPStatus.NO_CONTENT
-@paywall_ext.post("/api/v1/paywalls/invoice/{paywall_id}")
+@paywall_api_router.post("/api/v1/paywalls/invoice/{paywall_id}")
async def api_paywall_create_invoice(data: CreatePaywallInvoice, paywall_id: str):
try:
paywall = await get_paywall(paywall_id)
assert paywall, "Paywall not found"
return await _create_paywall_invoice(paywall, data.amount)
- except AssertionError as e:
- raise HTTPException(HTTPStatus.BAD_REQUEST, str(e))
- except Exception as e:
- raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
+ except AssertionError as exc:
+ raise HTTPException(HTTPStatus.BAD_REQUEST, str(exc)) from exc
+ except Exception as exc:
+ raise HTTPException(
+ status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(exc)
+ ) from exc
-@paywall_ext.get("/api/v1/paywalls/invoice/{paywall_id}")
+@paywall_api_router.get("/api/v1/paywalls/invoice/{paywall_id}")
async def api_paywall_create_fixed_amount_invoice(
paywall_id: str, amount: Optional[int] = None
):
@@ -102,16 +117,16 @@ async def api_paywall_create_fixed_amount_invoice(
return {"amount": paywall.amount}
return await _create_paywall_invoice(paywall, amount)
- except AssertionError as e:
- raise HTTPException(HTTPStatus.BAD_REQUEST, str(e))
- except Exception as e:
+ except AssertionError as exc:
+ raise HTTPException(HTTPStatus.BAD_REQUEST, str(exc)) from exc
+ except Exception as exc:
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail="Cannot create invoice.",
- )
+ ) from exc
-@paywall_ext.post("/api/v1/paywalls/check_invoice/{paywall_id}")
+@paywall_api_router.post("/api/v1/paywalls/check_invoice/{paywall_id}")
async def api_paywal_check_invoice(
request: Request, data: CheckPaywallInvoice, paywall_id: str
):
@@ -134,7 +149,7 @@ async def api_paywal_check_invoice(
return {"paid": False}
-@paywall_ext.websocket("/api/v1/paywalls/invoice/{paywall_id}/{payment_hash}")
+@paywall_api_router.websocket("/api/v1/paywalls/invoice/{paywall_id}/{payment_hash}")
async def websocket_connect(ws: WebSocket, paywall_id: str, payment_hash: str) -> None:
try:
await ws.accept()
@@ -171,7 +186,7 @@ async def websocket_connect(ws: WebSocket, paywall_id: str, payment_hash: str) -
await ws.close()
-@paywall_ext.get("/download/{paywall_id}")
+@paywall_api_router.get("/download/{paywall_id}")
async def api_paywall_download_file(
paywall_id: str, version: Optional[str] = None, payment_hash: Optional[str] = None
):
@@ -201,18 +216,20 @@ async def api_paywall_download_file(
content=_file_streamer(file_config.url, file_config.headers),
headers=headers,
)
- except AssertionError as e:
- raise HTTPException(HTTPStatus.BAD_REQUEST, str(e))
- except Exception as e:
- logger.error(e)
- raise HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, "Cannot download file.")
+ except AssertionError as exc:
+ raise HTTPException(HTTPStatus.BAD_REQUEST, str(exc)) from exc
+ except Exception as exc:
+ logger.error(exc)
+ raise HTTPException(
+ HTTPStatus.INTERNAL_SERVER_ERROR, "Cannot download file."
+ ) from exc
finally:
logger.info(
f"Downloaded file for paywall '{paywall_id}'." + f" Version: '{version}'."
)
-@paywall_ext.head("/download/{paywall_id}")
+@paywall_api_router.head("/download/{paywall_id}")
async def api_paywall_check_file(paywall_id: str, payment_hash: Optional[str] = None):
try:
assert payment_hash, "Payment hash is missing."
@@ -234,11 +251,13 @@ async def api_paywall_check_file(paywall_id: str, payment_hash: Optional[str] =
headers={"paid_sats": f"{int(paid_amount / 1000)}"},
)
- except AssertionError as e:
- raise HTTPException(HTTPStatus.BAD_REQUEST, str(e))
- except Exception as e:
- logger.error(e)
- raise HTTPException(HTTPStatus.INTERNAL_SERVER_ERROR, "Cannot download file.")
+ except AssertionError as exc:
+ raise HTTPException(HTTPStatus.BAD_REQUEST, str(exc)) from exc
+ except Exception as exc:
+ logger.error(exc)
+ raise HTTPException(
+ HTTPStatus.INTERNAL_SERVER_ERROR, "Cannot download file."
+ ) from exc
async def _file_streamer(url, headers):Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.