update store for new format, awaiting cors to test

This commit is contained in:
AAGaming
2022-06-29 12:17:25 -04:00
parent 18d444e8fc
commit 79e8af8be6
2 changed files with 21 additions and 18 deletions
+8 -9
View File
@@ -10,7 +10,7 @@ import {
} from 'decky-frontend-lib'; } from 'decky-frontend-lib';
import { FC, useRef, useState } from 'react'; import { FC, useRef, useState } from 'react';
import { StorePlugin, requestPluginInstall } from './Store'; import { StorePlugin, StorePluginVersion, requestPluginInstall } from './Store';
interface PluginCardProps { interface PluginCardProps {
plugin: StorePlugin; plugin: StorePlugin;
@@ -62,10 +62,9 @@ const PluginCard: FC<PluginCardProps> = ({ plugin }) => {
<a <a
style={{ fontSize: '18pt', padding: '10px' }} style={{ fontSize: '18pt', padding: '10px' }}
className={classNames(staticClasses.Text)} className={classNames(staticClasses.Text)}
onClick={() => Router.NavigateToExternalWeb('https://github.com/' + plugin.artifact)} // onClick={() => Router.NavigateToExternalWeb('https://github.com/' + plugin.artifact)}
> >
<span style={{ color: 'grey' }}>{plugin.artifact.split('/')[0]}/</span> {plugin.name}
{plugin.artifact.split('/')[1]}
</a> </a>
</div> </div>
<div <div
@@ -80,7 +79,7 @@ const PluginCard: FC<PluginCardProps> = ({ plugin }) => {
width: 'auto', width: 'auto',
height: '160px', height: '160px',
}} }}
src={`https://cdn.tzatzikiweeb.moe/file/steam-deck-homebrew/artifact_images/${plugin.artifact.replace( src={`https://cdn.tzatzikiweeb.moe/file/steam-deck-homebrew/artifact_images/${plugin.name.replace(
'/', '/',
'_', '_',
)}.png`} )}.png`}
@@ -133,7 +132,7 @@ const PluginCard: FC<PluginCardProps> = ({ plugin }) => {
> >
<DialogButton <DialogButton
ref={buttonRef} ref={buttonRef}
onClick={() => requestPluginInstall(plugin, Object.keys(plugin.versions)[selectedOption])} onClick={() => requestPluginInstall(plugin, plugin.versions[selectedOption])}
> >
Install Install
</DialogButton> </DialogButton>
@@ -145,9 +144,9 @@ const PluginCard: FC<PluginCardProps> = ({ plugin }) => {
> >
<Dropdown <Dropdown
rgOptions={ rgOptions={
Object.keys(plugin.versions).map((v, k) => ({ plugin.versions.map((version: StorePluginVersion, index) => ({
data: k, data: index,
label: v, label: version.name,
})) as SingleDropdownOption[] })) as SingleDropdownOption[]
} }
strDefaultLabel={'Select a version'} strDefaultLabel={'Select a version'}
+13 -9
View File
@@ -3,11 +3,15 @@ import { FC, useEffect, useState } from 'react';
import PluginCard from './PluginCard'; import PluginCard from './PluginCard';
export interface StorePluginVersion {
name: string;
hash: string;
}
export interface StorePlugin { export interface StorePlugin {
artifact: string; id: number;
versions: { name: string;
[version: string]: string; versions: StorePluginVersion[];
};
author: string; author: string;
description: string; description: string;
tags: string[]; tags: string[];
@@ -22,11 +26,11 @@ export async function installFromURL(url: string) {
}); });
} }
export async function requestPluginInstall(plugin: StorePlugin, selectedVer: string) { export async function requestPluginInstall(plugin: StorePlugin, selectedVer: StorePluginVersion) {
const formData = new FormData(); const formData = new FormData();
formData.append('artifact', `https://github.com/${plugin.artifact}/archive/refs/tags/${selectedVer}.zip`); formData.append('artifact', `https://cdn.tzatzikiweeb.moe/file/steam-deck-homebrew/versions/${selectedVer.hash}.zip`);
formData.append('version', selectedVer); formData.append('version', selectedVer.name);
formData.append('hash', plugin.versions[selectedVer]); formData.append('hash', selectedVer.hash);
await fetch('http://localhost:1337/browser/install_plugin', { await fetch('http://localhost:1337/browser/install_plugin', {
method: 'POST', method: 'POST',
body: formData, body: formData,
@@ -38,7 +42,7 @@ const StorePage: FC<{}> = () => {
useEffect(() => { useEffect(() => {
(async () => { (async () => {
const res = await fetch('https://beta.deckbrew.xyz/get_plugins', { method: 'GET' }).then((r) => r.json()); const res = await fetch('https://beta.deckbrew.xyz/plugins', { method: 'GET' }).then((r) => r.json());
console.log(res); console.log(res);
setData(res); setData(res);
})(); })();