feat(09-03): add .ps1 script download routes and detail-page links
- Refactor install/uninstall/detect handlers into shared _*_response() helpers
- Add .ps1 route aliases: /scripts/install.ps1, /scripts/uninstall.ps1, /scripts/detect.ps1
- Add Scripts section to printer_detail.html inside {% if has_driver %} with 3 download links
- All 6 new tests green, full suite 106/106 passing
This commit is contained in:
+39
-12
@@ -35,13 +35,10 @@ def _get_printer_and_driver(printer_id: int):
|
||||
return (printer, driver, driver_name), None
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/install")
|
||||
def get_install_script(printer_id: int):
|
||||
"""Download the PowerShell install script for a printer."""
|
||||
def _install_response(printer_id: int):
|
||||
result, error = _get_printer_and_driver(printer_id)
|
||||
if error is not None:
|
||||
return error
|
||||
|
||||
printer, driver, driver_name = result
|
||||
rendered = render_install(
|
||||
printer_name=printer.name,
|
||||
@@ -60,13 +57,10 @@ def get_install_script(printer_id: int):
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/uninstall")
|
||||
def get_uninstall_script(printer_id: int):
|
||||
"""Download the PowerShell uninstall script for a printer."""
|
||||
def _uninstall_response(printer_id: int):
|
||||
result, error = _get_printer_and_driver(printer_id)
|
||||
if error is not None:
|
||||
return error
|
||||
|
||||
printer, driver, driver_name = result
|
||||
rendered = render_uninstall(
|
||||
printer_name=printer.name,
|
||||
@@ -79,16 +73,49 @@ def get_uninstall_script(printer_id: int):
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/detect")
|
||||
def get_detect_script(printer_id: int):
|
||||
"""Download the PowerShell detection script for a printer."""
|
||||
def _detect_response(printer_id: int):
|
||||
result, error = _get_printer_and_driver(printer_id)
|
||||
if error is not None:
|
||||
return error
|
||||
|
||||
printer, driver, driver_name = result
|
||||
rendered = render_detect(printer_name=printer.name)
|
||||
return PlainTextResponse(
|
||||
content=rendered,
|
||||
headers={"Content-Disposition": 'attachment; filename="detect.ps1"'},
|
||||
)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/install")
|
||||
def get_install_script(printer_id: int):
|
||||
"""Download the PowerShell install script for a printer."""
|
||||
return _install_response(printer_id)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/install.ps1")
|
||||
def get_install_script_ps1(printer_id: int):
|
||||
"""Download the PowerShell install script for a printer (.ps1 alias)."""
|
||||
return _install_response(printer_id)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/uninstall")
|
||||
def get_uninstall_script(printer_id: int):
|
||||
"""Download the PowerShell uninstall script for a printer."""
|
||||
return _uninstall_response(printer_id)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/uninstall.ps1")
|
||||
def get_uninstall_script_ps1(printer_id: int):
|
||||
"""Download the PowerShell uninstall script for a printer (.ps1 alias)."""
|
||||
return _uninstall_response(printer_id)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/detect")
|
||||
def get_detect_script(printer_id: int):
|
||||
"""Download the PowerShell detection script for a printer."""
|
||||
return _detect_response(printer_id)
|
||||
|
||||
|
||||
@router.get("/{printer_id}/scripts/detect.ps1")
|
||||
def get_detect_script_ps1(printer_id: int):
|
||||
"""Download the PowerShell detection script for a printer (.ps1 alias)."""
|
||||
return _detect_response(printer_id)
|
||||
|
||||
Reference in New Issue
Block a user