From 28063e3f467e1d52a8afa6f8d4e0d59d9ef60471 Mon Sep 17 00:00:00 2001 From: matu6968 Date: Thu, 21 Nov 2024 02:15:16 +0100 Subject: [PATCH] remove outdated client demo --- client-demo/demo.js | 105 -------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 client-demo/demo.js diff --git a/client-demo/demo.js b/client-demo/demo.js deleted file mode 100644 index cc17028..0000000 --- a/client-demo/demo.js +++ /dev/null @@ -1,105 +0,0 @@ -// WebDesk App Market server demo - -const apiUrl = "http://localhost:8080"; -const bearerToken = "your-secret-bearer-token"; - -// Utility function for making authorized requests -async function apiRequest(endpoint, method = "GET", data = null, isFileUpload = false) { - const headers = { "Authorization": `Bearer ${bearerToken}` }; - - let body; - if (data) { - if (isFileUpload) { - body = new FormData(); - for (const key in data) { - body.append(key, data[key]); - } - } else { - headers["Content-Type"] = "application/json"; - body = JSON.stringify(data); - } - } - - const response = await fetch(`${apiUrl}${endpoint}`, { - method, - headers, - body - }); - - if (!response.ok) { - throw new Error(`Error: ${response.statusText}`); - } - return response.json(); -} - -// List all apps -async function listApps() { - try { - const apps = await apiRequest("/apps", "GET"); - console.log("List of Apps:", apps); - } catch (error) { - console.error("Failed to list apps:", error); - } -} - -// Upload a new app -async function uploadApp(appData, file, customPath = "") { - try { - const data = { metadata: JSON.stringify(appData) }; - data.file = file; - if (customPath) data.customPath = customPath; - - const newApp = await apiRequest("/apps", "POST", data, true); - console.log("Uploaded App:", newApp); - } catch (error) { - console.error("Failed to upload app:", error); - } -} - -// Edit an existing app -async function editApp(appID, updates, newFile = null, customPath = "") { - try { - const data = { id: appID, ...updates }; - if (newFile) data.file = newFile; - if (customPath) data.customPath = customPath; - - const updatedApp = await apiRequest("/editapp", "POST", data, true); - console.log("Updated App:", updatedApp); - } catch (error) { - console.error("Failed to edit app:", error); - } -} - -// Delete an app by ID -async function deleteApp(appID) { - try { - const params = new URLSearchParams({ id: appID }); - const result = await apiRequest(`/delete?${params}`, "POST"); - console.log("App deleted:", result); - } catch (error) { - console.error("Failed to delete app:", error); - } -} - -// Example Usage -// List all apps -listApps(); - -// Upload a new app -const newAppData = { - developer: "John Doe", - name: "Camera App", - version: "1.0", - info: "A great camera app", - id: "1234" -}; -const appFile = new File(["dummy content"], "camera_app.zip", { type: "application/zip" }); -uploadApp(newAppData, appFile, "custom_camera_path"); - -// Edit an existing app -const appUpdates = { name: "Updated Camera App", info: "An updated camera app description" }; -const newAppFile = new File(["new content"], "updated_camera_app.zip", { type: "application/zip" }); -editApp("1234", appUpdates, newAppFile, "updated_camera_path"); - -// Delete an app by ID -deleteApp("1234");