From 8d872ceeeaf17be2dabd7e7c6f9836bb6c2bb2e5 Mon Sep 17 00:00:00 2001 From: Michel Roegl-Brunner Date: Mon, 17 Mar 2025 14:25:27 +0100 Subject: [PATCH 1/2] Add Version Tag to frontend --- frontend/src/app/api/versions/route.ts | 48 ++++++++++++++++ .../app/scripts/_components/ScriptItem.tsx | 56 ++++++++++++++++--- frontend/src/lib/data.ts | 8 +++ frontend/src/lib/types.ts | 8 ++- 4 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 frontend/src/app/api/versions/route.ts diff --git a/frontend/src/app/api/versions/route.ts b/frontend/src/app/api/versions/route.ts new file mode 100644 index 0000000..be6099c --- /dev/null +++ b/frontend/src/app/api/versions/route.ts @@ -0,0 +1,48 @@ +import { AppVersion } from "@/lib/types"; +import { promises as fs } from "fs"; +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); + console.log("TEST"); + console.log("FilePath: ", filePath); + const fileContent = await fs.readFile(filePath, encoding); + const versions: AppVersion = JSON.parse(fileContent); + return versions; +}; + + +export async function GET(request: Request) { + try { + const { searchParams } = new URL(request.url); + const slug = searchParams.get("slug"); + + if (!slug) { + return NextResponse.json({ error: "Missing slug parameter" }, { status: 400 }); + } + console.log("Slug: ", slug); + const versions = await getVersions(); + + const cleanedSlug = slug.toLowerCase().replace(/[^a-z0-9]/g, ''); + + const matchedVersion = Object.values(versions).find( + (version: AppVersion) => { + const versionNameParts = version.name.split('/'); + const cleanedVersionName = versionNameParts[1]?.toLowerCase().replace(/[^a-z0-9]/g, ''); + return cleanedVersionName === cleanedSlug; + } + ); + + return NextResponse.json(matchedVersion); + } catch (error) { + console.error(error); + return NextResponse.json({name: "name", version: "No version found"}); + } +} diff --git a/frontend/src/app/scripts/_components/ScriptItem.tsx b/frontend/src/app/scripts/_components/ScriptItem.tsx index 973514a..b712e04 100644 --- a/frontend/src/app/scripts/_components/ScriptItem.tsx +++ b/frontend/src/app/scripts/_components/ScriptItem.tsx @@ -1,7 +1,9 @@ "use client"; import { Separator } from "@/components/ui/separator"; 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 Image from "next/image"; @@ -15,22 +17,48 @@ import InstallCommand from "./ScriptItems/InstallCommand"; import InterFaces from "./ScriptItems/InterFaces"; import Tooltips from "./ScriptItems/Tooltips"; import { basePath } from "@/config/siteConfig"; +import { useEffect, useState } from "react"; + +interface ScriptItemProps { + item: Script; + setSelectedScript: (script: string | null) => void; +} function ScriptItem({ item, setSelectedScript, -}: { - item: Script; - setSelectedScript: (script: string | null) => void; -}) { +}: ScriptItemProps) { + + const closeScript = () => { window.history.pushState({}, document.title, window.location.pathname); setSelectedScript(null); - }; +}; + + const [versions, setVersions] = useState([]); + + +useEffect(() => { + fetchVersions(item.slug) + .then((fetchedVersions) => { + console.log("Fetched Versions: ", fetchedVersions); + + // Ensure fetchedVersions is always an array + if (Array.isArray(fetchedVersions)) { + setVersions(fetchedVersions); + } else if (fetchedVersions && typeof fetchedVersions === "object") { + setVersions([fetchedVersions]); // Wrap object in an array + } else { + setVersions([]); // Fallback to empty array + } + }) + .catch((error) => console.error("Error fetching versions:", error)); +}, [item.name]); + +const defaultInstallMethod = item.install_methods?.[0]; +const os = defaultInstallMethod?.resources?.os || "Proxmox Node"; +const version = defaultInstallMethod?.resources?.version || ""; - const defaultInstallMethod = item.install_methods?.[0]; - const os = defaultInstallMethod?.resources?.os || "Proxmox Node"; - const version = defaultInstallMethod?.resources?.version || ""; return (
@@ -71,6 +99,16 @@ function ScriptItem({
+
+ + + {versions.length === 0 ? ( +

Loading versions...

+ ) : ( +

Version: {versions[0].version}

+ )} + +
diff --git a/frontend/src/lib/data.ts b/frontend/src/lib/data.ts index 9967803..48bae86 100644 --- a/frontend/src/lib/data.ts +++ b/frontend/src/lib/data.ts @@ -8,3 +8,11 @@ export const fetchCategories = async () => { const categories: Category[] = await response.json(); return categories; }; + +export const fetchVersions = async (slug: string) => { + const response = await fetch(`api/versions?slug=${slug}`); + if (!response.ok) { + throw new Error(`Failed to fetch versions: ${response.statusText}`); + } + return response.json(); +}; diff --git a/frontend/src/lib/types.ts b/frontend/src/lib/types.ts index 2dfa971..c44ba4a 100644 --- a/frontend/src/lib/types.ts +++ b/frontend/src/lib/types.ts @@ -13,6 +13,7 @@ export type Script = { website: string | null; logo: string | null; description: string; + version: string; install_methods: { type: "default" | "alpine"; script: string; @@ -47,6 +48,11 @@ export type Metadata = { categories: Category[]; }; +export interface AppVersion { + name: string; + version: string; +} + export interface Version { name: string; slug: string; @@ -55,4 +61,4 @@ export interface Version { export interface OperatingSystem { name: string; versions: Version[]; -} \ No newline at end of file +} From 6894e1511eef3f7e6822670f7fc95372710cc2ee Mon Sep 17 00:00:00 2001 From: tremor021 Date: Mon, 17 Mar 2025 14:40:30 +0100 Subject: [PATCH 2/2] Move from git pull to tarball --- ct/cryptpad.sh | 10 ++++++++-- install/cryptpad-install.sh | 12 +++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ct/cryptpad.sh b/ct/cryptpad.sh index 0da381f..9cb3738 100644 --- a/ct/cryptpad.sh +++ b/ct/cryptpad.sh @@ -35,15 +35,21 @@ function update_script() { msg_ok "Stopped $APP" msg_info "Updating $APP to ${RELEASE}" + cp /opt/cryptpad/config/config.js /opt/config.js + wget -q "https://github.com/cryptpad/cryptpad/archive/refs/tags/${RELEASE}.tar.gz" -O $temp_file + tar zxf $temp_file + cp -rf cryptpad-$RELEASE/* /opt/cryptpad cd /opt/cryptpad - $STD git fetch origin --tags - $STD git checkout $RELEASE $STD npm ci $STD npm run install:components $STD npm run build echo "${RELEASE}" >/opt/${APP}_version.txt msg_ok "Updated $APP to ${RELEASE}" + msg_info "Cleaning Up" + rm -f $temp_file + msg_ok "Cleanup Completed" + msg_info "Starting $APP" systemctl start cryptpad msg_ok "Started $APP" diff --git a/install/cryptpad-install.sh b/install/cryptpad-install.sh index a619697..634b4f4 100644 --- a/install/cryptpad-install.sh +++ b/install/cryptpad-install.sh @@ -33,14 +33,15 @@ $STD apt-get update $STD apt-get install -y nodejs msg_ok "Setup Node.js" -read -p "Do you want to install OnlyOffice components? (Y/N): " onlyoffice +read -p "Install OnlyOffice components instead of CKEditor? (Y/N): " onlyoffice msg_info "Setup ${APPLICATION}" +temp_file=$(mktemp) RELEASE=$(curl -s https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') -cd /opt -$STD git clone https://github.com/cryptpad/cryptpad.git cryptpad -cd cryptpad -$STD git checkout $RELEASE +wget -q "https://github.com/cryptpad/cryptpad/archive/refs/tags/${RELEASE}.tar.gz" -O $temp_file +tar zxf $temp_file +mv cryptpad-$RELEASE /opt/cryptpad +cd /opt/cryptpad $STD npm ci $STD npm run install:components $STD npm run build @@ -81,6 +82,7 @@ motd_ssh customize msg_info "Cleaning up" +rm -f $temp_file $STD apt-get -y autoremove $STD apt-get -y autoclean msg_ok "Cleaned"