From 8129e3cf394b864016977d44b4f40254ff757314 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner <73236783+michelroegl-brunner@users.noreply.github.com> Date: Tue, 4 Feb 2025 13:23:20 +0100 Subject: [PATCH] [API] Masiv update to api (#1990) * Masiv refactor of the api * Masiv refactor of the api * Format page.tsx * Format page.tsx * testing * update build.func * Change urls to Repo * Change urls to Repo * update install.func * Add post_to_api_vm * Update api.func * Update api.func * Update api.func * update api.func --- frontend/src/app/data/page.tsx | 80 ++++++++------------- misc/api.func | 125 +++++++++++++++++++++++++++++++++ misc/build.func | 78 ++------------------ misc/install.func | 6 +- 4 files changed, 164 insertions(+), 125 deletions(-) create mode 100644 misc/api.func diff --git a/frontend/src/app/data/page.tsx b/frontend/src/app/data/page.tsx index 462158f65..e78b4a675 100644 --- a/frontend/src/app/data/page.tsx +++ b/frontend/src/app/data/page.tsx @@ -11,18 +11,16 @@ interface DataModel { disk_size: number; core_count: number; ram_size: number; - verbose: string; os_type: string; os_version: string; - hn: string; disableip6: string; - ssh: string; - tags: string; nsapp: string; created_at: string; method: string; pve_version: string; status: string; + error: string; + type: string; } @@ -36,8 +34,8 @@ const DataFetcher: React.FC = () => { const [sortConfig, setSortConfig] = useState<{ key: keyof DataModel | null, direction: 'ascending' | 'descending' }>({ key: 'id', direction: 'descending' }); const [itemsPerPage, setItemsPerPage] = useState(25); const [currentPage, setCurrentPage] = useState(1); - const [interval, setIntervalTime] = useState(10); // Default interval 10 seconds - const [reloadInterval, setReloadInterval] = useState(null); + + const [showErrorRow, setShowErrorRow] = useState(null); useEffect(() => { @@ -118,38 +116,6 @@ const DataFetcher: React.FC = () => { const paginatedData = sortedData.slice((currentPage - 1) * itemsPerPage, currentPage * itemsPerPage); - useEffect(() => { - const storedInterval = localStorage.getItem('reloadInterval'); - if (storedInterval) { - setIntervalTime(Number(storedInterval)); - } - }, []); - - - useEffect(() => { - if (interval <= 10) { - const newInterval = setInterval(() => { - window.location.reload(); - }, 10000); - - - return () => clearInterval(newInterval); - } else { - const newInterval = setInterval(() => { - window.location.reload(); - }, interval * 1000); - } - - }, [interval]); - - - useEffect(() => { - if (interval > 0) { - localStorage.setItem('reloadInterval', interval.toString()); - } else { - localStorage.removeItem('reloadInterval'); - } - }, [interval]); if (loading) return

Loading...

; if (error) return

Error: {error}

; @@ -211,19 +177,6 @@ const DataFetcher: React.FC = () => { /> - -
-
- setIntervalTime(Number(e.target.value))} - className="p-2 border" - placeholder="Interval (seconds)" - /> - -
-
@@ -242,6 +195,7 @@ const DataFetcher: React.FC = () => { requestSort('status')}>Status + requestSort('type')}>Type requestSort('nsapp')}>Application requestSort('os_type')}>OS requestSort('os_version')}>OS Version @@ -250,6 +204,7 @@ const DataFetcher: React.FC = () => { requestSort('ram_size')}>RAM Size requestSort('method')}>Method requestSort('pve_version')}>PVE Version + requestSort('error')}>Error Message requestSort('created_at')}>Created At @@ -262,11 +217,18 @@ const DataFetcher: React.FC = () => { ) : item.status === "failed" ? ( "❌" ) : item.status === "installing" ? ( - "🔄" + "🔄" ) : ( item.status )} + {item.type === "lxc" ? ( + "📦" + ) : item.type === "vm" ? ( + "🖥️" + ) : ( + item.type + )} {item.nsapp} {item.os_type} {item.os_version} @@ -275,6 +237,20 @@ const DataFetcher: React.FC = () => { {item.ram_size} {item.method} {item.pve_version} + + {item.error && item.error !== "none" ? ( + showErrorRow === index ? ( + <> + {item.error} + + + ) : ( + + ) + ) : ( + "none" + )} + {formatDate(item.created_at)} ))} diff --git a/misc/api.func b/misc/api.func new file mode 100644 index 000000000..b1faa0c2a --- /dev/null +++ b/misc/api.func @@ -0,0 +1,125 @@ +# Copyright (c) 2021-2025 community-scripts ORG +# Author: michelroegl-brunner +# License: MIT | https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/LICENSE + +post_to_api() { + + if ! command -v curl &> /dev/null; then + return + fi + + if [ "$DIAGNOSTICS" = "no" ]; then + return + fi + + if [ -z "$RANDOM_UUID" ]; then + return + fi + + local API_URL="http://api.community-scripts.org/upload" + local pve_version="not found" + pve_version=$(pveversion | awk -F'[/ ]' '{print $2}') + + JSON_PAYLOAD=$(cat < /dev/null; then + return + fi + + if [ "$POST_UPDATE_DONE" = true ]; then + return 0 + fi + local API_URL="http://api.community-scripts.org/upload/updatestatus" + local status="${1:-failed}" + local error="${2:-unknown}" + + JSON_PAYLOAD=$(cat < /dev/null; then kill $SPINNER_PID > /dev/null; fi printf "\e[?25h" local exit_code="$?" @@ -63,8 +64,11 @@ error_handler() { local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" echo -e "\n$error_message" - if [[ "$line_number" -eq 23 ]]; then + if [[ "$line_number" -eq 44 ]]; then echo -e "The silent function has suppressed the error, run the script with verbose mode enabled, which will provide more detailed output.\n" + post_update_to_api "failed" "No error message, script ran in silent mode" + else + post_update_to_api "failed" "${command}" fi }