mirror of
				https://github.com/community-scripts/ProxmoxVE.git
				synced 2025-11-04 10:22:50 +00:00 
			
		
		
		
	Update Frontedn (#3216)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							9f2d44879f
						
					
				
				
					commit
					05d4064f03
				
			
							
								
								
									
										46
									
								
								frontend/src/app/api/versions/route.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								frontend/src/app/api/versions/route.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					import { AppVersion } from "@/lib/types";
 | 
				
			||||||
 | 
					import { error } from "console";
 | 
				
			||||||
 | 
					import { promises as fs } from "fs";
 | 
				
			||||||
 | 
					// import Error from "next/error";
 | 
				
			||||||
 | 
					import { NextResponse } from "next/server";
 | 
				
			||||||
 | 
					import path from "path";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const dynamic = "force-static";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const jsonDir = "public/json";
 | 
				
			||||||
 | 
					const versionsFileName = "versions.json";
 | 
				
			||||||
 | 
					const encoding = "utf-8";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const getVersions = async () => {
 | 
				
			||||||
 | 
					  const filePath = path.resolve(jsonDir, versionsFileName);
 | 
				
			||||||
 | 
					  const fileContent = await fs.readFile(filePath, encoding);
 | 
				
			||||||
 | 
					  const versions: AppVersion[] = JSON.parse(fileContent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const modifiedVersions = versions.map(version => {
 | 
				
			||||||
 | 
					    const nameParts = version.name.split('/');
 | 
				
			||||||
 | 
					    let newName = nameParts[nameParts.length - 1];
 | 
				
			||||||
 | 
					    newName = newName.toLowerCase().replace(/[^a-z0-9]/g, '');
 | 
				
			||||||
 | 
					    return { ...version, name: newName };
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return modifiedVersions;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export async function GET() {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const versions = await getVersions();
 | 
				
			||||||
 | 
					    return NextResponse.json(versions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  } catch (error) {
 | 
				
			||||||
 | 
					    console.error(error);
 | 
				
			||||||
 | 
					    const err = error as globalThis.Error;
 | 
				
			||||||
 | 
					    return NextResponse.json({
 | 
				
			||||||
 | 
					      name: err.name,
 | 
				
			||||||
 | 
					      message: err.message || "An unexpected error occurred",
 | 
				
			||||||
 | 
					      version: "No version found - Error"
 | 
				
			||||||
 | 
					    }, {
 | 
				
			||||||
 | 
					      status: 500,
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,7 +1,9 @@
 | 
				
			|||||||
"use client";
 | 
					
 | 
				
			||||||
import { Separator } from "@/components/ui/separator";
 | 
					import { Separator } from "@/components/ui/separator";
 | 
				
			||||||
import { extractDate } from "@/lib/time";
 | 
					import { extractDate } from "@/lib/time";
 | 
				
			||||||
import { Script } from "@/lib/types";
 | 
					import { Script, AppVersion } from "@/lib/types";
 | 
				
			||||||
 | 
					import { fetchVersions } from "@/lib/data";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { X } from "lucide-react";
 | 
					import { X } from "lucide-react";
 | 
				
			||||||
import Image from "next/image";
 | 
					import Image from "next/image";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -15,6 +17,8 @@ import InstallCommand from "./ScriptItems/InstallCommand";
 | 
				
			|||||||
import InterFaces from "./ScriptItems/InterFaces";
 | 
					import InterFaces from "./ScriptItems/InterFaces";
 | 
				
			||||||
import Tooltips from "./ScriptItems/Tooltips";
 | 
					import Tooltips from "./ScriptItems/Tooltips";
 | 
				
			||||||
import { basePath } from "@/config/siteConfig";
 | 
					import { basePath } from "@/config/siteConfig";
 | 
				
			||||||
 | 
					import { useEffect, useState } from "react";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function ScriptItem({
 | 
					function ScriptItem({
 | 
				
			||||||
  item,
 | 
					  item,
 | 
				
			||||||
@@ -27,6 +31,23 @@ function ScriptItem({
 | 
				
			|||||||
    window.history.pushState({}, document.title, window.location.pathname);
 | 
					    window.history.pushState({}, document.title, window.location.pathname);
 | 
				
			||||||
    setSelectedScript(null);
 | 
					    setSelectedScript(null);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					  const [versions, setVersions] = useState<AppVersion[]>([]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  useEffect(() => {
 | 
				
			||||||
 | 
					    fetchVersions()
 | 
				
			||||||
 | 
					      .then((fetchedVersions) => {
 | 
				
			||||||
 | 
					        console.log("Fetched Versions: ", fetchedVersions);
 | 
				
			||||||
 | 
					        if (Array.isArray(fetchedVersions)) {
 | 
				
			||||||
 | 
					          setVersions(fetchedVersions);
 | 
				
			||||||
 | 
					        } else if (fetchedVersions && typeof fetchedVersions === "object") {
 | 
				
			||||||
 | 
					          setVersions([fetchedVersions]);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					          setVersions([]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					      .catch((error) => console.error("Error fetching versions:", error));
 | 
				
			||||||
 | 
					  }, []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const defaultInstallMethod = item.install_methods?.[0];
 | 
					  const defaultInstallMethod = item.install_methods?.[0];
 | 
				
			||||||
  const os = defaultInstallMethod?.resources?.os || "Proxmox Node";
 | 
					  const os = defaultInstallMethod?.resources?.os || "Proxmox Node";
 | 
				
			||||||
@@ -48,8 +69,8 @@ function ScriptItem({
 | 
				
			|||||||
                  src={item.logo || `/${basePath}/logo.png`}
 | 
					                  src={item.logo || `/${basePath}/logo.png`}
 | 
				
			||||||
                  width={400}
 | 
					                  width={400}
 | 
				
			||||||
                  onError={(e) =>
 | 
					                  onError={(e) =>
 | 
				
			||||||
                    ((e.currentTarget as HTMLImageElement).src =
 | 
					                  ((e.currentTarget as HTMLImageElement).src =
 | 
				
			||||||
                      `/${basePath}/logo.png`)
 | 
					                    `/${basePath}/logo.png`)
 | 
				
			||||||
                  }
 | 
					                  }
 | 
				
			||||||
                  height={400}
 | 
					                  height={400}
 | 
				
			||||||
                  alt={item.name}
 | 
					                  alt={item.name}
 | 
				
			||||||
@@ -71,6 +92,13 @@ function ScriptItem({
 | 
				
			|||||||
                    <div className="flex gap-5">
 | 
					                    <div className="flex gap-5">
 | 
				
			||||||
                      <DefaultSettings item={item} />
 | 
					                      <DefaultSettings item={item} />
 | 
				
			||||||
                    </div>
 | 
					                    </div>
 | 
				
			||||||
 | 
					                    <div>{versions.length === 0 ? (<p>Loading versions...</p>) :
 | 
				
			||||||
 | 
					                      (<>
 | 
				
			||||||
 | 
					                        <p className="text-l text-foreground">Version:</p>
 | 
				
			||||||
 | 
					                        <p className="text-l text-muted-foreground">{versions.find((v) => v.name === item.slug.replace(/[^a-z0-9]/g, ''))?.version || "No Version Information found"}</p>
 | 
				
			||||||
 | 
					                      </>)
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
                  </div>
 | 
					                  </div>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
              </div>
 | 
					              </div>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,3 +8,11 @@ export const fetchCategories = async () => {
 | 
				
			|||||||
  const categories: Category[] = await response.json();
 | 
					  const categories: Category[] = await response.json();
 | 
				
			||||||
  return categories;
 | 
					  return categories;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const fetchVersions = async () => {
 | 
				
			||||||
 | 
					  const response = await fetch(`api/versions`);
 | 
				
			||||||
 | 
					  if (!response.ok) {
 | 
				
			||||||
 | 
					      throw new Error(`Failed to fetch versions: ${response.statusText}`);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return response.json();
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -55,4 +55,9 @@ export interface Version {
 | 
				
			|||||||
export interface OperatingSystem {
 | 
					export interface OperatingSystem {
 | 
				
			||||||
  name: string;
 | 
					  name: string;
 | 
				
			||||||
  versions: Version[];
 | 
					  versions: Version[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface AppVersion {
 | 
				
			||||||
 | 
					  name: string;
 | 
				
			||||||
 | 
					  version: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user