Revert "feat: Add inline editing and manual script entry functionality (#39)" (#40)

This reverts commit a410aeacf7.
This commit is contained in:
Michel Roegl-Brunner
2025-10-06 16:21:49 +02:00
committed by GitHub
parent a410aeacf7
commit a05185db1b
98 changed files with 2328 additions and 3323 deletions

40
.gitattributes vendored
View File

@@ -1,40 +0,0 @@
# Set default behavior to automatically normalize line endings
* text=auto
# Shell scripts should always use LF
*.sh text eol=lf
*.func text eol=lf
*.bash text eol=lf
# Windows batch files should use CRLF
*.bat text eol=crlf
*.cmd text eol=crlf
# Configuration files should use LF
*.conf text eol=lf
*.config text eol=lf
*.ini text eol=lf
*.toml text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.json text eol=lf
# Source code files should use LF
*.js text eol=lf
*.ts text eol=lf
*.tsx text eol=lf
*.jsx text eol=lf
*.css text eol=lf
*.scss text eol=lf
*.html text eol=lf
*.xml text eol=lf
# Binary files
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.db binary
*.exe binary
*.dll binary

View File

@@ -1,43 +0,0 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(dirname "$0")"
source "$SCRIPT_DIR/../core/build.func"
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://www.debian.org/
APP="Debian"
var_tags="${var_tags:-os}"
var_cpu="${var_cpu:-1}"
var_ram="${var_ram:-512}"
var_disk="${var_disk:-2}"
var_os="${var_os:-debian}"
var_version="${var_version:-13}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
variables
color
catch_errors
function update_script() {
header_info
check_container_storage
check_container_resources
if [[ ! -d /var ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
msg_info "Updating $APP LXC"
$STD apt update
$STD apt -y upgrade
msg_ok "Updated $APP LXC"
exit
}
start
build_container
description
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"

View File

@@ -1,24 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2021-2025 tteck
# Author: tteck (tteckster)
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# Source: https://www.debian.org/
source /dev/stdin <<<"$FUNCTIONS_FILE_PATH"
color
verb_ip6
catch_errors
setting_up_container
network_check
update_os
motd_ssh
customize
msg_info "Cleaning up"
$STD apt -y autoremove
$STD apt -y autoclean
$STD apt -y clean
msg_ok "Cleaned"

View File

@@ -23,7 +23,7 @@
"ram": 512,
"hdd": 2,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -23,7 +23,7 @@
"ram": 2048,
"hdd": 4,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -1,5 +1,5 @@
{
"name": "PVE LXC Tag",
"name": "Proxmox VE LXC Tag",
"slug": "add-iptag",
"categories": [
1

View File

@@ -23,7 +23,7 @@
"ram": 512,
"hdd": 2,
"os": "debian",
"version": "13"
"version": "12"
}
},
{
@@ -44,7 +44,7 @@
},
"notes": [
{
"text": "AdGuard Home can only be updated via the user interface.",
"text": "Adguard Home can be updated via the user interface.",
"type": "info"
}
]

View File

@@ -23,7 +23,7 @@
"ram": 2048,
"hdd": 7,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -23,7 +23,7 @@
"ram": 2048,
"hdd": 4,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -20,7 +20,7 @@
"script": "ct/booklore.sh",
"resources": {
"cpu": 3,
"ram": 3072,
"ram": 2048,
"hdd": 7,
"os": "debian",
"version": "12"

View File

@@ -4,7 +4,7 @@
"categories": [
21
],
"date_created": "2025-09-17",
"date_created": "2024-05-11",
"type": "ct",
"updateable": true,
"privileged": false,
@@ -21,21 +21,10 @@
"resources": {
"cpu": 1,
"ram": 512,
"hdd": 6,
"hdd": 4,
"os": "debian",
"version": "12"
}
},
{
"type": "alpine",
"script": "ct/alpine-caddy.sh",
"resources": {
"cpu": 1,
"ram": 256,
"hdd": 3,
"os": "alpine",
"version": "3.22"
}
}
],
"default_credentials": {

View File

@@ -1,5 +1,5 @@
{
"name": "PVE LXC Cleaner",
"name": "Proxmox VE LXC Cleaner",
"slug": "clean-lxcs",
"categories": [
1

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Clean Orphaned LVM",
"name": "Proxmox Clean Orphaned LVM",
"slug": "clean-orphaned-lvm",
"categories": [
1

View File

@@ -23,7 +23,7 @@
"ram": 512,
"hdd": 2,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -23,7 +23,7 @@
"ram": 1024,
"hdd": 4,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -32,10 +32,5 @@
"username": null,
"password": null
},
"notes": [
{
"type": "info",
"text": "The file `/etc/sysconfig/CosmosCloud` is optional. If you need custom settings, you can create it yourself."
}
]
"notes": []
}

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Cron LXC Updater",
"name": "Proxmox VE Cron LXC Updater",
"slug": "cron-update-lxcs",
"categories": [
1
@@ -13,7 +13,7 @@
"website": null,
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/proxmox.webp",
"config_path": "",
"description": "This script will add/remove a crontab schedule that updates the operating system of all LXCs every Sunday at midnight.",
"description": "This script will add/remove a crontab schedule that updates all LXCs every Sunday at midnight.",
"install_methods": [
{
"type": "default",

View File

@@ -23,7 +23,7 @@
"ram": 512,
"hdd": 2,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -39,10 +39,6 @@
{
"type": "info",
"text": "Synapse-Admin is running on port 5173"
},
{
"type": "info",
"text": "For bridges Installation methods (WhatsApp, Signal, Discord, etc.), see: ´https://docs.mau.fi/bridges/go/setup.html´"
}
]
}

View File

@@ -1,5 +1,5 @@
{
"name": "PVE LXC Filesystem Trim",
"name": "Proxmox VE LXC Filesystem Trim",
"slug": "fstrim",
"categories": [
1

View File

@@ -1,52 +0,0 @@
{
"name": "Ghostfolio",
"slug": "ghostfolio",
"categories": [
23
],
"date_created": "2025-09-29",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 3333,
"documentation": "https://github.com/ghostfolio/ghostfolio?tab=readme-ov-file#self-hosting",
"website": "https://ghostfol.io/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/ghostfolio.webp",
"config_path": "/opt/ghostfolio/.env",
"description": "Ghostfolio is an open source wealth management software built with web technology. The application empowers busy people to keep track of stocks, ETFs or cryptocurrencies and make solid, data-driven investment decisions.",
"install_methods": [
{
"type": "default",
"script": "ct/ghostfolio.sh",
"resources": {
"cpu": 2,
"ram": 4096,
"hdd": 8,
"os": "debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "Create your first user account by visiting the web interface and clicking 'Get Started'. The first user will automatically get admin privileges.",
"type": "info"
},
{
"text": "Database and Redis credentials: `cat ~/ghostfolio.creds`",
"type": "info"
},
{
"text": "Optional: CoinGecko API keys can be added during installation or later in the .env file for enhanced cryptocurrency data.",
"type": "info"
},
{
"text": "Build process requires 4GB RAM (runtime: ~2GB). A temporary swap file will be created automatically if insufficient memory is detected.",
"type": "warning"
}
]
}

View File

@@ -1,35 +0,0 @@
{
"name": "GlobaLeaks",
"slug": "globaleaks",
"categories": [
0
],
"date_created": "2025-09-18",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 443,
"documentation": "https://docs.globaleaks.org",
"website": "https://www.globaleaks.org/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/globaleaks.webp",
"config_path": "",
"description": "GlobaLeaks is a free and open-source whistleblowing software enabling anyone to easily set up and maintain a secure reporting platform.",
"install_methods": [
{
"type": "default",
"script": "ct/globaleaks.sh",
"resources": {
"cpu": 2,
"ram": 1024,
"hdd": 4,
"os": "debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": []
}

View File

@@ -1,40 +0,0 @@
{
"name": "GoAway",
"slug": "goaway",
"categories": [
5
],
"date_created": "2025-09-25",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 8080,
"documentation": "https://github.com/pommee/goaway#configuration-file",
"config_path": "/opt/goaway/config/settings.yaml",
"website": "https://github.com/pommee/goaway",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/goaway.webp",
"description": "Lightweight DNS sinkhole written in Go with a modern dashboard client. Very good looking new alternative to Pi-Hole and Adguard Home.",
"install_methods": [
{
"type": "default",
"script": "ct/goaway.sh",
"resources": {
"cpu": 1,
"ram": 1024,
"hdd": 4,
"os": "Debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "Type `cat ~/goaway.creds` to see login credentials.",
"type": "info"
}
]
}

View File

@@ -13,7 +13,7 @@
"website": "https://www.getgrist.com/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/grist.webp",
"config_path": "/opt/grist/.env",
"description": "Grist is like a spreadsheet + database hybrid. It lets you store structured data, use relational links between tables, apply formulas (even with Python), build custom layouts (cards, forms, dashboards), set fine-grained access rules, and visualize data with charts or pivot-tables.",
"description": "Grist is a modern, open source spreadsheet that goes beyond the grid",
"install_methods": [
{
"type": "default",

View File

@@ -32,10 +32,6 @@
"password": null
},
"notes": [
{
"text": "Containerized version doesn't allow Home Assistant add-ons.",
"type": "warning"
},
{
"text": "If the LXC is created Privileged, the script will automatically set up USB passthrough.",
"type": "warning"

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Host Backup",
"name": "Proxmox VE Host Backup",
"slug": "host-backup",
"categories": [
1

View File

@@ -23,7 +23,7 @@
"ram": 4096,
"hdd": 20,
"os": "Debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -1,40 +0,0 @@
{
"name": "Joplin Server",
"slug": "joplin-server",
"categories": [
12
],
"date_created": "2025-09-24",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 22300,
"documentation": "https://joplinapp.org/help/",
"config_path": "/opt/joplin-server/.env",
"website": "https://joplinapp.org/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/joplin.webp",
"description": "Joplin - the privacy-focused note taking app with sync capabilities for Windows, macOS, Linux, Android and iOS.",
"install_methods": [
{
"type": "default",
"script": "ct/joplin-server.sh",
"resources": {
"cpu": 2,
"ram": 4096,
"hdd": 20,
"os": "Debian",
"version": "12"
}
}
],
"default_credentials": {
"username": "admin@localhost",
"password": "admin"
},
"notes": [
{
"text": "Application can take some time to build, depending on your host speed. Please be patient.",
"type": "info"
}
]
}

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Kernel Clean",
"name": "Proxmox VE Kernel Clean",
"slug": "kernel-clean",
"categories": [
1

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Kernel Pin",
"name": "Proxmox VE Kernel Pin",
"slug": "kernel-pin",
"categories": [
1

View File

@@ -23,7 +23,7 @@
"ram": 2048,
"hdd": 4,
"os": "Debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -1,5 +1,5 @@
{
"name": "PVE LXC Deletion",
"name": "Container LXC Deletion",
"slug": "lxc-delete",
"categories": [
1

View File

@@ -1,48 +0,0 @@
{
"name": "PVE LXC Execute Command",
"slug": "lxc-execute",
"categories": [
1
],
"date_created": "2025-09-18",
"type": "pve",
"updateable": false,
"privileged": false,
"interface_port": null,
"documentation": null,
"website": null,
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/proxmox.webp",
"config_path": "",
"description": "This script allows administrators to execute a custom command inside one or multiple LXC containers on a Proxmox VE node. Containers can be selectively excluded via an interactive checklist. If a container is stopped, the script will automatically start it, run the command, and then shut it down again. Only Debian and Ubuntu based containers are supported.",
"install_methods": [
{
"type": "default",
"script": "tools/pve/execute.sh",
"resources": {
"cpu": null,
"ram": null,
"hdd": null,
"os": null,
"version": null
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "Execute within the Proxmox shell.",
"type": "info"
},
{
"text": "Non-Debian/Ubuntu containers will be skipped automatically.",
"type": "info"
},
{
"text": "Stopped containers will be started temporarily to run the command, then shut down again.",
"type": "warning"
}
]
}

View File

@@ -1,186 +1,31 @@
{
"categories": [
{
"name": "Proxmox & Virtualization",
"id": 1,
"sort_order": 1.0,
"description": "Tools and scripts to manage Proxmox VE and virtualization platforms effectively.",
"icon": "server"
},
{
"name": "Operating Systems",
"id": 2,
"sort_order": 2.0,
"description": "Scripts for deploying and managing various operating systems.",
"icon": "monitor"
},
{
"name": "Containers & Docker",
"id": 3,
"sort_order": 3.0,
"description": "Solutions for containerization using Docker and related technologies.",
"icon": "box"
},
{
"name": "Network & Firewall",
"id": 4,
"sort_order": 4.0,
"description": "Enhance network security and configure firewalls with ease.",
"icon": "shield"
},
{
"name": "Adblock & DNS",
"id": 5,
"sort_order": 5.0,
"description": "Optimize your network with DNS and ad-blocking solutions.",
"icon": "ban"
},
{
"name": "Authentication & Security",
"id": 6,
"sort_order": 6.0,
"description": "Secure your infrastructure with authentication and security tools.",
"icon": "lock"
},
{
"name": "Backup & Recovery",
"id": 7,
"sort_order": 7.0,
"description": "Reliable backup and recovery scripts to protect your data.",
"icon": "archive"
},
{
"name": "Databases",
"id": 8,
"sort_order": 8.0,
"description": "Deploy and manage robust database systems with ease.",
"icon": "database"
},
{
"name": "Monitoring & Analytics",
"id": 9,
"sort_order": 9.0,
"description": "Monitor system performance and analyze data seamlessly.",
"icon": "bar-chart"
},
{
"name": "Dashboards & Frontends",
"id": 10,
"sort_order": 10.0,
"description": "Create interactive dashboards and user-friendly frontends.",
"icon": "layout"
},
{
"name": "Files & Downloads",
"id": 11,
"sort_order": 11.0,
"description": "Manage file sharing and downloading solutions efficiently.",
"icon": "download"
},
{
"name": "Documents & Notes",
"id": 12,
"sort_order": 12.0,
"description": "Organize and manage documents and note-taking tools.",
"icon": "file-text"
},
{
"name": "Media & Streaming",
"id": 13,
"sort_order": 13.0,
"description": "Stream and manage media effortlessly across devices.",
"icon": "play"
},
{
"name": "*Arr Suite",
"id": 14,
"sort_order": 14.0,
"description": "Automated media management with the popular *Arr suite tools.",
"icon": "tv"
},
{
"name": "NVR & Cameras",
"id": 15,
"sort_order": 15.0,
"description": "Manage network video recorders and camera setups.",
"icon": "camera"
},
{
"name": "IoT & Smart Home",
"id": 16,
"sort_order": 16.0,
"description": "Control and automate IoT devices and smart home systems.",
"icon": "home"
},
{
"name": "ZigBee, Z-Wave & Matter",
"id": 17,
"sort_order": 17.0,
"description": "Solutions for ZigBee, Z-Wave, and Matter-based device management.",
"icon": "radio"
},
{
"name": "MQTT & Messaging",
"id": 18,
"sort_order": 18.0,
"description": "Set up reliable messaging and MQTT-based communication systems.",
"icon": "message-circle"
},
{
"name": "Automation & Scheduling",
"id": 19,
"sort_order": 19.0,
"description": "Automate tasks and manage scheduling with powerful tools.",
"icon": "clock"
},
{
"name": "AI / Coding & Dev-Tools",
"id": 20,
"sort_order": 20.0,
"description": "Leverage AI and developer tools for smarter coding workflows.",
"icon": "code"
},
{
"name": "Webservers & Proxies",
"id": 21,
"sort_order": 21.0,
"description": "Deploy and configure web servers and proxy solutions.",
"icon": "globe"
},
{
"name": "Bots & ChatOps",
"id": 22,
"sort_order": 22.0,
"description": "Enhance collaboration with bots and ChatOps integrations.",
"icon": "bot"
},
{
"name": "Finance & Budgeting",
"id": 23,
"sort_order": 23.0,
"description": "Track expenses and manage budgets efficiently.",
"icon": "dollar-sign"
},
{
"name": "Gaming & Leisure",
"id": 24,
"sort_order": 24.0,
"description": "Scripts for gaming servers and leisure-related tools.",
"icon": "gamepad-2"
},
{
"name": "Business & ERP",
"id": 25,
"sort_order": 25.0,
"description": "Streamline business operations with ERP and management tools.",
"icon": "building"
},
{
"name": "Miscellaneous",
"id": 0,
"sort_order": 99.0,
"description": "General scripts and tools that don't fit into other categories.",
"icon": "more-horizontal"
}
{ "name": "Proxmox & Virtualization", "id": 1, "sort_order": 1.0, "description": "Tools and scripts to manage Proxmox VE and virtualization platforms effectively." },
{ "name": "Operating Systems", "id": 2, "sort_order": 2.0, "description": "Scripts for deploying and managing various operating systems." },
{ "name": "Containers & Docker", "id": 3, "sort_order": 3.0, "description": "Solutions for containerization using Docker and related technologies." },
{ "name": "Network & Firewall", "id": 4, "sort_order": 4.0, "description": "Enhance network security and configure firewalls with ease." },
{ "name": "Adblock & DNS", "id": 5, "sort_order": 5.0, "description": "Optimize your network with DNS and ad-blocking solutions." },
{ "name": "Authentication & Security", "id": 6, "sort_order": 6.0, "description": "Secure your infrastructure with authentication and security tools." },
{ "name": "Backup & Recovery", "id": 7, "sort_order": 7.0, "description": "Reliable backup and recovery scripts to protect your data." },
{ "name": "Databases", "id": 8, "sort_order": 8.0, "description": "Deploy and manage robust database systems with ease." },
{ "name": "Monitoring & Analytics", "id": 9, "sort_order": 9.0, "description": "Monitor system performance and analyze data seamlessly." },
{ "name": "Dashboards & Frontends", "id": 10, "sort_order": 10.0, "description": "Create interactive dashboards and user-friendly frontends." },
{ "name": "Files & Downloads", "id": 11, "sort_order": 11.0, "description": "Manage file sharing and downloading solutions efficiently." },
{ "name": "Documents & Notes", "id": 12, "sort_order": 12.0, "description": "Organize and manage documents and note-taking tools." },
{ "name": "Media & Streaming", "id": 13, "sort_order": 13.0, "description": "Stream and manage media effortlessly across devices." },
{ "name": "*Arr Suite", "id": 14, "sort_order": 14.0, "description": "Automated media management with the popular *Arr suite tools." },
{ "name": "NVR & Cameras", "id": 15, "sort_order": 15.0, "description": "Manage network video recorders and camera setups." },
{ "name": "IoT & Smart Home", "id": 16, "sort_order": 16.0, "description": "Control and automate IoT devices and smart home systems." },
{ "name": "ZigBee, Z-Wave & Matter", "id": 17, "sort_order": 17.0, "description": "Solutions for ZigBee, Z-Wave, and Matter-based device management." },
{ "name": "MQTT & Messaging", "id": 18, "sort_order": 18.0, "description": "Set up reliable messaging and MQTT-based communication systems." },
{ "name": "Automation & Scheduling", "id": 19, "sort_order": 19.0, "description": "Automate tasks and manage scheduling with powerful tools." },
{ "name": "AI / Coding & Dev-Tools", "id": 20, "sort_order": 20.0, "description": "Leverage AI and developer tools for smarter coding workflows." },
{ "name": "Webservers & Proxies", "id": 21, "sort_order": 21.0, "description": "Deploy and configure web servers and proxy solutions." },
{ "name": "Bots & ChatOps", "id": 22, "sort_order": 22.0, "description": "Enhance collaboration with bots and ChatOps integrations." },
{ "name": "Finance & Budgeting", "id": 23, "sort_order": 23.0, "description": "Track expenses and manage budgets efficiently." },
{ "name": "Gaming & Leisure", "id": 24, "sort_order": 24.0, "description": "Scripts for gaming servers and leisure-related tools." },
{ "name": "Business & ERP", "id": 25, "sort_order": 25.0, "description": "Streamline business operations with ERP and management tools." },
{ "name": "Miscellaneous", "id": 0, "sort_order": 99.0, "description": "General scripts and tools that don't fit into other categories." }
]
}

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Processor Microcode",
"name": "Proxmox VE Processor Microcode",
"slug": "microcode",
"categories": [
1

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Monitor-All",
"name": "Proxmox VE Monitor-All",
"slug": "monitor-all",
"categories": [
1

View File

@@ -1,35 +0,0 @@
{
"name": "MyIP",
"slug": "myip",
"categories": [
4
],
"date_created": "2025-09-29",
"type": "ct",
"updateable": true,
"privileged": false,
"config_path": "/opt/myip/.env",
"interface_port": 18966,
"documentation": "https://github.com/jason5ng32/MyIP#-environment-variable",
"website": "https://ipcheck.ing/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/myip.webp",
"description": "The best IP Toolbox. Easy to check what's your IPs, IP geolocation, check for DNS leaks, examine WebRTC connections, speed test, ping test, MTR test, check website availability, whois search and more!",
"install_methods": [
{
"type": "default",
"script": "ct/myip.sh",
"resources": {
"cpu": 1,
"ram": 512,
"hdd": 2,
"os": "Debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": []
}

View File

@@ -23,7 +23,7 @@
"ram": 1024,
"hdd": 4,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Netdata",
"name": "Proxmox VE Netdata",
"slug": "netdata",
"categories": [
1

View File

@@ -23,7 +23,7 @@
"ram": 1024,
"hdd": 4,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -23,7 +23,7 @@
"ram": 1024,
"hdd": 4,
"os": "debian",
"version": "13"
"version": "12"
}
},
{

View File

@@ -23,7 +23,7 @@
"ram": 512,
"hdd": 2,
"os": "debian",
"version": "13"
"version": "12"
}
}
],

View File

@@ -31,10 +31,5 @@
"username": null,
"password": null
},
"notes": [
{
"text": "Script contains optional installation of Ollama.",
"type": "info"
}
]
"notes": []
}

View File

@@ -20,7 +20,7 @@
"script": "ct/overseerr.sh",
"resources": {
"cpu": 2,
"ram": 4096,
"ram": 2048,
"hdd": 8,
"os": "debian",
"version": "12"

View File

@@ -1,5 +1,5 @@
{
"name": "PBS Processor Microcode",
"name": "Proxmox Backup Server Processor Microcode",
"slug": "pbs-microcode",
"categories": [
1

View File

@@ -1,44 +0,0 @@
{
"name": "PhpMyAdmin",
"slug": "phpmyadmin",
"categories": [
8
],
"date_created": "2025-10-01",
"type": "addon",
"updateable": true,
"privileged": false,
"interface_port": null,
"documentation": "https://www.phpmyadmin.net/docs/",
"config_path": "Debian/Ubuntu: /var/www/html/phpMyAdmin | Alpine: /usr/share/phpmyadmin",
"website": "https://www.phpmyadmin.net/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/phpmyadmin.webp",
"description": "phpMyAdmin is a free software tool written in PHP, intended to handle the administration of MySQL over the Web. phpMyAdmin supports a wide range of operations on MySQL and MariaDB. Frequently used operations (managing databases, tables, columns, relations, indexes, users, permissions, etc) can be performed via the user interface, while you still have the ability to directly execute any SQL statement.",
"install_methods": [
{
"type": "default",
"script": "tools/addon/phpmyadmin.sh",
"resources": {
"cpu": null,
"ram": null,
"hdd": null,
"os": null,
"version": null
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "Execute within an existing LXC Console",
"type": "warning"
},
{
"text": "To update or uninstall run bash call again",
"type": "info"
}
]
}

View File

@@ -1,5 +1,5 @@
{
"name": "PBS Post Install",
"name": "Proxmox Backup Server Post Install",
"slug": "post-pbs-install",
"categories": [
1
@@ -13,7 +13,7 @@
"website": null,
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/proxmox.webp",
"config_path": "",
"description": "The script is designed for Proxmox Backup Server (PBS) and will give options to Disable the Enterprise Repo, Add/Correct PBS Sources, Enable the No-Subscription Repo, Add Test Repo, Disable Subscription Nag, Update Proxmox Backup Server and Reboot PBS.",
"description": "The script will give options to Disable the Enterprise Repo, Add/Correct PBS Sources, Enable the No-Subscription Repo, Add Test Repo, Disable Subscription Nag, Update Proxmox Backup Server and Reboot PBS.",
"install_methods": [
{
"type": "default",

View File

@@ -1,5 +1,5 @@
{
"name": "PMG Post Install",
"name": "Proxmox Mail Gateway Post Install",
"slug": "post-pmg-install",
"categories": [
1
@@ -13,7 +13,7 @@
"website": null,
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/proxmox.webp",
"config_path": "",
"description": "The script is designed for Proxmox Mail Gateway and will give options to Disable the Enterprise Repo, Add/Correct PMG Sources, Enable the No-Subscription Repo, Add Test Repo, Disable Subscription Nag, Update Proxmox Mail Gateway and Reboot PMG.",
"description": "The script will give options to Disable the Enterprise Repo, Add/Correct PMG Sources, Enable the No-Subscription Repo, Add Test Repo, Disable Subscription Nag, Update Proxmox Mail Gateway and Reboot PMG.",
"install_methods": [
{
"type": "default",

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Post Install",
"name": "Proxmox VE Post Install",
"slug": "post-pve-install",
"categories": [
1

View File

@@ -46,10 +46,6 @@
{
"text": "Set a password after installation for postgres user by running `echo \"ALTER USER postgres with encrypted password 'your_password';\" | sudo -u postgres psql`",
"type": "info"
},
{
"text": "Debian script offers versions `15, 16, 17, 18`, while Alpine script offers versions `15, 16, 17`.",
"type": "info"
}
]
}

View File

@@ -1,5 +1,5 @@
{
"name": "Proxmox Backup Server (PBS)",
"name": "Proxmox Backup Server",
"slug": "proxmox-backup-server",
"categories": [
1

View File

@@ -1,5 +1,5 @@
{
"name": "Proxmox Datacenter Manager (PDM)",
"name": "Proxmox Datacenter Manager",
"slug": "proxmox-datacenter-manager",
"categories": [
1

View File

@@ -1,5 +1,5 @@
{
"name": "Proxmox Mail Gateway (PMG)",
"name": "Proxmox Mail Gateway",
"slug": "proxmox-mail-gateway",
"categories": [
1

View File

@@ -1,35 +0,0 @@
{
"name": "PVEScriptsLocal",
"slug": "pve-scripts-local",
"categories": [
1
],
"date_created": "2025-10-03",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 3000,
"documentation": "https://github.com/community-scripts/ProxmoxVE-Local",
"config_path": "/opt/PVEScripts-Local/.env",
"website": "https://community-scripts.github.io/ProxmoxVE",
"logo": "https://raw.githubusercontent.com/community-scripts/ProxmoxVE-Local/refs/heads/main/.github/logo.png",
"description": "A modern web-based management interface for Proxmox VE (PVE) helper scripts. This tool provides a user-friendly way to discover, download, and execute community-sourced Proxmox scripts locally with real-time terminal output streaming.",
"install_methods": [
{
"type": "default",
"script": "ct/pve-scripts-local.sh",
"resources": {
"cpu": 2,
"ram": 4096,
"hdd": 4,
"os": "Debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": []
}

View File

@@ -1,5 +1,5 @@
{
"name": "PVE CPU Scaling Governor",
"name": "Proxmox VE CPU Scaling Governor",
"slug": "scaling-governor",
"categories": [
1

View File

@@ -10,7 +10,7 @@
"privileged": false,
"interface_port": 3000,
"documentation": "https://tracktor.bytedge.in/introduction.html",
"config_path": "/opt/tracktor.env",
"config_path": "/opt/tracktor/app/server/.env",
"website": "https://tracktor.bytedge.in/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/tracktor.webp",
"description": "Tracktor is an open-source web application for comprehensive vehicle management.\nEasily track fuel consumption, maintenance, insurance, and regulatory documents for all your vehicles in one place.",
@@ -23,17 +23,17 @@
"ram": 1024,
"hdd": 6,
"os": "Debian",
"version": "13"
"version": "12"
}
}
],
"default_credentials": {
"username": null,
"password": "123456"
"password": null
},
"notes": [
{
"text": "Please check and update the '/opt/tracktor.env' file if using behind reverse proxy.",
"text": "Please check and update the '/opt/tracktor/app/backend/.env' file if using behind reverse proxy.",
"type": "info"
}
]

View File

@@ -1,35 +0,0 @@
{
"name": "Tunarr",
"slug": "tunarr",
"categories": [
13
],
"date_created": "2025-09-19",
"type": "ct",
"updateable": true,
"privileged": false,
"config_path": "/opt/tunarr/.env",
"interface_port": 8000,
"documentation": "https://tunarr.com/",
"website": "https://tunarr.com/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/tunarr.webp",
"description": "Create a classic TV experience using your own media - IPTV backed by Plex/Jellyfin/Emby.",
"install_methods": [
{
"type": "default",
"script": "ct/tunarr.sh",
"resources": {
"cpu": 2,
"ram": 1024,
"hdd": 5,
"os": "Debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": []
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
{
"name": "PVE LXC Updater",
"name": "Proxmox VE LXC Updater",
"slug": "update-lxcs",
"categories": [
1
@@ -13,7 +13,7 @@
"website": null,
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/linuxcontainers.webp",
"config_path": "",
"description": "This script has been created to simplify and speed up the process of updating the operating system running inside LXC containers across various Linux distributions, such as Ubuntu, Debian, Devuan, Alpine Linux, CentOS-Rocky-Alma, Fedora, and ArchLinux. It's designed to automatically skip templates and specific containers during the update, enhancing its convenience and usability.",
"description": "This script has been created to simplify and speed up the process of updating all LXC containers across various Linux distributions, such as Ubuntu, Debian, Devuan, Alpine Linux, CentOS-Rocky-Alma, Fedora, and ArchLinux. It's designed to automatically skip templates and specific containers during the update, enhancing its convenience and usability.",
"install_methods": [
{
"type": "default",
@@ -35,10 +35,6 @@
{
"text": "Execute within the Proxmox shell",
"type": "info"
},
{
"text": "The script updates only the operating system of the LXC container. It DOES NOT update the application installed within the container!",
"type": "warning"
}
]
}

View File

@@ -1,5 +1,5 @@
{
"name": "PVE Update Repositories",
"name": "Proxmox Update Repositories",
"slug": "update-repo",
"categories": [
1

View File

@@ -1,40 +0,0 @@
{
"name": "UpSnap",
"slug": "upsnap",
"categories": [
4
],
"date_created": "2025-09-23",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 8090,
"documentation": "https://github.com/seriousm4x/UpSnap/wiki",
"config_path": "",
"website": "https://github.com/seriousm4x/UpSnap",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/upsnap.webp",
"description": "UpSnap is a self-hosted web app that lets you wake up, manage and monitor devices on your network with ease. Built with SvelteKit, Go and PocketBase, it offers a clean dashboard, scheduled wake-ups, device discovery and secure user management.",
"install_methods": [
{
"type": "default",
"script": "ct/upsnap.sh",
"resources": {
"cpu": 1,
"ram": 512,
"hdd": 2,
"os": "Debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "The first user you register will be the admin user.",
"type": "info"
}
]
}

View File

@@ -1,40 +0,0 @@
{
"name": "Verdaccio",
"slug": "verdaccio",
"categories": [
20
],
"date_created": "2025-09-29",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 4873,
"documentation": "https://verdaccio.org/docs/what-is-verdaccio",
"website": "https://verdaccio.org/",
"logo": "https://verdaccio.org/img/logo/symbol/png/verdaccio-tiny.png",
"config_path": "/opt/verdaccio/config/config.yaml",
"description": "Verdaccio is a lightweight private npm proxy registry built with Node.js. It allows you to host your own npm registry with minimal configuration, providing a private npm repository for your projects. Verdaccio supports npm, yarn, and pnpm, and can cache packages from the public npm registry, allowing for faster installs and protection against npm registry outages. It includes a web interface for browsing packages, authentication and authorization features, and can be easily integrated into your development workflow.",
"install_methods": [
{
"type": "default",
"script": "ct/verdaccio.sh",
"resources": {
"cpu": 2,
"ram": 2048,
"hdd": 8,
"os": "debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "To create the first user, run: npm adduser --registry http://<container-ip>:4873",
"type": "info"
}
]
}

View File

@@ -1,40 +0,0 @@
{
"name": "Warracker",
"slug": "warracker",
"categories": [
12
],
"date_created": "2025-09-29",
"type": "ct",
"updateable": true,
"privileged": false,
"interface_port": 80,
"documentation": null,
"config_path": "/opt/.env",
"website": "https://warracker.com/",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons/webp/warracker.webp",
"description": "Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!",
"install_methods": [
{
"type": "default",
"script": "ct/warracker.sh",
"resources": {
"cpu": 1,
"ram": 512,
"hdd": 4,
"os": "Debian",
"version": "13"
}
}
],
"default_credentials": {
"username": null,
"password": null
},
"notes": [
{
"text": "The first user you register will be the admin user.",
"type": "info"
}
]
}

View File

@@ -21,7 +21,7 @@
"resources": {
"cpu": 4,
"ram": 4096,
"hdd": 25,
"hdd": 18,
"os": "debian",
"version": "12"
}

View File

@@ -23,7 +23,7 @@
"ram": 4096,
"hdd": 6,
"os": "debian",
"version": "13"
"version": "12"
}
}
],
@@ -33,19 +33,11 @@
},
"notes": [
{
"text": "Database credentials: `cat ~/zabbix.creds`",
"text": "Database credentials: `cat zabbix.creds`",
"type": "info"
},
{
"text": "You can choose between Zabbix agent (classic) and agent2 (modern) during installation",
"type": "info"
},
{
"text": "For agent2 the PostgreSQL plugin is installed by default; all plugins are optional",
"type": "info"
},
{
"text": "If agent2 with NVIDIA plugin is installed in an environment without GPU, the installer disables it automatically",
"text": "Zabbix agent 2 is used by default",
"type": "info"
}
]

50
src/__tests__/env.test.ts Normal file
View File

@@ -0,0 +1,50 @@
import { describe, it, expect, vi } from 'vitest'
// Mock the environment variables
const mockEnv = {
SCRIPTS_DIRECTORY: '/test/scripts',
ALLOWED_SCRIPT_EXTENSIONS: '.sh,.py,.js,.ts',
ALLOWED_SCRIPT_PATHS: '/,/ct/',
MAX_SCRIPT_EXECUTION_TIME: '30000',
REPO_URL: 'https://github.com/test/repo',
NODE_ENV: 'test',
}
vi.mock('~/env.js', () => ({
env: mockEnv,
}))
describe('Environment Configuration', () => {
it('should have required environment variables', async () => {
const { env } = await import('~/env.js')
expect(env.SCRIPTS_DIRECTORY).toBeDefined()
expect(env.ALLOWED_SCRIPT_EXTENSIONS).toBeDefined()
expect(env.ALLOWED_SCRIPT_PATHS).toBeDefined()
expect(env.MAX_SCRIPT_EXECUTION_TIME).toBeDefined()
})
it('should have correct script directory path', async () => {
const { env } = await import('~/env.js')
expect(env.SCRIPTS_DIRECTORY).toBe('/test/scripts')
})
it('should have correct allowed extensions', async () => {
const { env } = await import('~/env.js')
expect(env.ALLOWED_SCRIPT_EXTENSIONS).toBe('.sh,.py,.js,.ts')
})
it('should have correct allowed paths', async () => {
const { env } = await import('~/env.js')
expect(env.ALLOWED_SCRIPT_PATHS).toBe('/,/ct/')
})
it('should have correct max execution time', async () => {
const { env } = await import('~/env.js')
expect(env.MAX_SCRIPT_EXECUTION_TIME).toBe('30000')
})
})

View File

@@ -0,0 +1,140 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import Home from '../page'
// Mock tRPC
vi.mock('~/trpc/react', () => ({
api: {
scripts: {
getRepoStatus: {
useQuery: vi.fn(() => ({
data: { isRepo: true, isBehind: false, branch: 'main', lastCommit: 'abc123' },
refetch: vi.fn(),
})),
},
getScriptCards: {
useQuery: vi.fn(() => ({
data: { success: true, cards: [] },
isLoading: false,
error: null,
})),
},
getCtScripts: {
useQuery: vi.fn(() => ({
data: { scripts: [] },
isLoading: false,
error: null,
})),
},
getScriptBySlug: {
useQuery: vi.fn(() => ({
data: null,
})),
},
checkProxmoxVE: {
useQuery: vi.fn(() => ({
data: { success: true, isProxmoxVE: true },
isLoading: false,
error: null,
})),
},
fullUpdateRepo: {
useMutation: vi.fn(() => ({
mutate: vi.fn(),
})),
},
},
},
}))
// Mock child components
vi.mock('../_components/ScriptsGrid', () => ({
ScriptsGrid: ({ onInstallScript }: { onInstallScript?: (path: string, name: string) => void }) => (
<div data-testid="scripts-grid">
<button onClick={() => onInstallScript?.('/test/path', 'test-script')}>
Run Script
</button>
</div>
),
}))
vi.mock('../_components/ResyncButton', () => ({
ResyncButton: () => <div data-testid="resync-button">Resync Button</div>,
}))
vi.mock('../_components/Terminal', () => ({
Terminal: ({ scriptPath, onClose }: { scriptPath: string; onClose: () => void }) => (
<div data-testid="terminal">
<div>Terminal for: {scriptPath}</div>
<button onClick={onClose}>Close Terminal</button>
</div>
),
}))
describe('Home Page', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should render main page elements', () => {
render(<Home />)
expect(screen.getByText('🚀 PVE Scripts Management')).toBeInTheDocument()
expect(screen.getByText('Manage and execute Proxmox helper scripts locally with live output streaming')).toBeInTheDocument()
expect(screen.getByTestId('resync-button')).toBeInTheDocument()
expect(screen.getByTestId('scripts-grid')).toBeInTheDocument()
})
it('should not show terminal initially', () => {
render(<Home />)
expect(screen.queryByTestId('terminal')).not.toBeInTheDocument()
})
it('should show terminal when script is run', () => {
render(<Home />)
const runButton = screen.getByText('Run Script')
fireEvent.click(runButton)
expect(screen.getByTestId('terminal')).toBeInTheDocument()
expect(screen.getByText('Terminal for: /test/path')).toBeInTheDocument()
})
it('should close terminal when close button is clicked', () => {
render(<Home />)
// First run a script to show terminal
const runButton = screen.getByText('Run Script')
fireEvent.click(runButton)
expect(screen.getByTestId('terminal')).toBeInTheDocument()
// Then close the terminal
const closeButton = screen.getByText('Close Terminal')
fireEvent.click(closeButton)
expect(screen.queryByTestId('terminal')).not.toBeInTheDocument()
})
it('should handle multiple script runs', () => {
render(<Home />)
// Run first script
const runButton = screen.getByText('Run Script')
fireEvent.click(runButton)
expect(screen.getByText('Terminal for: /test/path')).toBeInTheDocument()
// Close terminal
const closeButton = screen.getByText('Close Terminal')
fireEvent.click(closeButton)
expect(screen.queryByTestId('terminal')).not.toBeInTheDocument()
// Run second script
fireEvent.click(runButton)
expect(screen.getByText('Terminal for: /test/path')).toBeInTheDocument()
})
})

View File

@@ -1,140 +0,0 @@
'use client';
import React from 'react';
interface BadgeProps {
variant: 'type' | 'updateable' | 'privileged' | 'status' | 'note' | 'execution-mode';
type?: string;
noteType?: 'info' | 'warning' | 'error';
status?: 'success' | 'failed' | 'in_progress';
executionMode?: 'local' | 'ssh';
children: React.ReactNode;
className?: string;
}
export function Badge({ variant, type, noteType, status, executionMode, children, className = '' }: BadgeProps) {
const getTypeStyles = (scriptType: string) => {
switch (scriptType.toLowerCase()) {
case 'ct':
return 'bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200 border-blue-200 dark:border-blue-700';
case 'addon':
return 'bg-purple-100 dark:bg-purple-900/30 text-purple-800 dark:text-purple-200 border-purple-200 dark:border-purple-700';
case 'vm':
return 'bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200 border-green-200 dark:border-green-700';
case 'pve':
return 'bg-orange-100 dark:bg-orange-900/30 text-orange-800 dark:text-orange-200 border-orange-200 dark:border-orange-700';
default:
return 'bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200 border-gray-200 dark:border-gray-600';
}
};
const getVariantStyles = () => {
switch (variant) {
case 'type':
return `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium border ${type ? getTypeStyles(type) : getTypeStyles('unknown')}`;
case 'updateable':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200 border border-green-200 dark:border-green-700';
case 'privileged':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-200 border border-red-200 dark:border-red-700';
case 'status':
switch (status) {
case 'success':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-200 border border-green-200 dark:border-green-700';
case 'failed':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-200 border border-red-200 dark:border-red-700';
case 'in_progress':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 border border-yellow-200 dark:border-yellow-700';
default:
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200 border border-gray-200 dark:border-gray-600';
}
case 'execution-mode':
switch (executionMode) {
case 'local':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200 border border-blue-200 dark:border-blue-700';
case 'ssh':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-800 dark:text-purple-200 border border-purple-200 dark:border-purple-700';
default:
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200 border border-gray-200 dark:border-gray-600';
}
case 'note':
switch (noteType) {
case 'warning':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 border border-yellow-200 dark:border-yellow-700';
case 'error':
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 dark:bg-red-900/30 text-red-800 dark:text-red-200 border border-red-200 dark:border-red-700';
default:
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-800 dark:text-blue-200 border border-blue-200 dark:border-blue-700';
}
default:
return 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200 border border-gray-200 dark:border-gray-600';
}
};
// Format the text for type badges
const formatText = () => {
if (variant === 'type' && type) {
switch (type.toLowerCase()) {
case 'ct':
return 'LXC';
case 'addon':
return 'ADDON';
case 'vm':
return 'VM';
case 'pve':
return 'PVE';
default:
return type.toUpperCase();
}
}
return children;
};
return (
<span className={`${getVariantStyles()} ${className}`}>
{formatText()}
</span>
);
}
// Convenience components for common use cases
export const TypeBadge = ({ type, className }: { type: string; className?: string }) => (
<Badge variant="type" type={type} className={className}>
{type}
</Badge>
);
export const UpdateableBadge = ({ className }: { className?: string }) => (
<Badge variant="updateable" className={className}>
Updateable
</Badge>
);
export const PrivilegedBadge = ({ className }: { className?: string }) => (
<Badge variant="privileged" className={className}>
Privileged
</Badge>
);
export const StatusBadge = ({ status, children, className }: { status: 'success' | 'failed' | 'in_progress'; children: React.ReactNode; className?: string }) => (
<Badge variant="status" status={status} className={className}>
{children}
</Badge>
);
export const ExecutionModeBadge = ({ mode, children, className }: { mode: 'local' | 'ssh'; children: React.ReactNode; className?: string }) => (
<Badge variant="execution-mode" executionMode={mode} className={className}>
{children}
</Badge>
);
export const NoteBadge = ({ noteType, children, className }: { noteType: 'info' | 'warning' | 'error'; children: React.ReactNode; className?: string }) => (
<Badge variant="note" noteType={noteType} className={className}>
{children}
</Badge>
);

View File

@@ -1,363 +0,0 @@
'use client';
import { useState } from 'react';
interface CategorySidebarProps {
categories: string[];
categoryCounts: Record<string, number>;
totalScripts: number;
selectedCategory: string | null;
onCategorySelect: (category: string | null) => void;
}
// Icon mapping for categories
const CategoryIcon = ({ iconName, className = "w-5 h-5" }: { iconName: string; className?: string }) => {
const iconMap: Record<string, React.ReactElement> = {
server: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 12h14M5 12a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v4a2 2 0 01-2 2M5 12a2 2 0 00-2 2v4a2 2 0 002 2h14a2 2 0 002-2v-4a2 2 0 00-2-2m-2-4h.01M17 16h.01" />
</svg>
),
monitor: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
</svg>
),
box: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
</svg>
),
shield: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
</svg>
),
"shield-check": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z" />
</svg>
),
key: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1721 9z" />
</svg>
),
archive: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4" />
</svg>
),
database: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 7v10c0 2.21 3.582 4 8 4s8-1.79 8-4V7M4 7c0 2.21 3.582 4 8 4s8-1.79 8-4M4 7c0-2.21 3.582-4 8-4s8 1.79 8 4m0 5c0 2.21-3.582 4-8 4s-8-1.79-8-4" />
</svg>
),
"chart-bar": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg>
),
template: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 5a1 1 0 011-1h14a1 1 0 011 1v2a1 1 0 01-1 1H5a1 1 0 01-1-1V5zM4 13a1 1 0 011-1h6a1 1 0 011 1v6a1 1 0 01-1 1H5a1 1 0 01-1-1v-6zM16 13a1 1 0 011-1h2a1 1 0 011 1v6a1 1 0 01-1 1h-2a1 1 0 01-1-1v-6z" />
</svg>
),
"folder-open": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
</svg>
),
"document-text": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
),
film: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 4V2a1 1 0 011-1h8a1 1 0 011 1v2m0 0V1.5a.5.5 0 01.5-.5h1a.5.5 0 01.5.5V4m-3 0H9m3 0v16a1 1 0 01-1 1H8a1 1 0 01-1-1V4m6 0h2a2 2 0 012 2v12a2 2 0 01-2 2h-2V4z" />
</svg>
),
download: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
</svg>
),
"video-camera": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
</svg>
),
home: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
</svg>
),
wifi: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8.111 16.404a5.5 5.5 0 017.778 0M12 20h.01m-7.08-7.071c3.904-3.905 10.236-3.905 14.141 0M1.394 9.393c5.857-5.857 15.355-5.857 21.213 0" />
</svg>
),
"chat-alt": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
</svg>
),
clock: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
),
code: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4" />
</svg>
),
"external-link": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
</svg>
),
sparkles: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 3v4M3 5h4M6 17v4m-2-2h4m5-16l2.286 6.857L21 12l-5.714 2.143L13 21l-2.286-6.857L5 12l5.714-2.143L13 3z" />
</svg>
),
"currency-dollar": (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1" />
</svg>
),
puzzle: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M11 4a2 2 0 114 0v1a1 1 0 001 1h3a1 1 0 011 1v3a1 1 0 01-1 1h-1a2 2 0 100 4h1a1 1 0 011 1v3a1 1 0 01-1 1h-3a1 1 0 01-1-1v-1a2 2 0 10-4 0v1a1 1 0 01-1 1H7a1 1 0 01-1-1v-3a1 1 0 00-1-1H4a2 2 0 110-4h1a1 1 0 001-1V7a1 1 0 011-1h3a1 1 0 001-1V4z" />
</svg>
),
office: (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
</svg>
),
};
return iconMap[iconName] ?? (
<svg className={className} fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zM21 5a2 2 0 00-2-2h-4a2 2 0 00-2 2v12a4 4 0 004 4 4 4 0 004-4V5z" />
</svg>
);
};
export function CategorySidebar({
categories,
categoryCounts,
totalScripts,
selectedCategory,
onCategorySelect
}: CategorySidebarProps) {
const [isCollapsed, setIsCollapsed] = useState(false);
// Category to icon mapping (based on metadata.json)
const categoryIconMapping: Record<string, string> = {
'Proxmox & Virtualization': 'server',
'Operating Systems': 'monitor',
'Containers & Docker': 'box',
'Network & Firewall': 'shield',
'Adblock & DNS': 'shield-check',
'Authentication & Security': 'key',
'Backup & Recovery': 'archive',
'Databases': 'database',
'Monitoring & Analytics': 'chart-bar',
'Dashboards & Frontends': 'template',
'Files & Downloads': 'folder-open',
'Documents & Notes': 'document-text',
'Media & Streaming': 'film',
'*Arr Suite': 'download',
'NVR & Cameras': 'video-camera',
'IoT & Smart Home': 'home',
'ZigBee, Z-Wave & Matter': 'wifi',
'MQTT & Messaging': 'chat-alt',
'Automation & Scheduling': 'clock',
'AI / Coding & Dev-Tools': 'code',
'Webservers & Proxies': 'external-link',
'Bots & ChatOps': 'sparkles',
'Finance & Budgeting': 'currency-dollar',
'Gaming & Leisure': 'puzzle',
'Business & ERP': 'office',
'Miscellaneous': 'box'
};
// Sort categories by count (descending) and then alphabetically
const sortedCategories = categories
.map(category => [category, categoryCounts[category] ?? 0] as const)
.sort(([a, countA], [b, countB]) => {
if (countB !== countA) return countB - countA;
return a.localeCompare(b);
});
return (
<div className={`bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-700 transition-all duration-300 ${
isCollapsed ? 'w-16' : 'w-80'
}`}>
{/* Header */}
<div className="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700">
{!isCollapsed && (
<div>
<h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100">Categories</h3>
<p className="text-sm text-gray-500 dark:text-gray-400">{totalScripts} Total scripts</p>
</div>
)}
<button
onClick={() => setIsCollapsed(!isCollapsed)}
className="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
title={isCollapsed ? 'Expand categories' : 'Collapse categories'}
>
<svg
className={`w-5 h-5 text-gray-500 dark:text-gray-400 transition-transform ${
isCollapsed ? 'rotate-180' : ''
}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 19l-7-7 7-7" />
</svg>
</button>
</div>
{/* Expanded state - show full categories */}
{!isCollapsed && (
<div className="p-4">
<div className="space-y-2">
{/* "All Categories" option */}
<button
onClick={() => onCategorySelect(null)}
className={`w-full flex items-center justify-between p-3 rounded-lg text-left transition-colors ${
selectedCategory === null
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 border border-blue-200 dark:border-blue-800'
: 'hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300'
}`}
>
<div className="flex items-center space-x-3">
<CategoryIcon
iconName="template"
className={`w-5 h-5 ${selectedCategory === null ? 'text-blue-500' : 'text-gray-500 dark:text-gray-400'}`}
/>
<span className="font-medium">All Categories</span>
</div>
<span className={`text-sm px-2 py-1 rounded-full ${
selectedCategory === null
? 'bg-blue-100 dark:bg-blue-800 text-blue-700 dark:text-blue-300'
: 'bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400'
}`}>
{totalScripts}
</span>
</button>
{/* Individual Categories */}
{sortedCategories.map(([category, count]) => {
const isSelected = selectedCategory === category;
return (
<button
key={category}
onClick={() => onCategorySelect(category)}
className={`w-full flex items-center justify-between p-3 rounded-lg text-left transition-colors ${
isSelected
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 border border-blue-200 dark:border-blue-800'
: 'hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300'
}`}
>
<div className="flex items-center space-x-3">
<CategoryIcon
iconName={categoryIconMapping[category] ?? 'box'}
className={`w-5 h-5 ${isSelected ? 'text-blue-500' : 'text-gray-500 dark:text-gray-400'}`}
/>
<span className="font-medium capitalize">
{category.replace(/[_-]/g, ' ')}
</span>
</div>
<span className={`text-sm px-2 py-1 rounded-full ${
isSelected
? 'bg-blue-100 dark:bg-blue-800 text-blue-700 dark:text-blue-300'
: 'bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400'
}`}>
{count}
</span>
</button>
);
})}
</div>
</div>
)}
{/* Collapsed state - show only icons with counters and tooltips */}
{isCollapsed && (
<div className="p-2 flex flex-col space-y-2">
{/* "All Categories" option */}
<div className="group relative">
<button
onClick={() => onCategorySelect(null)}
className={`w-12 h-12 rounded-lg flex flex-col items-center justify-center transition-colors relative ${
selectedCategory === null
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 border border-blue-200 dark:border-blue-800'
: 'hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300'
}`}
>
<CategoryIcon
iconName="template"
className={`w-5 h-5 ${selectedCategory === null ? 'text-blue-500' : 'text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-200'}`}
/>
<span className={`text-xs mt-1 px-1 rounded ${
selectedCategory === null
? 'bg-blue-100 dark:bg-blue-800 text-blue-700 dark:text-blue-300'
: 'bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400'
}`}>
{totalScripts}
</span>
</button>
{/* Tooltip */}
<div className="absolute left-full ml-2 top-1/2 transform -translate-y-1/2 bg-gray-900 dark:bg-gray-700 text-white text-sm px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none whitespace-nowrap z-50">
All Categories ({totalScripts})
</div>
</div>
{/* Individual Categories */}
{sortedCategories.map(([category, count]) => {
const isSelected = selectedCategory === category;
return (
<div key={category} className="group relative">
<button
onClick={() => onCategorySelect(category)}
className={`w-12 h-12 rounded-lg flex flex-col items-center justify-center transition-colors relative ${
isSelected
? 'bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300 border border-blue-200 dark:border-blue-800'
: 'hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300'
}`}
>
<CategoryIcon
iconName={categoryIconMapping[category] ?? 'box'}
className={`w-5 h-5 ${isSelected ? 'text-blue-500' : 'text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-200'}`}
/>
<span className={`text-xs mt-1 px-1 rounded ${
isSelected
? 'bg-blue-100 dark:bg-blue-800 text-blue-700 dark:text-blue-300'
: 'bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-400'
}`}>
{count}
</span>
</button>
{/* Tooltip */}
<div className="absolute left-full ml-2 top-1/2 transform -translate-y-1/2 bg-gray-900 dark:bg-gray-700 text-white text-sm px-2 py-1 rounded opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none whitespace-nowrap z-50">
{category} ({count})
</div>
</div>
);
})}
</div>
)}
</div>
);
}

View File

@@ -19,6 +19,7 @@ export function DarkModeProvider({ children }: { children: React.ReactNode }) {
// Initialize theme from localStorage after mount
useEffect(() => {
setMounted(true);
const stored = localStorage.getItem('theme') as Theme;
if (stored && ['light', 'dark', 'system'].includes(stored)) {
setThemeState(stored);
@@ -27,7 +28,6 @@ export function DarkModeProvider({ children }: { children: React.ReactNode }) {
// Set initial isDark state based on current DOM state
const currentlyDark = document.documentElement.classList.contains('dark');
setIsDark(currentlyDark);
setMounted(true);
}, []);
// Update dark mode state and DOM when theme changes
@@ -38,8 +38,6 @@ export function DarkModeProvider({ children }: { children: React.ReactNode }) {
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const shouldBeDark = theme === 'dark' || (theme === 'system' && systemDark);
// Only update if there's actually a change
if (shouldBeDark !== isDark) {
setIsDark(shouldBeDark);
// Apply to document
@@ -48,7 +46,6 @@ export function DarkModeProvider({ children }: { children: React.ReactNode }) {
} else {
document.documentElement.classList.remove('dark');
}
}
};
updateDarkMode();
@@ -63,7 +60,7 @@ export function DarkModeProvider({ children }: { children: React.ReactNode }) {
mediaQuery.addEventListener('change', handleChange);
return () => mediaQuery.removeEventListener('change', handleChange);
}, [theme, mounted, isDark]);
}, [theme, mounted]);
const setTheme = (newTheme: Theme) => {
setThemeState(newTheme);

View File

@@ -1,342 +0,0 @@
"use client";
import React, { useState } from "react";
export interface FilterState {
searchQuery: string;
showUpdatable: boolean | null; // null = all, true = only updatable, false = only non-updatable
selectedTypes: string[]; // Array of selected types: 'lxc', 'vm', 'addon', 'pve'
sortBy: "name" | "created"; // Sort criteria (removed 'updated')
sortOrder: "asc" | "desc"; // Sort direction
}
interface FilterBarProps {
filters: FilterState;
onFiltersChange: (filters: FilterState) => void;
totalScripts: number;
filteredCount: number;
updatableCount?: number;
}
const SCRIPT_TYPES = [
{ value: "ct", label: "LXC Container", icon: "📦" },
{ value: "vm", label: "Virtual Machine", icon: "💻" },
{ value: "addon", label: "Add-on", icon: "🔧" },
{ value: "pve", label: "PVE Host", icon: "🖥️" },
];
export function FilterBar({
filters,
onFiltersChange,
totalScripts,
filteredCount,
updatableCount = 0,
}: FilterBarProps) {
const [isTypeDropdownOpen, setIsTypeDropdownOpen] = useState(false);
const updateFilters = (updates: Partial<FilterState>) => {
onFiltersChange({ ...filters, ...updates });
};
const clearAllFilters = () => {
onFiltersChange({
searchQuery: "",
showUpdatable: null,
selectedTypes: [],
sortBy: "name",
sortOrder: "asc",
});
};
const hasActiveFilters =
filters.searchQuery ||
filters.showUpdatable !== null ||
filters.selectedTypes.length > 0 ||
filters.sortBy !== "name" ||
filters.sortOrder !== "asc";
const getUpdatableButtonText = () => {
if (filters.showUpdatable === null) return "Updatable: All";
if (filters.showUpdatable === true)
return `Updatable: Yes (${updatableCount})`;
return "Updatable: No";
};
const getTypeButtonText = () => {
if (filters.selectedTypes.length === 0) return "All Types";
if (filters.selectedTypes.length === 1) {
const type = SCRIPT_TYPES.find(
(t) => t.value === filters.selectedTypes[0],
);
return type?.label ?? filters.selectedTypes[0];
}
return `${filters.selectedTypes.length} Types`;
};
return (
<div className="mb-6 rounded-lg border border-gray-200 bg-white p-6 shadow-sm dark:border-gray-700 dark:bg-gray-800">
{/* Search Bar */}
<div className="mb-4">
<div className="relative max-w-md">
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
<svg
className="h-5 w-5 text-gray-400 dark:text-gray-500"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
</div>
<input
type="text"
placeholder="Search scripts..."
value={filters.searchQuery}
onChange={(e) => updateFilters({ searchQuery: e.target.value })}
className="block w-full rounded-lg border border-gray-300 bg-white py-3 pr-10 pl-10 text-sm leading-5 text-gray-900 placeholder-gray-500 focus:border-blue-500 focus:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100 dark:placeholder-gray-400 dark:focus:border-blue-400 dark:focus:placeholder-gray-300 dark:focus:ring-blue-400"
/>
{filters.searchQuery && (
<button
onClick={() => updateFilters({ searchQuery: "" })}
className="absolute inset-y-0 right-0 flex items-center pr-3 text-gray-400 hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300"
>
<svg
className="h-5 w-5"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
)}
</div>
</div>
{/* Filter Buttons */}
<div className="mb-4 flex flex-wrap gap-3">
{/* Updateable Filter */}
<button
onClick={() => {
const next =
filters.showUpdatable === null
? true
: filters.showUpdatable === true
? false
: null;
updateFilters({ showUpdatable: next });
}}
className={`rounded-lg px-4 py-2 text-sm font-medium transition-colors ${
filters.showUpdatable === null
? "bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600"
: filters.showUpdatable === true
? "border border-green-300 bg-green-100 text-green-800 dark:border-green-700 dark:bg-green-900/50 dark:text-green-200"
: "border border-red-300 bg-red-100 text-red-800 dark:border-red-700 dark:bg-red-900/50 dark:text-red-200"
}`}
>
{getUpdatableButtonText()}
</button>
{/* Type Dropdown */}
<div className="relative">
<button
onClick={() => setIsTypeDropdownOpen(!isTypeDropdownOpen)}
className={`flex items-center space-x-2 rounded-lg px-4 py-2 text-sm font-medium transition-colors ${
filters.selectedTypes.length === 0
? "bg-gray-100 text-gray-700 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600"
: "border border-cyan-300 bg-cyan-100 text-cyan-800 dark:border-cyan-700 dark:bg-cyan-900/50 dark:text-cyan-200"
}`}
>
<span>{getTypeButtonText()}</span>
<svg
className={`h-4 w-4 transition-transform ${isTypeDropdownOpen ? "rotate-180" : ""}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M19 9l-7 7-7-7"
/>
</svg>
</button>
{isTypeDropdownOpen && (
<div className="absolute top-full left-0 z-10 mt-1 w-48 rounded-lg border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-800">
<div className="p-2">
{SCRIPT_TYPES.map((type) => (
<label
key={type.value}
className="flex cursor-pointer items-center space-x-3 rounded-md px-3 py-2 hover:bg-gray-50 dark:hover:bg-gray-700"
>
<input
type="checkbox"
checked={filters.selectedTypes.includes(type.value)}
onChange={(e) => {
if (e.target.checked) {
updateFilters({
selectedTypes: [
...filters.selectedTypes,
type.value,
],
});
} else {
updateFilters({
selectedTypes: filters.selectedTypes.filter(
(t) => t !== type.value,
),
});
}
}}
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500 dark:border-gray-600"
/>
<span className="text-lg">{type.icon}</span>
<span className="text-sm text-gray-700 dark:text-gray-300">
{type.label}
</span>
</label>
))}
</div>
<div className="border-t border-gray-200 p-2 dark:border-gray-700">
<button
onClick={() => {
updateFilters({ selectedTypes: [] });
setIsTypeDropdownOpen(false);
}}
className="w-full rounded-md px-3 py-2 text-left text-sm text-gray-600 hover:bg-gray-50 hover:text-gray-900 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-gray-100"
>
Clear all
</button>
</div>
</div>
)}
</div>
{/* Sort Options */}
<div className="flex items-center space-x-2">
{/* Sort By Dropdown */}
<select
value={filters.sortBy}
onChange={(e) =>
updateFilters({ sortBy: e.target.value as "name" | "created" })
}
className="rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-700 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:focus:ring-blue-400"
>
<option value="name">📝 By Name</option>
<option value="created">📅 By Created Date</option>
</select>
{/* Sort Order Button */}
<button
onClick={() =>
updateFilters({
sortOrder: filters.sortOrder === "asc" ? "desc" : "asc",
})
}
className="flex items-center space-x-1 rounded-lg bg-gray-100 px-3 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-300 dark:hover:bg-gray-600"
>
{filters.sortOrder === "asc" ? (
<>
<svg
className="h-4 w-4"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M7 11l5-5m0 0l5 5m-5-5v12"
/>
</svg>
<span>
{filters.sortBy === "created" ? "Oldest First" : "A-Z"}
</span>
</>
) : (
<>
<svg
className="h-4 w-4"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M17 13l-5 5m0 0l-5-5m5 5V6"
/>
</svg>
<span>
{filters.sortBy === "created" ? "Newest First" : "Z-A"}
</span>
</>
)}
</button>
</div>
</div>
{/* Filter Summary and Clear All */}
<div className="flex items-center justify-between">
<div className="text-sm text-gray-600 dark:text-gray-400">
{filteredCount === totalScripts ? (
<span>Showing all {totalScripts} scripts</span>
) : (
<span>
{filteredCount} of {totalScripts} scripts{" "}
{hasActiveFilters && (
<span className="font-medium text-blue-600 dark:text-blue-400">
(filtered)
</span>
)}
</span>
)}
</div>
{hasActiveFilters && (
<button
onClick={clearAllFilters}
className="flex items-center space-x-1 rounded-md px-3 py-1 text-sm text-red-600 transition-colors hover:bg-red-50 hover:text-red-800 dark:text-red-400 dark:hover:bg-red-900/20 dark:hover:text-red-300"
>
<svg
className="h-4 w-4"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
<span>Clear all filters</span>
</button>
)}
</div>
{/* Click outside to close dropdown */}
{isTypeDropdownOpen && (
<div
className="fixed inset-0 z-0"
onClick={() => setIsTypeDropdownOpen(false)}
/>
)}
</div>
);
}

View File

@@ -3,7 +3,6 @@
import { useState } from 'react';
import { api } from '~/trpc/react';
import { Terminal } from './Terminal';
import { StatusBadge, ExecutionModeBadge } from './Badge';
interface InstalledScript {
id: number;
@@ -26,15 +25,10 @@ export function InstalledScriptsTab() {
const [statusFilter, setStatusFilter] = useState<'all' | 'success' | 'failed' | 'in_progress'>('all');
const [serverFilter, setServerFilter] = useState<string>('all');
const [updatingScript, setUpdatingScript] = useState<{ id: number; containerId: string; server?: any; mode: 'local' | 'ssh' } | null>(null);
const [editingScriptId, setEditingScriptId] = useState<number | null>(null);
const [editFormData, setEditFormData] = useState<{ script_name: string; container_id: string }>({ script_name: '', container_id: '' });
const [showAddForm, setShowAddForm] = useState(false);
const [addFormData, setAddFormData] = useState<{ script_name: string; container_id: string; server_id: string }>({ script_name: '', container_id: '', server_id: 'local' });
// Fetch installed scripts
const { data: scriptsData, refetch: refetchScripts, isLoading } = api.installedScripts.getAllInstalledScripts.useQuery();
const { data: statsData } = api.installedScripts.getInstallationStats.useQuery();
const { data: serversData } = api.servers.getAllServers.useQuery();
// Delete script mutation
const deleteScriptMutation = api.installedScripts.deleteInstalledScript.useMutation({
@@ -43,30 +37,6 @@ export function InstalledScriptsTab() {
}
});
// Update script mutation
const updateScriptMutation = api.installedScripts.updateInstalledScript.useMutation({
onSuccess: () => {
void refetchScripts();
setEditingScriptId(null);
setEditFormData({ script_name: '', container_id: '' });
},
onError: (error) => {
alert(`Error updating script: ${error.message}`);
}
});
// Create script mutation
const createScriptMutation = api.installedScripts.createInstalledScript.useMutation({
onSuccess: () => {
void refetchScripts();
setShowAddForm(false);
setAddFormData({ script_name: '', container_id: '', server_id: 'local' });
},
onError: (error) => {
alert(`Error creating script: ${error.message}`);
}
});
const scripts: InstalledScript[] = (scriptsData?.scripts as InstalledScript[]) ?? [];
const stats = statsData?.stats;
@@ -134,74 +104,37 @@ export function InstalledScriptsTab() {
setUpdatingScript(null);
};
const handleEditScript = (script: InstalledScript) => {
setEditingScriptId(script.id);
setEditFormData({
script_name: script.script_name,
container_id: script.container_id ?? ''
});
};
const handleCancelEdit = () => {
setEditingScriptId(null);
setEditFormData({ script_name: '', container_id: '' });
};
const handleSaveEdit = () => {
if (!editFormData.script_name.trim()) {
alert('Script name is required');
return;
}
if (editingScriptId) {
updateScriptMutation.mutate({
id: editingScriptId,
script_name: editFormData.script_name.trim(),
container_id: editFormData.container_id.trim() || undefined,
});
}
};
const handleInputChange = (field: 'script_name' | 'container_id', value: string) => {
setEditFormData(prev => ({
...prev,
[field]: value
}));
};
const handleAddFormChange = (field: 'script_name' | 'container_id' | 'server_id', value: string) => {
setAddFormData(prev => ({
...prev,
[field]: value
}));
};
const handleAddScript = () => {
if (!addFormData.script_name.trim()) {
alert('Script name is required');
return;
}
createScriptMutation.mutate({
script_name: addFormData.script_name.trim(),
script_path: `manual/${addFormData.script_name.trim()}`,
container_id: addFormData.container_id.trim() || undefined,
server_id: addFormData.server_id === 'local' ? undefined : Number(addFormData.server_id),
execution_mode: addFormData.server_id === 'local' ? 'local' : 'ssh',
status: 'success'
});
};
const handleCancelAdd = () => {
setShowAddForm(false);
setAddFormData({ script_name: '', container_id: '', server_id: 'local' });
};
const formatDate = (dateString: string) => {
return new Date(dateString).toLocaleString();
};
const getStatusBadge = (status: string): string => {
const baseClasses = 'px-2 py-1 text-xs font-medium rounded-full';
switch (status) {
case 'success':
return `${baseClasses} bg-green-100 text-green-800`;
case 'failed':
return `${baseClasses} bg-red-100 text-red-800`;
case 'in_progress':
return `${baseClasses} bg-yellow-100 text-yellow-800`;
default:
return `${baseClasses} bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200`;
}
};
const getModeBadge = (mode: string): string => {
const baseClasses = 'px-2 py-1 text-xs font-medium rounded-full';
switch (mode) {
case 'local':
return `${baseClasses} bg-blue-100 text-blue-800`;
case 'ssh':
return `${baseClasses} bg-purple-100 text-purple-800`;
default:
return `${baseClasses} bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200`;
}
};
if (isLoading) {
return (
<div className="flex items-center justify-center h-64">
@@ -251,81 +184,6 @@ export function InstalledScriptsTab() {
</div>
)}
{/* Add Script Button */}
<div className="mb-4">
<button
onClick={() => setShowAddForm(!showAddForm)}
className="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md text-sm font-medium transition-colors"
>
{showAddForm ? 'Cancel Add Script' : '+ Add Manual Script Entry'}
</button>
</div>
{/* Add Script Form */}
{showAddForm && (
<div className="mb-6 p-4 bg-gray-50 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600">
<h3 className="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4">Add Manual Script Entry</h3>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Script Name *
</label>
<input
type="text"
value={addFormData.script_name}
onChange={(e) => handleAddFormChange('script_name', e.target.value)}
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400"
placeholder="Enter script name"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Container ID
</label>
<input
type="text"
value={addFormData.container_id}
onChange={(e) => handleAddFormChange('container_id', e.target.value)}
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400"
placeholder="Enter container ID"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Server
</label>
<select
value={addFormData.server_id}
onChange={(e) => handleAddFormChange('server_id', e.target.value)}
className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400"
>
<option value="local">Select Server (Local if none)</option>
{serversData?.servers?.map((server: any) => (
<option key={server.id} value={server.id}>
{server.name}
</option>
))}
</select>
</div>
</div>
<div className="flex justify-end space-x-3 mt-4">
<button
onClick={handleCancelAdd}
className="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-600 border border-gray-300 dark:border-gray-500 rounded-md hover:bg-gray-50 dark:hover:bg-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 dark:focus:ring-blue-400"
>
Cancel
</button>
<button
onClick={handleAddScript}
disabled={createScriptMutation.isPending}
className="px-4 py-2 text-sm font-medium text-white bg-green-600 rounded-md hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 disabled:opacity-50 disabled:cursor-not-allowed"
>
{createScriptMutation.isPending ? 'Adding...' : 'Add Script'}
</button>
</div>
</div>
)}
{/* Filters */}
<div className="flex flex-wrap gap-4">
<div className="flex-1 min-w-64">
@@ -383,9 +241,6 @@ export function InstalledScriptsTab() {
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
Server
</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
Mode
</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">
Status
</th>
@@ -399,41 +254,16 @@ export function InstalledScriptsTab() {
</thead>
<tbody className="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
{filteredScripts.map((script) => (
<tr key={script.id} className="hover:bg-gray-50 dark:hover:bg-gray-700">
<tr key={script.id} className="hover:bg-gray-50">
<td className="px-6 py-4 whitespace-nowrap">
{editingScriptId === script.id ? (
<div className="space-y-2">
<input
type="text"
value={editFormData.script_name}
onChange={(e) => handleInputChange('script_name', e.target.value)}
className="w-full px-2 py-1 text-sm border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Script name"
/>
<div className="text-xs text-gray-500 dark:text-gray-400">{script.script_path}</div>
</div>
) : (
<div>
<div className="text-sm font-medium text-gray-900 dark:text-gray-100">{script.script_name}</div>
<div className="text-sm text-gray-500 dark:text-gray-400">{script.script_path}</div>
</div>
)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
{editingScriptId === script.id ? (
<input
type="text"
value={editFormData.container_id}
onChange={(e) => handleInputChange('container_id', e.target.value)}
className="w-full px-2 py-1 text-sm font-mono border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-2 focus:ring-blue-500"
placeholder="Container ID"
/>
) : (
script.container_id ? (
{script.container_id ? (
<span className="text-sm font-mono text-gray-900 dark:text-gray-100">{String(script.container_id)}</span>
) : (
<span className="text-sm text-gray-400 dark:text-gray-500">-</span>
)
)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
@@ -447,44 +277,20 @@ export function InstalledScriptsTab() {
)}
</td>
<td className="px-6 py-4 whitespace-nowrap">
<ExecutionModeBadge mode={script.execution_mode}>
{script.execution_mode.toUpperCase()}
</ExecutionModeBadge>
<span className={getModeBadge(String(script.execution_mode))}>
{String(script.execution_mode).toUpperCase()}
</span>
</td>
<td className="px-6 py-4 whitespace-nowrap">
<StatusBadge status={script.status}>
{script.status.replace('_', ' ').toUpperCase()}
</StatusBadge>
<span className={getStatusBadge(String(script.status))}>
{String(script.status).replace('_', ' ').toUpperCase()}
</span>
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
{formatDate(String(script.installation_date))}
</td>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium">
<div className="flex space-x-2">
{editingScriptId === script.id ? (
<>
<button
onClick={handleSaveEdit}
disabled={updateScriptMutation.isPending}
className="bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded text-sm font-medium disabled:opacity-50"
>
{updateScriptMutation.isPending ? 'Saving...' : 'Save'}
</button>
<button
onClick={handleCancelEdit}
className="bg-gray-600 hover:bg-gray-700 text-white px-3 py-1 rounded text-sm font-medium"
>
Cancel
</button>
</>
) : (
<>
<button
onClick={() => handleEditScript(script)}
className="bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded text-sm font-medium"
>
Edit
</button>
{script.container_id && (
<button
onClick={() => handleUpdateScript(script)}
@@ -500,8 +306,6 @@ export function InstalledScriptsTab() {
>
{deleteScriptMutation.isPending ? 'Deleting...' : 'Delete'}
</button>
</>
)}
</div>
</td>
</tr>
@@ -511,6 +315,7 @@ export function InstalledScriptsTab() {
</div>
)}
</div>
</div>
);
}

View File

@@ -38,11 +38,7 @@ export function ResyncButton() {
};
return (
<div className="flex flex-col sm:flex-row sm:items-center gap-3">
<div className="text-sm text-gray-600 dark:text-gray-300 font-medium">
Sync scripts with ProxmoxVE repo
</div>
<div className="flex flex-col sm:flex-row sm:items-center gap-3">
<div className="flex items-center space-x-4">
<button
onClick={handleResync}
disabled={isResyncing}
@@ -62,17 +58,16 @@ export function ResyncButton() {
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
</svg>
<span>Sync Json Files</span>
<span>Resync Scripts</span>
</>
)}
</button>
{lastSync && (
<div className="text-xs text-gray-500 dark:text-gray-400">
<div className="text-sm text-gray-500 dark:text-gray-400">
Last sync: {lastSync.toLocaleTimeString()}
</div>
)}
</div>
{syncMessage && (
<div className={`text-sm px-3 py-1 rounded-lg ${

View File

@@ -3,7 +3,6 @@
import { useState } from 'react';
import Image from 'next/image';
import type { ScriptCard } from '~/types/script';
import { TypeBadge, UpdateableBadge } from './Badge';
interface ScriptCardProps {
script: ScriptCard;
@@ -50,8 +49,20 @@ export function ScriptCard({ script, onClick }: ScriptCardProps) {
<div className="mt-2 space-y-2">
{/* Type and Updateable status on first row */}
<div className="flex items-center space-x-2">
<TypeBadge type={script.type ?? 'unknown'} />
{script.updateable && <UpdateableBadge />}
<span className={`inline-flex items-center px-2 py-1 rounded text-xs font-medium ${
script.type === 'ct'
? 'bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200'
: script.type === 'addon'
? 'bg-purple-100 dark:bg-purple-900 text-purple-800 dark:text-purple-200'
: 'bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200'
}`}>
{script.type?.toUpperCase() || 'UNKNOWN'}
</span>
{script.updateable && (
<span className="inline-flex items-center px-2 py-1 rounded text-xs font-medium bg-amber-100 dark:bg-amber-900 text-amber-800 dark:text-amber-200">
Updateable
</span>
)}
</div>
{/* Download Status */}

View File

@@ -7,7 +7,6 @@ import type { Script } from "~/types/script";
import { DiffViewer } from "./DiffViewer";
import { TextViewer } from "./TextViewer";
import { ExecutionModeModal } from "./ExecutionModeModal";
import { TypeBadge, UpdateableBadge, PrivilegedBadge, NoteBadge } from "./Badge";
interface ScriptDetailModalProps {
script: Script | null;
@@ -135,7 +134,7 @@ export function ScriptDetailModal({
className="bg-opacity-50 fixed inset-0 z-50 flex items-center justify-center bg-black p-4"
onClick={handleBackdropClick}
>
<div className="bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-6xl w-full max-h-[95vh] min-h-[80vh] overflow-y-auto">
<div className="max-h-[90vh] w-full max-w-4xl overflow-y-auto rounded-lg bg-white shadow-xl dark:bg-gray-800">
{/* Header */}
<div className="flex items-center justify-between border-b border-gray-200 p-6 dark:border-gray-700">
<div className="flex items-center space-x-4">
@@ -160,9 +159,25 @@ export function ScriptDetailModal({
{script.name}
</h2>
<div className="mt-1 flex items-center space-x-2">
<TypeBadge type={script.type} />
{script.updateable && <UpdateableBadge />}
{script.privileged && <PrivilegedBadge />}
<span
className={`inline-flex items-center rounded-full px-3 py-1 text-sm font-medium ${
script.type === "ct"
? "bg-blue-100 text-blue-800"
: "bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200"
}`}
>
{script.type.toUpperCase()}
</span>
{script.updateable && (
<span className="inline-flex items-center rounded-full bg-green-100 px-3 py-1 text-sm font-medium text-green-800">
Updateable
</span>
)}
{script.privileged && (
<span className="inline-flex items-center rounded-full bg-red-100 px-3 py-1 text-sm font-medium text-red-800">
Privileged
</span>
)}
</div>
</div>
</div>
@@ -662,9 +677,17 @@ export function ScriptDetailModal({
}`}
>
<div className="flex items-start">
<NoteBadge noteType={noteType as 'info' | 'warning' | 'error'} className="mr-2 flex-shrink-0">
<span
className={`mr-2 inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${
noteType === "warning"
? "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200"
: noteType === "error"
? "bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"
: "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200"
}`}
>
{noteType}
</NoteBadge>
</span>
<span>{noteText}</span>
</div>
</li>

View File

@@ -1,12 +1,9 @@
'use client';
import React, { useState, useRef, useEffect } from 'react';
import React, { useState } from 'react';
import { api } from '~/trpc/react';
import { ScriptCard } from './ScriptCard';
import { ScriptDetailModal } from './ScriptDetailModal';
import { CategorySidebar } from './CategorySidebar';
import { FilterBar, type FilterState } from './FilterBar';
import type { ScriptCard as ScriptCardType } from '~/types/script';
interface ScriptsGridProps {
@@ -17,88 +14,31 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
const [selectedSlug, setSelectedSlug] = useState<string | null>(null);
const [isModalOpen, setIsModalOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState('');
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
const [filters, setFilters] = useState<FilterState>({
searchQuery: '',
showUpdatable: null,
selectedTypes: [],
sortBy: 'name',
sortOrder: 'asc',
});
const gridRef = useRef<HTMLDivElement>(null);
const { data: scriptCardsData, isLoading: githubLoading, error: githubError, refetch } = api.scripts.getScriptCardsWithCategories.useQuery();
const { data: scriptCardsData, isLoading: githubLoading, error: githubError, refetch } = api.scripts.getScriptCards.useQuery();
const { data: localScriptsData, isLoading: localLoading, error: localError } = api.scripts.getCtScripts.useQuery();
const { data: scriptData } = api.scripts.getScriptBySlug.useQuery(
{ slug: selectedSlug ?? '' },
{ enabled: !!selectedSlug }
);
// Extract categories from metadata
const categories = React.useMemo((): string[] => {
if (!scriptCardsData?.success || !scriptCardsData.metadata?.categories) return [];
return (scriptCardsData.metadata.categories as any[])
.filter((cat) => cat.id !== 0) // Exclude Miscellaneous for main list
.sort((a, b) => a.sort_order - b.sort_order)
.map((cat) => cat.name as string)
.filter((name): name is string => typeof name === 'string');
}, [scriptCardsData]);
// Get GitHub scripts with download status (deduplicated)
const combinedScripts = React.useMemo((): ScriptCardType[] => {
if (!scriptCardsData?.success) return [];
// Use Map to deduplicate by slug/name
const scriptMap = new Map<string, ScriptCardType>();
scriptCardsData.cards?.forEach(script => {
if (script?.name && script?.slug) {
// Use slug as unique identifier, only keep first occurrence
if (!scriptMap.has(script.slug)) {
scriptMap.set(script.slug, {
// Get GitHub scripts with download status
const combinedScripts = React.useMemo(() => {
const githubScripts = scriptCardsData?.success ? (scriptCardsData.cards
?.filter(script => script?.name) // Filter out invalid scripts
?.map(script => ({
...script,
source: 'github' as const,
isDownloaded: false, // Will be updated by status check
isUpToDate: false, // Will be updated by status check
});
}
}
});
})) ?? []) : [];
return Array.from(scriptMap.values());
return githubScripts;
}, [scriptCardsData]);
// Count scripts per category (using deduplicated scripts)
const categoryCounts = React.useMemo((): Record<string, number> => {
if (!scriptCardsData?.success) return {};
const counts: Record<string, number> = {};
// Initialize all categories with 0
categories.forEach((categoryName: string) => {
counts[categoryName] = 0;
});
// Count each unique script only once per category
combinedScripts.forEach(script => {
if (script.categoryNames && script.slug) {
const countedCategories = new Set<string>();
script.categoryNames.forEach((categoryName: unknown) => {
if (typeof categoryName === 'string' && counts[categoryName] !== undefined && !countedCategories.has(categoryName)) {
countedCategories.add(categoryName);
counts[categoryName]++;
}
});
}
});
return counts;
}, [categories, combinedScripts, scriptCardsData?.success]);
// Update scripts with download status
const scriptsWithStatus = React.useMemo((): ScriptCardType[] => {
const scriptsWithStatus = React.useMemo(() => {
return combinedScripts.map(script => {
if (!script?.name) {
return script; // Return as-is if invalid
@@ -120,16 +60,21 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
});
}, [combinedScripts, localScriptsData]);
// Filter scripts based on all filters and category
const filteredScripts = React.useMemo((): ScriptCardType[] => {
let scripts = scriptsWithStatus;
// Filter scripts based on search query (name and slug only)
const filteredScripts = React.useMemo(() => {
if (!searchQuery?.trim()) {
return scriptsWithStatus;
}
// Filter by search query (use filters.searchQuery instead of deprecated searchQuery)
if (filters.searchQuery?.trim()) {
const query = filters.searchQuery.toLowerCase().trim();
const query = searchQuery.toLowerCase().trim();
if (query.length >= 1) {
scripts = scripts.filter(script => {
// If query is too short, don't filter
if (query.length < 1) {
return scriptsWithStatus;
}
const filtered = scriptsWithStatus.filter(script => {
// Ensure script exists and has required properties
if (!script || typeof script !== 'object') {
return false;
}
@@ -137,121 +82,13 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
const name = (script.name ?? '').toLowerCase();
const slug = (script.slug ?? '').toLowerCase();
return name.includes(query) ?? slug.includes(query);
});
}
}
const matches = name.includes(query) || slug.includes(query);
// Filter by category using real category data from deduplicated scripts
if (selectedCategory) {
scripts = scripts.filter(script => {
if (!script) return false;
// Check if the deduplicated script has categoryNames that include the selected category
return script.categoryNames?.includes(selectedCategory) ?? false;
});
}
// Filter by updateable status
if (filters.showUpdatable !== null) {
scripts = scripts.filter(script => {
if (!script) return false;
const isUpdatable = script.updateable ?? false;
return filters.showUpdatable ? isUpdatable : !isUpdatable;
});
}
// Filter by script types
if (filters.selectedTypes.length > 0) {
scripts = scripts.filter(script => {
if (!script) return false;
const scriptType = (script.type ?? '').toLowerCase();
return filters.selectedTypes.some(type => type.toLowerCase() === scriptType);
});
}
// Apply sorting
scripts.sort((a, b) => {
if (!a || !b) return 0;
let compareValue = 0;
switch (filters.sortBy) {
case 'name':
compareValue = (a.name ?? '').localeCompare(b.name ?? '');
break;
case 'created':
// Get creation date from script metadata in JSON format (date_created: "YYYY-MM-DD")
const aCreated = a?.date_created ?? '';
const bCreated = b?.date_created ?? '';
// If both have dates, compare them directly
if (aCreated && bCreated) {
// For dates: asc = oldest first (2020 before 2024), desc = newest first (2024 before 2020)
compareValue = aCreated.localeCompare(bCreated);
} else if (aCreated && !bCreated) {
// Scripts with dates come before scripts without dates
compareValue = -1;
} else if (!aCreated && bCreated) {
// Scripts without dates come after scripts with dates
compareValue = 1;
} else {
// Both have no dates, fallback to name comparison
compareValue = (a.name ?? '').localeCompare(b.name ?? '');
}
break;
default:
compareValue = (a.name ?? '').localeCompare(b.name ?? '');
}
// Apply sort order
return filters.sortOrder === 'asc' ? compareValue : -compareValue;
return matches;
});
return scripts;
}, [scriptsWithStatus, filters, selectedCategory]);
// Calculate filter counts for FilterBar
const filterCounts = React.useMemo(() => {
const installedCount = scriptsWithStatus.filter(script => script?.isDownloaded).length;
const updatableCount = scriptsWithStatus.filter(script => script?.updateable).length;
return { installedCount, updatableCount };
}, [scriptsWithStatus]);
// Sync legacy searchQuery with filters.searchQuery for backward compatibility
useEffect(() => {
if (searchQuery !== filters.searchQuery) {
setFilters(prev => ({ ...prev, searchQuery }));
}
}, [searchQuery, filters.searchQuery]);
// Handle filter changes
const handleFiltersChange = (newFilters: FilterState) => {
setFilters(newFilters);
// Sync searchQuery for backward compatibility
setSearchQuery(newFilters.searchQuery);
};
// Handle category selection with auto-scroll
const handleCategorySelect = (category: string | null) => {
setSelectedCategory(category);
};
// Auto-scroll effect when category changes
useEffect(() => {
if (selectedCategory && gridRef.current) {
const timeoutId = setTimeout(() => {
gridRef.current?.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest'
});
}, 100);
return () => clearTimeout(timeoutId);
}
}, [selectedCategory]);
return filtered;
}, [scriptsWithStatus, searchQuery]);
const handleCardClick = (scriptCard: { slug: string }) => {
@@ -313,31 +150,9 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
}
return (
<div className="flex gap-6">
{/* Category Sidebar */}
<div className="flex-shrink-0">
<CategorySidebar
categories={categories}
categoryCounts={categoryCounts}
totalScripts={scriptsWithStatus.length}
selectedCategory={selectedCategory}
onCategorySelect={handleCategorySelect}
/>
</div>
{/* Main Content */}
<div className="flex-1 min-w-0" ref={gridRef}>
{/* Enhanced Filter Bar */}
<FilterBar
filters={filters}
onFiltersChange={handleFiltersChange}
totalScripts={scriptsWithStatus.length}
filteredCount={filteredScripts.length}
updatableCount={filterCounts.updatableCount}
/>
{/* Legacy Search Bar (keeping for backward compatibility, but hidden) */}
<div className="hidden mb-8">
<>
{/* Search Bar */}
<div className="mb-8">
<div className="relative max-w-md mx-auto">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<svg className="h-5 w-5 text-gray-400 dark:text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -362,23 +177,19 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
</button>
)}
</div>
{(searchQuery || selectedCategory) && (
{searchQuery && (
<div className="text-center mt-2 text-sm text-gray-600">
{filteredScripts.length === 0 ? (
<span>No scripts found{searchQuery ? ` matching "${searchQuery}"` : ''}{selectedCategory ? ` in category "${selectedCategory}"` : ''}</span>
<span>No scripts found matching &quot;{searchQuery}&quot;</span>
) : (
<span>
Found {filteredScripts.length} script{filteredScripts.length !== 1 ? 's' : ''}
{searchQuery ? ` matching "${searchQuery}"` : ''}
{selectedCategory ? ` in category "${selectedCategory}"` : ''}
</span>
<span>Found {filteredScripts.length} script{filteredScripts.length !== 1 ? 's' : ''} matching &quot;{searchQuery}&quot;</span>
)}
</div>
)}
</div>
{/* Scripts Grid */}
{filteredScripts.length === 0 && (filters.searchQuery || selectedCategory || filters.showUpdatable !== null || filters.selectedTypes.length > 0) ? (
{filteredScripts.length === 0 && searchQuery ? (
<div className="text-center py-12">
<div className="text-gray-500">
<svg className="w-12 h-12 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -386,26 +197,14 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
</svg>
<p className="text-lg font-medium">No matching scripts found</p>
<p className="text-sm text-gray-500 mt-1">
Try different filter settings or clear all filters.
Try adjusting your search terms or clear the search to see all scripts.
</p>
<div className="flex justify-center gap-2 mt-4">
{filters.searchQuery && (
<button
onClick={() => handleFiltersChange({ ...filters, searchQuery: '' })}
className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
onClick={() => setSearchQuery('')}
className="mt-4 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
>
Clear Search
</button>
)}
{selectedCategory && (
<button
onClick={() => handleCategorySelect(null)}
className="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700 transition-colors"
>
Clear Category
</button>
)}
</div>
</div>
</div>
) : (
@@ -436,7 +235,6 @@ export function ScriptsGrid({ onInstallScript }: ScriptsGridProps) {
onClose={handleCloseModal}
onInstallScript={onInstallScript}
/>
</div>
</div>
</>
);
}

View File

@@ -8,13 +8,9 @@ export function SettingsButton() {
return (
<>
<div className="flex flex-col sm:flex-row sm:items-center gap-3">
<div className="text-sm text-gray-600 dark:text-gray-300 font-medium">
Add and manage PVE Servers
</div>
<button
onClick={() => setIsOpen(true)}
className="inline-flex items-center px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg shadow-sm text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors duration-200"
className="inline-flex items-center px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800 focus:ring-blue-500 dark:focus:ring-blue-400 transition-colors duration-200"
title="Add PVE Server"
>
<svg
@@ -37,9 +33,8 @@ export function SettingsButton() {
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
/>
</svg>
Manage PVE Servers
Add PVE Server
</button>
</div>
<SettingsModal isOpen={isOpen} onClose={() => setIsOpen(false)} />
</>

View File

@@ -1,7 +0,0 @@
import { describe, it, expect } from 'vitest'
describe('Always Pass Tests', () => {
it('should always pass - basic assertion', () => {
expect(true).toBe(true)
})
})

View File

@@ -0,0 +1,62 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen, fireEvent } from '@testing-library/react'
import { ResyncButton } from '../ResyncButton'
// Mock tRPC
vi.mock('~/trpc/react', () => ({
api: {
scripts: {
resyncScripts: {
useMutation: vi.fn(),
},
},
},
}))
describe('ResyncButton', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('should render resync button', async () => {
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.resyncScripts.useMutation).mockReturnValue({
mutate: vi.fn(),
})
render(<ResyncButton />)
expect(screen.getByText('Resync Scripts')).toBeInTheDocument()
})
it('should show loading state when resyncing', async () => {
const mockMutate = vi.fn()
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.resyncScripts.useMutation).mockReturnValue({
mutate: mockMutate,
})
render(<ResyncButton />)
const button = screen.getByRole('button')
fireEvent.click(button)
expect(screen.getByText('Syncing...')).toBeInTheDocument()
expect(button).toBeDisabled()
})
it('should handle button click', async () => {
const mockMutate = vi.fn()
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.resyncScripts.useMutation).mockReturnValue({
mutate: mockMutate,
})
render(<ResyncButton />)
const button = screen.getByRole('button')
fireEvent.click(button)
expect(mockMutate).toHaveBeenCalled()
})
})

View File

@@ -0,0 +1,192 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { ScriptsGrid } from '../ScriptsGrid'
// Mock tRPC
vi.mock('~/trpc/react', () => ({
api: {
scripts: {
getScriptCards: {
useQuery: vi.fn(),
},
getCtScripts: {
useQuery: vi.fn(),
},
getScriptBySlug: {
useQuery: vi.fn(),
},
},
},
}))
// Mock child components
vi.mock('../ScriptCard', () => ({
ScriptCard: ({ script, onClick }: { script: any; onClick: (script: any) => void }) => (
<div data-testid={`script-card-${script.slug}`} onClick={() => onClick(script)}>
{script.name}
</div>
),
}))
vi.mock('../ScriptDetailModal', () => ({
ScriptDetailModal: ({ isOpen, onClose, onInstallScript }: any) =>
isOpen ? (
<div data-testid="script-detail-modal">
<button onClick={onClose}>Close</button>
<button onClick={() => { onInstallScript?.('/test/path', 'test-script') }}>Install</button>
</div>
) : null,
}))
describe('ScriptsGrid', () => {
const mockOnInstallScript = vi.fn()
beforeEach(async () => {
vi.clearAllMocks()
mockOnInstallScript.mockClear()
})
it('should render loading state', async () => {
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({ data: null, isLoading: true, error: null })
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: null, isLoading: true, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
expect(screen.getByText('Loading scripts...')).toBeInTheDocument()
})
it('should render error state', async () => {
const mockRefetch = vi.fn()
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({
data: null,
isLoading: false,
error: { message: 'Test error' },
refetch: mockRefetch
})
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
expect(screen.getByText('Failed to load scripts')).toBeInTheDocument()
expect(screen.getByText('Test error')).toBeInTheDocument()
expect(screen.getByText('Try Again')).toBeInTheDocument()
})
it('should render empty state when no scripts', async () => {
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({ data: { success: true, cards: [] }, isLoading: false, error: null })
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: { scripts: [] }, isLoading: false, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
expect(screen.getByText('No scripts found')).toBeInTheDocument()
})
it('should render scripts grid with search functionality', async () => {
const mockScripts = [
{ name: 'Test Script 1', slug: 'test-script-1' },
{ name: 'Test Script 2', slug: 'test-script-2' },
]
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({
data: { success: true, cards: mockScripts },
isLoading: false,
error: null
})
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: { scripts: [] }, isLoading: false, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
expect(screen.getByTestId('script-card-test-script-1')).toBeInTheDocument()
expect(screen.getByTestId('script-card-test-script-2')).toBeInTheDocument()
// Test search functionality
const searchInput = screen.getByPlaceholderText('Search scripts by name...')
await userEvent.type(searchInput, 'Script 1')
await waitFor(() => {
expect(screen.getByTestId('script-card-test-script-1')).toBeInTheDocument()
expect(screen.queryByTestId('script-card-test-script-2')).not.toBeInTheDocument()
})
})
it('should handle script card click and open modal', async () => {
const mockScripts = [
{ name: 'Test Script', slug: 'test-script' },
]
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({
data: { success: true, cards: mockScripts },
isLoading: false,
error: null
})
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: { scripts: [] }, isLoading: false, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
const scriptCard = screen.getByTestId('script-card-test-script')
fireEvent.click(scriptCard)
expect(screen.getByTestId('script-detail-modal')).toBeInTheDocument()
})
it('should handle clear search', async () => {
const mockScripts = [
{ name: 'Test Script', slug: 'test-script' },
]
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({
data: { success: true, cards: mockScripts },
isLoading: false,
error: null
})
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: { scripts: [] }, isLoading: false, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
const searchInput = screen.getByPlaceholderText('Search scripts by name...')
await userEvent.type(searchInput, 'test')
// Clear search - the clear button doesn't have accessible text, so we'll click it directly
const clearButton = screen.getByRole('button')
fireEvent.click(clearButton)
expect(searchInput).toHaveValue('')
})
it('should show no matching scripts when search returns empty', async () => {
const mockScripts = [
{ name: 'Test Script', slug: 'test-script' },
]
const { api } = await import('~/trpc/react')
vi.mocked(api.scripts.getScriptCards.useQuery).mockReturnValue({
data: { success: true, cards: mockScripts },
isLoading: false,
error: null
})
vi.mocked(api.scripts.getCtScripts.useQuery).mockReturnValue({ data: { scripts: [] }, isLoading: false, error: null })
vi.mocked(api.scripts.getScriptBySlug.useQuery).mockReturnValue({ data: null, isLoading: false, error: null })
render(<ScriptsGrid onInstallScript={mockOnInstallScript} />)
const searchInput = screen.getByPlaceholderText('Search scripts by name...')
await userEvent.type(searchInput, 'nonexistent')
await waitFor(() => {
expect(screen.getByText('No matching scripts found')).toBeInTheDocument()
})
})
})

View File

@@ -43,22 +43,13 @@ export default function RootLayout({
} else {
document.documentElement.classList.remove('dark');
}
} catch (e) {
// Fallback to system preference if localStorage fails
const systemDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
if (systemDark) {
document.documentElement.classList.add('dark');
}
}
} catch (e) {}
})();
`,
}}
/>
</head>
<body
className="bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 transition-colors"
suppressHydrationWarning={true}
>
<body className="bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 transition-colors">
<DarkModeProvider>
{/* Dark Mode Toggle in top right corner */}
<div className="fixed top-4 right-4 z-50">

View File

@@ -35,15 +35,11 @@ export default function Home() {
{/* Controls */}
<div className="mb-8">
<div className="flex flex-col lg:flex-row lg:items-center lg:justify-between gap-6 p-6 bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700">
<div className="flex flex-col sm:flex-row sm:items-center gap-4">
<div className="flex items-left pr-4 mb-6">
<SettingsButton />
</div>
<div className="flex flex-col sm:flex-row sm:items-center gap-4">
<ResyncButton />
</div>
</div>
</div>
{/* Tab Navigation */}
<div className="mb-8">

View File

@@ -0,0 +1,368 @@
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { createCallerFactory } from '~/server/api/trpc'
import { scriptsRouter } from '../scripts'
// Mock dependencies
vi.mock('~/server/lib/scripts', () => ({
scriptManager: {
getScripts: vi.fn(),
getCtScripts: vi.fn(),
validateScriptPath: vi.fn(),
getScriptsDirectoryInfo: vi.fn(),
},
}))
vi.mock('~/server/lib/git', () => ({
gitManager: {
getStatus: vi.fn(),
pullUpdates: vi.fn(),
},
}))
vi.mock('~/server/services/githubJsonService', () => ({
githubJsonService: {
syncJsonFiles: vi.fn(),
getAllScripts: vi.fn(),
getScriptBySlug: vi.fn(),
},
}))
vi.mock('~/server/services/localScripts', () => ({
localScriptsService: {
getScriptCards: vi.fn(),
getAllScripts: vi.fn(),
getScriptBySlug: vi.fn(),
saveScriptsFromGitHub: vi.fn(),
},
}))
vi.mock('~/server/services/scriptDownloader', () => ({
scriptDownloaderService: {
loadScript: vi.fn(),
checkScriptExists: vi.fn(),
compareScriptContent: vi.fn(),
getScriptDiff: vi.fn(),
},
}))
vi.mock('fs/promises', () => ({
readFile: vi.fn(),
}))
vi.mock('path', () => ({
join: vi.fn((...args) => {
// Simulate path.join behavior for security check
const result = args.join('/')
// If the path contains '..', it should be considered invalid
if (result.includes('../')) {
return '/invalid/path'
}
return result
}),
}))
vi.mock('~/env', () => ({
env: {
SCRIPTS_DIRECTORY: '/test/scripts',
},
}))
describe('scriptsRouter', () => {
let caller: ReturnType<typeof createCallerFactory<typeof scriptsRouter>>
beforeEach(() => {
vi.clearAllMocks()
caller = createCallerFactory(scriptsRouter)({})
})
describe('getScripts', () => {
it('should return scripts and directory info', async () => {
const mockScripts = [
{ name: 'test.sh', path: '/test/scripts/test.sh', extension: '.sh' },
]
const mockDirectoryInfo = {
path: '/test/scripts',
allowedExtensions: ['.sh'],
allowedPaths: ['/'],
maxExecutionTime: 30000,
}
const { scriptManager } = await import('~/server/lib/scripts')
vi.mocked(scriptManager.getScripts).mockResolvedValue(mockScripts)
vi.mocked(scriptManager.getScriptsDirectoryInfo).mockReturnValue(mockDirectoryInfo)
const result = await caller.getScripts()
expect(result).toEqual({
scripts: mockScripts,
directoryInfo: mockDirectoryInfo,
})
})
})
describe('getCtScripts', () => {
it('should return CT scripts and directory info', async () => {
const mockScripts = [
{ name: 'ct-test.sh', path: '/test/scripts/ct/ct-test.sh', slug: 'ct-test' },
]
const mockDirectoryInfo = {
path: '/test/scripts',
allowedExtensions: ['.sh'],
allowedPaths: ['/'],
maxExecutionTime: 30000,
}
const { scriptManager } = await import('~/server/lib/scripts')
vi.mocked(scriptManager.getCtScripts).mockResolvedValue(mockScripts)
vi.mocked(scriptManager.getScriptsDirectoryInfo).mockReturnValue(mockDirectoryInfo)
const result = await caller.getCtScripts()
expect(result).toEqual({
scripts: mockScripts,
directoryInfo: mockDirectoryInfo,
})
})
})
describe('getScriptContent', () => {
it('should return script content for valid path', async () => {
const mockContent = '#!/bin/bash\necho "Hello World"'
const { readFile } = await import('fs/promises')
vi.mocked(readFile).mockResolvedValue(mockContent)
const result = await caller.getScriptContent({ path: 'test.sh' })
expect(result).toEqual({
success: true,
content: mockContent,
})
})
it('should return error for invalid path', async () => {
const result = await caller.getScriptContent({ path: '../../../etc/passwd' })
expect(result).toEqual({
success: false,
error: 'Failed to read script content',
})
})
})
describe('validateScript', () => {
it('should return validation result', async () => {
const mockValidation = { valid: true }
const { scriptManager } = await import('~/server/lib/scripts')
vi.mocked(scriptManager.validateScriptPath).mockReturnValue(mockValidation)
const result = await caller.validateScript({ scriptPath: '/test/scripts/test.sh' })
expect(result).toEqual(mockValidation)
})
})
describe('getDirectoryInfo', () => {
it('should return directory information', async () => {
const mockDirectoryInfo = {
path: '/test/scripts',
allowedExtensions: ['.sh'],
allowedPaths: ['/'],
maxExecutionTime: 30000,
}
const { scriptManager } = await import('~/server/lib/scripts')
vi.mocked(scriptManager.getScriptsDirectoryInfo).mockReturnValue(mockDirectoryInfo)
const result = await caller.getDirectoryInfo()
expect(result).toEqual(mockDirectoryInfo)
})
})
describe('getScriptCards', () => {
it('should return script cards on success', async () => {
const mockCards = [
{ name: 'Test Script', slug: 'test-script' },
]
const { localScriptsService } = await import('~/server/services/localScripts')
vi.mocked(localScriptsService.getScriptCards).mockResolvedValue(mockCards)
const result = await caller.getScriptCards()
expect(result).toEqual({
success: true,
cards: mockCards,
})
})
it('should return error on failure', async () => {
const { localScriptsService } = await import('~/server/services/localScripts')
vi.mocked(localScriptsService.getScriptCards).mockRejectedValue(new Error('Test error'))
const result = await caller.getScriptCards()
expect(result).toEqual({
success: false,
error: 'Test error',
cards: [],
})
})
})
describe('getScriptBySlug', () => {
it('should return script on success', async () => {
const mockScript = { name: 'Test Script', slug: 'test-script' }
const { githubJsonService } = await import('~/server/services/githubJsonService')
vi.mocked(githubJsonService.getScriptBySlug).mockResolvedValue(mockScript)
const result = await caller.getScriptBySlug({ slug: 'test-script' })
expect(result).toEqual({
success: true,
script: mockScript,
})
})
it('should return error when script not found', async () => {
const { githubJsonService } = await import('~/server/services/githubJsonService')
vi.mocked(githubJsonService.getScriptBySlug).mockResolvedValue(null)
const result = await caller.getScriptBySlug({ slug: 'nonexistent' })
expect(result).toEqual({
success: false,
error: 'Script not found',
script: null,
})
})
})
describe('resyncScripts', () => {
it('should resync scripts successfully', async () => {
const { githubJsonService } = await import('~/server/services/githubJsonService')
vi.mocked(githubJsonService.syncJsonFiles).mockResolvedValue({
success: true,
message: 'Successfully synced 2 scripts from GitHub using 1 API call + raw downloads',
count: 2
})
const result = await caller.resyncScripts()
expect(result).toEqual({
success: true,
message: 'Successfully synced 2 scripts from GitHub using 1 API call + raw downloads',
count: 2,
})
})
it('should return error on failure', async () => {
const { githubJsonService } = await import('~/server/services/githubJsonService')
vi.mocked(githubJsonService.syncJsonFiles).mockResolvedValue({
success: false,
message: 'GitHub error',
count: 0
})
const result = await caller.resyncScripts()
expect(result).toEqual({
success: false,
message: 'GitHub error',
count: 0,
})
})
})
describe('loadScript', () => {
it('should load script successfully', async () => {
const mockScript = { name: 'Test Script', slug: 'test-script' }
const mockResult = { success: true, files: ['test.sh'] }
const { localScriptsService } = await import('~/server/services/localScripts')
const { scriptDownloaderService } = await import('~/server/services/scriptDownloader')
vi.mocked(localScriptsService.getScriptBySlug).mockResolvedValue(mockScript)
vi.mocked(scriptDownloaderService.loadScript).mockResolvedValue(mockResult)
const result = await caller.loadScript({ slug: 'test-script' })
expect(result).toEqual(mockResult)
})
it('should return error when script not found', async () => {
const { localScriptsService } = await import('~/server/services/localScripts')
vi.mocked(localScriptsService.getScriptBySlug).mockResolvedValue(null)
const result = await caller.loadScript({ slug: 'nonexistent' })
expect(result).toEqual({
success: false,
error: 'Script not found',
files: [],
})
})
})
describe('checkScriptFiles', () => {
it('should check script files successfully', async () => {
const mockScript = { name: 'Test Script', slug: 'test-script' }
const mockResult = { ctExists: true, installExists: false, files: ['test.sh'] }
const { localScriptsService } = await import('~/server/services/localScripts')
const { scriptDownloaderService } = await import('~/server/services/scriptDownloader')
vi.mocked(localScriptsService.getScriptBySlug).mockResolvedValue(mockScript)
vi.mocked(scriptDownloaderService.checkScriptExists).mockResolvedValue(mockResult)
const result = await caller.checkScriptFiles({ slug: 'test-script' })
expect(result).toEqual({
success: true,
...mockResult,
})
})
})
describe('compareScriptContent', () => {
it('should compare script content successfully', async () => {
const mockScript = { name: 'Test Script', slug: 'test-script' }
const mockResult = { hasDifferences: true, differences: ['line 1'] }
const { localScriptsService } = await import('~/server/services/localScripts')
const { scriptDownloaderService } = await import('~/server/services/scriptDownloader')
vi.mocked(localScriptsService.getScriptBySlug).mockResolvedValue(mockScript)
vi.mocked(scriptDownloaderService.compareScriptContent).mockResolvedValue(mockResult)
const result = await caller.compareScriptContent({ slug: 'test-script' })
expect(result).toEqual({
success: true,
...mockResult,
})
})
})
describe('getScriptDiff', () => {
it('should get script diff successfully', async () => {
const mockScript = { name: 'Test Script', slug: 'test-script' }
const mockResult = { diff: 'diff content' }
const { localScriptsService } = await import('~/server/services/localScripts')
const { scriptDownloaderService } = await import('~/server/services/scriptDownloader')
vi.mocked(localScriptsService.getScriptBySlug).mockResolvedValue(mockScript)
vi.mocked(scriptDownloaderService.getScriptDiff).mockResolvedValue(mockResult)
const result = await caller.getScriptDiff({ slug: 'test-script', filePath: 'test.sh' })
expect(result).toEqual({
success: true,
...mockResult,
})
})
})
})

View File

@@ -105,7 +105,6 @@ export const installedScriptsRouter = createTRPCRouter({
updateInstalledScript: publicProcedure
.input(z.object({
id: z.number(),
script_name: z.string().optional(),
container_id: z.string().optional(),
status: z.enum(['in_progress', 'success', 'failed']).optional(),
output_log: z.string().optional()

View File

@@ -4,7 +4,6 @@ import { scriptManager } from "~/server/lib/scripts";
import { githubJsonService } from "~/server/services/githubJsonService";
import { localScriptsService } from "~/server/services/localScripts";
import { scriptDownloaderService } from "~/server/services/scriptDownloader";
import type { ScriptCard } from "~/types/script";
export const scriptsRouter = createTRPCRouter({
// Get all available scripts
@@ -122,68 +121,6 @@ export const scriptsRouter = createTRPCRouter({
}
}),
// Get metadata (categories and other metadata)
getMetadata: publicProcedure
.query(async () => {
try {
const metadata = await localScriptsService.getMetadata();
return { success: true, metadata };
} catch (error) {
console.error('Error in getMetadata:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch metadata',
metadata: null
};
}
}),
// Get script cards with category information
getScriptCardsWithCategories: publicProcedure
.query(async () => {
try {
const [cards, metadata] = await Promise.all([
localScriptsService.getScriptCards(),
localScriptsService.getMetadata()
]);
// Get all scripts to access their categories
const scripts = await localScriptsService.getAllScripts();
// Create category ID to name mapping
const categoryMap: Record<number, string> = {};
if (metadata?.categories) {
metadata.categories.forEach((cat: any) => {
categoryMap[cat.id] = cat.name;
});
}
// Enhance cards with category information and additional script data
const cardsWithCategories = cards.map(card => {
const script = scripts.find(s => s.slug === card.slug);
const categoryNames: string[] = script?.categories?.map(id => categoryMap[id]).filter((name): name is string => typeof name === 'string') ?? [];
return {
...card,
categories: script?.categories ?? [],
categoryNames: categoryNames,
// Add date_created from script
date_created: script?.date_created,
} as ScriptCard;
});
return { success: true, cards: cardsWithCategories, metadata };
} catch (error) {
console.error('Error in getScriptCardsWithCategories:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Failed to fetch script cards with categories',
cards: [],
metadata: null
};
}
}),
// Resync scripts from GitHub (1 API call + raw downloads)
resyncScripts: publicProcedure
.mutation(async () => {

View File

@@ -167,20 +167,15 @@ class DatabaseService {
/**
* @param {number} id
* @param {Object} updateData
* @param {string} [updateData.script_name]
* @param {string} [updateData.container_id]
* @param {string} [updateData.status]
* @param {string} [updateData.output_log]
*/
updateInstalledScript(id, updateData) {
const { script_name, container_id, status, output_log } = updateData;
const { container_id, status, output_log } = updateData;
const updates = [];
const values = [];
if (script_name !== undefined) {
updates.push('script_name = ?');
values.push(script_name);
}
if (container_id !== undefined) {
updates.push('container_id = ?');
values.push(container_id);

View File

@@ -0,0 +1,349 @@
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
// Create mock functions using vi.hoisted
const mockReaddir = vi.hoisted(() => vi.fn())
const mockStat = vi.hoisted(() => vi.fn())
const mockReadFile = vi.hoisted(() => vi.fn())
const mockSpawn = vi.hoisted(() => vi.fn())
// Mock the dependencies before importing ScriptManager
vi.mock('fs/promises', () => ({
readdir: mockReaddir,
stat: mockStat,
readFile: mockReadFile,
default: {
readdir: mockReaddir,
stat: mockStat,
readFile: mockReadFile,
}
}))
vi.mock('child_process', () => ({
spawn: mockSpawn,
default: {
spawn: mockSpawn,
}
}))
vi.mock('~/env.js', () => ({
env: {
SCRIPTS_DIRECTORY: '/test/scripts',
ALLOWED_SCRIPT_EXTENSIONS: '.sh,.py,.js,.ts',
ALLOWED_SCRIPT_PATHS: '/,/ct/',
MAX_SCRIPT_EXECUTION_TIME: '30000',
},
}))
vi.mock('~/server/services/localScripts', () => ({
localScriptsService: {
getScriptBySlug: vi.fn(),
},
}))
// Import after mocking
import { ScriptManager } from '../scripts'
describe('ScriptManager', () => {
let scriptManager: ScriptManager
beforeEach(async () => {
vi.clearAllMocks()
scriptManager = new ScriptManager()
})
afterEach(() => {
vi.clearAllMocks()
})
describe('constructor', () => {
it('should initialize with correct configuration', () => {
const info = scriptManager.getScriptsDirectoryInfo()
expect(info.path).toBe('/test/scripts')
expect(info.allowedExtensions).toEqual(['.sh', '.py', '.js', '.ts'])
expect(info.allowedPaths).toEqual(['/', '/ct/'])
expect(info.maxExecutionTime).toBe(30000)
})
})
describe('getScripts', () => {
it('should return empty array when directory read fails', async () => {
mockReaddir.mockRejectedValue(new Error('Directory not found'))
const scripts = await scriptManager.getScripts()
expect(scripts).toEqual([])
})
it('should return scripts with correct properties', async () => {
const mockFiles = ['script1.sh', 'script2.py', 'script3.js', 'readme.txt']
mockReaddir.mockResolvedValue(mockFiles)
mockStat.mockImplementation((filePath) => {
// Mock different responses based on file path
if (filePath.includes('script1.sh') || filePath.includes('script2.py') || filePath.includes('script3.js')) {
return Promise.resolve({
isFile: () => true,
isDirectory: () => false,
size: 1024,
mtime: new Date('2024-01-01T00:00:00Z'),
mode: 0o755, // executable permissions
} as any)
}
return Promise.resolve({
isFile: () => false,
isDirectory: () => true,
size: 0,
mtime: new Date('2024-01-01T00:00:00Z'),
mode: 0o755,
} as any)
})
const scripts = await scriptManager.getScripts()
expect(scripts).toHaveLength(3) // Only .sh, .py, .js files
expect(scripts[0]).toMatchObject({
name: 'script1.sh',
path: '/test/scripts/script1.sh',
extension: '.sh',
size: 1024,
executable: true,
})
expect(scripts[1]).toMatchObject({
name: 'script2.py',
path: '/test/scripts/script2.py',
extension: '.py',
size: 1024,
executable: true,
})
expect(scripts[2]).toMatchObject({
name: 'script3.js',
path: '/test/scripts/script3.js',
extension: '.js',
size: 1024,
executable: true,
})
})
it('should sort scripts alphabetically', async () => {
const mockFiles = ['z_script.sh', 'a_script.sh', 'm_script.sh']
mockReaddir.mockResolvedValue(mockFiles)
mockStat.mockResolvedValue({
isFile: () => true,
isDirectory: () => false,
size: 1024,
mtime: new Date('2024-01-01T00:00:00Z'),
mode: 0o755,
} as any)
const scripts = await scriptManager.getScripts()
expect(scripts.map(s => s.name)).toEqual(['a_script.sh', 'm_script.sh', 'z_script.sh'])
})
})
describe('getCtScripts', () => {
it('should return ct scripts with slug and logo', async () => {
const mockFiles = ['test-script.sh']
// Mock readdir for the ct directory
mockReaddir.mockImplementation((dirPath) => {
if (dirPath.includes('/ct')) {
return Promise.resolve(mockFiles)
}
return Promise.resolve([])
})
mockStat.mockResolvedValue({
isFile: () => true,
isDirectory: () => false,
size: 1024,
mtime: new Date('2024-01-01T00:00:00Z'),
mode: 0o755,
} as any)
// Mock the localScriptsService
const { localScriptsService } = await import('~/server/services/localScripts')
vi.mocked(localScriptsService.getScriptBySlug).mockResolvedValue({
logo: 'test-logo.png',
name: 'Test Script',
description: 'A test script',
} as { logo: string; name: string; description: string })
const scripts = await scriptManager.getCtScripts()
expect(scripts).toHaveLength(1)
expect(scripts[0]).toMatchObject({
name: 'test-script.sh',
path: '/test/scripts/ct/test-script.sh',
slug: 'test-script',
logo: 'test-logo.png',
})
})
it('should handle missing logo gracefully', async () => {
const mockFiles = ['test-script.sh']
// Mock readdir for the ct directory
mockReaddir.mockImplementation((dirPath) => {
if (dirPath.includes('/ct')) {
return Promise.resolve(mockFiles)
}
return Promise.resolve([])
})
mockStat.mockResolvedValue({
isFile: () => true,
isDirectory: () => false,
size: 1024,
mtime: new Date('2024-01-01T00:00:00Z'),
mode: 0o755,
} as any)
const { localScriptsService } = await import('~/server/services/localScripts')
vi.mocked(localScriptsService.getScriptBySlug).mockRejectedValue(new Error('Not found'))
const scripts = await scriptManager.getCtScripts()
expect(scripts).toHaveLength(1)
expect(scripts[0].logo).toBeUndefined()
})
})
describe('validateScriptPath', () => {
it('should validate correct script path', () => {
const result = scriptManager.validateScriptPath('/test/scripts/valid-script.sh')
expect(result.valid).toBe(true)
expect(result.message).toBeUndefined()
})
it('should reject path outside scripts directory', () => {
const result = scriptManager.validateScriptPath('/other/path/script.sh')
expect(result.valid).toBe(false)
expect(result.message).toBe('Script path is not within the allowed scripts directory')
})
it('should reject path not in allowed paths', () => {
const result = scriptManager.validateScriptPath('/test/scripts/forbidden/script.sh')
expect(result.valid).toBe(false)
expect(result.message).toBe('Script path is not in the allowed paths list')
})
it('should reject invalid file extension', () => {
const result = scriptManager.validateScriptPath('/test/scripts/script.exe')
expect(result.valid).toBe(false)
expect(result.message).toContain('File extension')
})
it('should accept ct subdirectory paths', () => {
const result = scriptManager.validateScriptPath('/test/scripts/ct/script.sh')
expect(result.valid).toBe(true)
})
})
describe('executeScript', () => {
it('should execute bash script correctly', async () => {
const mockChildProcess = {
kill: vi.fn(),
on: vi.fn(),
killed: false,
stdout: { on: vi.fn() },
stderr: { on: vi.fn() },
stdin: { write: vi.fn(), end: vi.fn() },
}
mockSpawn.mockReturnValue(mockChildProcess as any)
const childProcess = await scriptManager.executeScript('/test/scripts/script.sh')
expect(mockSpawn).toHaveBeenCalledWith('bash', ['/test/scripts/script.sh'], {
cwd: '/test/scripts',
stdio: ['pipe', 'pipe', 'pipe'],
shell: true,
})
expect(childProcess).toBe(mockChildProcess)
})
it('should execute python script correctly', async () => {
const mockChildProcess = {
kill: vi.fn(),
on: vi.fn(),
killed: false,
stdout: { on: vi.fn() },
stderr: { on: vi.fn() },
stdin: { write: vi.fn(), end: vi.fn() },
}
mockSpawn.mockReturnValue(mockChildProcess as any)
await scriptManager.executeScript('/test/scripts/script.py')
expect(mockSpawn).toHaveBeenCalledWith('python', ['/test/scripts/script.py'], {
cwd: '/test/scripts',
stdio: ['pipe', 'pipe', 'pipe'],
shell: true,
})
})
it('should throw error for invalid script path', async () => {
await expect(scriptManager.executeScript('/invalid/path/script.sh'))
.rejects.toThrow('Script path is not within the allowed scripts directory')
})
it('should set up timeout correctly', async () => {
vi.useFakeTimers()
const mockChildProcess = {
kill: vi.fn(),
on: vi.fn(),
killed: false,
stdout: { on: vi.fn() },
stderr: { on: vi.fn() },
stdin: { write: vi.fn(), end: vi.fn() },
}
mockSpawn.mockReturnValue(mockChildProcess as any)
await scriptManager.executeScript('/test/scripts/script.sh')
// Fast-forward time to trigger timeout
vi.advanceTimersByTime(30001)
expect(mockChildProcess.kill).toHaveBeenCalledWith('SIGTERM')
vi.useRealTimers()
})
})
describe('getScriptContent', () => {
it('should return script content', async () => {
const mockContent = '#!/bin/bash\necho "Hello World"'
mockReadFile.mockResolvedValue(mockContent)
const content = await scriptManager.getScriptContent('/test/scripts/script.sh')
expect(content).toBe(mockContent)
expect(mockReadFile).toHaveBeenCalledWith('/test/scripts/script.sh', 'utf-8')
})
it('should throw error for invalid script path', async () => {
await expect(scriptManager.getScriptContent('/invalid/path/script.sh'))
.rejects.toThrow('Script path is not within the allowed scripts directory')
})
})
describe('getScriptsDirectoryInfo', () => {
it('should return correct directory information', () => {
const info = scriptManager.getScriptsDirectoryInfo()
expect(info).toEqual({
path: '/test/scripts',
allowedExtensions: ['.sh', '.py', '.js', '.ts'],
allowedPaths: ['/', '/ct/'],
maxExecutionTime: 30000,
})
})
})
})

View File

@@ -84,15 +84,6 @@ export class ScriptManager {
this.initializeConfig();
try {
const ctDir = join(this.scriptsDir!, 'ct');
// Check if ct directory exists
try {
await stat(ctDir);
} catch {
console.warn(`CT scripts directory not found: ${ctDir}`);
return [];
}
const files = await readdir(ctDir);
const scripts: ScriptInfo[] = [];

View File

@@ -90,17 +90,6 @@ export class LocalScriptsService {
}
}
async getMetadata(): Promise<any> {
try {
const filePath = join(this.scriptsDirectory, 'metadata.json');
const content = await readFile(filePath, 'utf-8');
return JSON.parse(content);
} catch (error) {
console.error('Error reading metadata file:', error);
throw new Error('Failed to read metadata');
}
}
async saveScriptsFromGitHub(scripts: Script[]): Promise<void> {
try {
// Ensure the directory exists

View File

@@ -0,0 +1,24 @@
import { vi } from 'vitest'
export const mockSpawn = vi.fn()
export const mockChildProcess = {
kill: vi.fn(),
on: vi.fn(),
killed: false,
stdout: {
on: vi.fn(),
},
stderr: {
on: vi.fn(),
},
stdin: {
write: vi.fn(),
end: vi.fn(),
},
}
export const resetMocks = () => {
mockSpawn.mockReset()
mockSpawn.mockReturnValue(mockChildProcess)
}

21
src/test/__mocks__/fs.ts Normal file
View File

@@ -0,0 +1,21 @@
import { vi } from 'vitest'
export const mockStats = {
isFile: vi.fn(() => true),
isDirectory: vi.fn(() => false),
size: 1024,
mtime: new Date('2024-01-01T00:00:00Z'),
mode: 0o755, // executable permissions
}
export const mockReaddir = vi.fn()
export const mockStat = vi.fn()
export const mockReadFile = vi.fn()
export const resetMocks = () => {
mockReaddir.mockReset()
mockStat.mockReset()
mockReadFile.mockReset()
mockStats.isFile.mockReset()
mockStats.isDirectory.mockReset()
}

24
src/test/setup.ts Normal file
View File

@@ -0,0 +1,24 @@
import '@testing-library/jest-dom'
import { vi } from 'vitest'
// Global test utilities
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}))
// Mock window.matchMedia
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(), // deprecated
removeListener: vi.fn(), // deprecated
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
})

View File

@@ -51,12 +51,7 @@ export interface ScriptCard {
website: string | null;
source?: 'github' | 'local';
isDownloaded?: boolean;
isUpToDate?: boolean;
localPath?: string;
// Additional properties added by API
categories?: number[];
categoryNames?: string[];
date_created?: string;
}
export interface GitHubFile {

View File

0
test/scripts/script1.sh Normal file
View File

0
test/scripts/script2.py Normal file
View File

0
test/scripts/script3.js Normal file
View File

View File

@@ -7,6 +7,7 @@ export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts'],
include: ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
exclude: ['node_modules', 'dist', '.next', '.git'],
coverage: {