-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add public upload page - add print helpers
- Loading branch information
Showing
16 changed files
with
593 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"id": "pay2print", | ||
"name": "Pay 2 Print", | ||
"short_description": "pay sats to print a document", | ||
"tile": "https://raw.githubusercontent.com/lnbits/pay2print/main/static/bitcoin-extension.png", | ||
"tile": "https://raw.githubusercontent.com/lnbits/pay2print/main/static/printer.png", | ||
"min_lnbits_version": "1.0.0", | ||
"donate": "[email protected]", | ||
"contributors": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from os import path | ||
from pathlib import Path, PurePath | ||
from subprocess import PIPE, Popen | ||
from time import time | ||
|
||
from lnbits.settings import settings | ||
from loguru import logger | ||
|
||
upload_dir = Path(settings.lnbits_data_folder, "uploads") | ||
|
||
cmd_check_default_printer = ["lpstat", "-d"] | ||
cmd_print = "lpr" | ||
|
||
|
||
class PrinterError(Exception): | ||
"""Error is thrown we we cannot connect to the printer.""" | ||
|
||
|
||
def setup_upload_folder(): | ||
upload_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
|
||
def safe_file_name(file_name: str) -> Path: | ||
# strip leading path from file name to avoid directory traversal attacks | ||
safe_name = PurePath(file_name).name | ||
if path.exists(safe_name): | ||
safe_name = f"{int(time())}_{safe_name}" | ||
return Path(upload_dir, file_name) | ||
|
||
|
||
def print_file_path(file_name: str) -> Path: | ||
return Path(upload_dir, file_name) | ||
|
||
|
||
def check_printer(): | ||
try: | ||
lines = run_command(cmd_check_default_printer) | ||
if len(lines) == 0: | ||
raise PrinterError("No default printer found") | ||
logger.debug(f"Default printer: {lines[0]}") | ||
except Exception as e: | ||
raise PrinterError(f"Error checking default printer: {e}") from e | ||
|
||
|
||
def print_file(file_name: str): | ||
path = print_file_path(file_name) | ||
run_command([cmd_print, str(path)]) | ||
|
||
|
||
def run_command(command: list[str]) -> list[str]: | ||
"""Run a command and return the output as list of lines.""" | ||
stdout = Popen(command, stdout=PIPE).stdout | ||
if not stdout: | ||
return [] | ||
out = stdout.read().decode() | ||
return out.splitlines() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ authors = ["Alan Bits <[email protected]>"] | |
[tool.poetry.dependencies] | ||
python = "^3.10 | ^3.9" | ||
lnbits = {version = "*", allow-prereleases = true} | ||
python-multipart = "^0.0.20" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
black = "^24.3.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
window.app = Vue.createApp({ | ||
el: '#vue', | ||
mixins: [window.windowMixin], | ||
data() { | ||
return { | ||
invoice: null, | ||
invoiceAmount: amount + ' sat', | ||
paid: false | ||
} | ||
}, | ||
methods: { | ||
uploaded(e) { | ||
console.log('uploaded', e.xhr) | ||
this.invoice = e.xhr.response | ||
} | ||
}, | ||
created() {} | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.