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
|
return (printer, driver, driver_name), None
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{printer_id}/scripts/install")
|
def _install_response(printer_id: int):
|
||||||
def get_install_script(printer_id: int):
|
|
||||||
"""Download the PowerShell install script for a printer."""
|
|
||||||
result, error = _get_printer_and_driver(printer_id)
|
result, error = _get_printer_and_driver(printer_id)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
printer, driver, driver_name = result
|
printer, driver, driver_name = result
|
||||||
rendered = render_install(
|
rendered = render_install(
|
||||||
printer_name=printer.name,
|
printer_name=printer.name,
|
||||||
@@ -60,13 +57,10 @@ def get_install_script(printer_id: int):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{printer_id}/scripts/uninstall")
|
def _uninstall_response(printer_id: int):
|
||||||
def get_uninstall_script(printer_id: int):
|
|
||||||
"""Download the PowerShell uninstall script for a printer."""
|
|
||||||
result, error = _get_printer_and_driver(printer_id)
|
result, error = _get_printer_and_driver(printer_id)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
printer, driver, driver_name = result
|
printer, driver, driver_name = result
|
||||||
rendered = render_uninstall(
|
rendered = render_uninstall(
|
||||||
printer_name=printer.name,
|
printer_name=printer.name,
|
||||||
@@ -79,16 +73,49 @@ def get_uninstall_script(printer_id: int):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{printer_id}/scripts/detect")
|
def _detect_response(printer_id: int):
|
||||||
def get_detect_script(printer_id: int):
|
|
||||||
"""Download the PowerShell detection script for a printer."""
|
|
||||||
result, error = _get_printer_and_driver(printer_id)
|
result, error = _get_printer_and_driver(printer_id)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
return error
|
return error
|
||||||
|
|
||||||
printer, driver, driver_name = result
|
printer, driver, driver_name = result
|
||||||
rendered = render_detect(printer_name=printer.name)
|
rendered = render_detect(printer_name=printer.name)
|
||||||
return PlainTextResponse(
|
return PlainTextResponse(
|
||||||
content=rendered,
|
content=rendered,
|
||||||
headers={"Content-Disposition": 'attachment; filename="detect.ps1"'},
|
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)
|
||||||
|
|||||||
@@ -45,6 +45,17 @@
|
|||||||
" x-text="copiedUninstall ? 'Copied!' : 'Copy'" class="secondary outline"></button>
|
" x-text="copiedUninstall ? 'Copied!' : 'Copy'" class="secondary outline"></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h2>Scripts</h2>
|
||||||
|
<a href="/printers/{{ printer.id }}/scripts/install.ps1" role="button" class="secondary">
|
||||||
|
Download Install Script
|
||||||
|
</a>
|
||||||
|
<a href="/printers/{{ printer.id }}/scripts/uninstall.ps1" role="button" class="secondary">
|
||||||
|
Download Uninstall Script
|
||||||
|
</a>
|
||||||
|
<a href="/printers/{{ printer.id }}/scripts/detect.ps1" role="button" class="secondary">
|
||||||
|
Download Detect Script
|
||||||
|
</a>
|
||||||
|
|
||||||
<h2>Export</h2>
|
<h2>Export</h2>
|
||||||
<a href="/printers/{{ printer.id }}/packages/ninja" role="button">Download NinjaRMM ZIP</a>
|
<a href="/printers/{{ printer.id }}/packages/ninja" role="button">Download NinjaRMM ZIP</a>
|
||||||
<a href="/printers/{{ printer.id }}/packages/intunewin" role="button">Download .intunewin</a>
|
<a href="/printers/{{ printer.id }}/packages/intunewin" role="button">Download .intunewin</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user