From d72f364a8d032ca53c35c22c8dbe01ba354629df Mon Sep 17 00:00:00 2001
From: AAGaming <aa@mail.catvibers.me>
Date: Thu, 30 Jun 2022 16:04:29 -0400
Subject: backwards-compatible plugin store, legacy plugin library

---
 frontend/src/components/store/Store.tsx | 41 +++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

(limited to 'frontend/src/components/store/Store.tsx')

diff --git a/frontend/src/components/store/Store.tsx b/frontend/src/components/store/Store.tsx
index e317096f..f28434dd 100644
--- a/frontend/src/components/store/Store.tsx
+++ b/frontend/src/components/store/Store.tsx
@@ -17,6 +17,16 @@ export interface StorePlugin {
   tags: string[];
 }
 
+export interface LegacyStorePlugin {
+  artifact: string;
+  versions: {
+    [version: string]: string;
+  };
+  author: string;
+  description: string;
+  tags: string[];
+}
+
 export async function installFromURL(url: string) {
   const formData = new FormData();
   const splitURL = url.split('/');
@@ -28,6 +38,18 @@ export async function installFromURL(url: string) {
   });
 }
 
+export async function requestLegacyPluginInstall(plugin: LegacyStorePlugin, selectedVer: string) {
+  const formData = new FormData();
+  formData.append('name', plugin.artifact);
+  formData.append('artifact', `https://github.com/${plugin.artifact}/archive/refs/tags/${selectedVer}.zip`);
+  formData.append('version', selectedVer);
+  formData.append('hash', plugin.versions[selectedVer]);
+  await fetch('http://localhost:1337/browser/install_plugin', {
+    method: 'POST',
+    body: formData,
+  });
+}
+
 export async function requestPluginInstall(plugin: StorePlugin, selectedVer: StorePluginVersion) {
   const formData = new FormData();
   formData.append('name', plugin.name);
@@ -42,6 +64,7 @@ export async function requestPluginInstall(plugin: StorePlugin, selectedVer: Sto
 
 const StorePage: FC<{}> = () => {
   const [data, setData] = useState<StorePlugin[] | null>(null);
+  const [legacyData, setLegacyData] = useState<LegacyStorePlugin[] | null>(null);
 
   useEffect(() => {
     (async () => {
@@ -49,6 +72,11 @@ const StorePage: FC<{}> = () => {
       console.log(res);
       setData(res);
     })();
+    (async () => {
+      const res = await fetch('https://plugins.deckbrew.xyz/get_plugins', { method: 'GET' }).then((r) => r.json());
+      console.log(res);
+      setLegacyData(res);
+    })();
   }, []);
 
   return (
@@ -67,12 +95,21 @@ const StorePage: FC<{}> = () => {
           height: '100%',
         }}
       >
-        {data === null ? (
+        {!data ? (
           <div style={{ height: '100%' }}>
             <SteamSpinner />
           </div>
         ) : (
-          data.map((plugin: StorePlugin) => <PluginCard plugin={plugin} />)
+          <div>
+            {data.map((plugin: StorePlugin) => (
+              <PluginCard plugin={plugin} />
+            ))}
+            {!legacyData ? (
+              <SteamSpinner />
+            ) : (
+              legacyData.map((plugin: LegacyStorePlugin) => <PluginCard plugin={plugin} />)
+            )}
+          </div>
         )}
       </div>
     </div>
-- 
cgit v1.2.3

