mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 11:26:00 +00:00
remove web
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import useTheme from '../theme/useTheme';
|
||||
import { useSetOpenedTabs } from '../utility/globalState';
|
||||
import { extractPluginIcon, extractPluginAuthor } from '../plugins/manifestExtractors';
|
||||
import useOpenNewTab from '../utility/useOpenNewTab';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
margin: 1px 3px 10px 5px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
&:hover {
|
||||
background-color: ${props => props.theme.left_background_blue[1]};
|
||||
}
|
||||
`;
|
||||
|
||||
const Texts = styled.div`
|
||||
margin-left: 10px;
|
||||
`;
|
||||
|
||||
const Name = styled.div`
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
const Line = styled.div`
|
||||
display: flex;
|
||||
`;
|
||||
|
||||
const Icon = styled.img`
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
`;
|
||||
|
||||
const Description = styled.div`
|
||||
font-style: italic;
|
||||
`;
|
||||
|
||||
const Author = styled.div`
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
const Version = styled.div`
|
||||
margin-left: 5px;
|
||||
`;
|
||||
|
||||
function openPlugin(openNewTab, packageManifest) {
|
||||
openNewTab({
|
||||
title: packageManifest.name,
|
||||
icon: 'icon plugin',
|
||||
tabComponent: 'PluginTab',
|
||||
props: {
|
||||
packageName: packageManifest.name,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function PluginsListItem({ packageManifest }) {
|
||||
const openNewTab = useOpenNewTab();
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<Wrapper onClick={() => openPlugin(openNewTab, packageManifest)} theme={theme}>
|
||||
<Icon src={extractPluginIcon(packageManifest)} />
|
||||
<Texts>
|
||||
<Line>
|
||||
<Name>{packageManifest.name}</Name>
|
||||
<Version>{packageManifest.version}</Version>
|
||||
</Line>
|
||||
<Line>
|
||||
<Description>{packageManifest.description}</Description>
|
||||
</Line>
|
||||
<Line>
|
||||
<Author>{extractPluginAuthor(packageManifest)}</Author>
|
||||
</Line>
|
||||
</Texts>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default function PluginsList({ plugins }) {
|
||||
return (
|
||||
<>
|
||||
{plugins.map(packageManifest => (
|
||||
<PluginsListItem packageManifest={packageManifest} key={packageManifest.name} />
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
import axios from '../utility/axios';
|
||||
import { useInstalledPlugins } from '../utility/metadataLoaders';
|
||||
|
||||
const PluginsContext = React.createContext(null);
|
||||
|
||||
const dbgateEnv = {
|
||||
axios,
|
||||
};
|
||||
|
||||
export default function PluginsProvider({ children }) {
|
||||
const installedPlugins = useInstalledPlugins();
|
||||
const [plugins, setPlugins] = React.useState({});
|
||||
const handleLoadPlugins = async () => {
|
||||
const newPlugins = {};
|
||||
for (const installed of installedPlugins) {
|
||||
if (!_.keys(plugins).includes(installed.name)) {
|
||||
console.log('Loading module', installed.name);
|
||||
const resp = await axios.request({
|
||||
method: 'get',
|
||||
url: 'plugins/script',
|
||||
params: {
|
||||
packageName: installed.name,
|
||||
},
|
||||
});
|
||||
const module = eval(`${resp.data}; plugin`);
|
||||
console.log('Loaded plugin', module);
|
||||
const moduleContent = module.__esModule ? module.default : module;
|
||||
if (moduleContent.initialize) moduleContent.initialize(dbgateEnv);
|
||||
newPlugins[installed.name] = moduleContent;
|
||||
}
|
||||
}
|
||||
setPlugins(x =>
|
||||
_.pick(
|
||||
{ ...x, ...newPlugins },
|
||||
installedPlugins.map(y => y.name)
|
||||
)
|
||||
);
|
||||
};
|
||||
React.useEffect(() => {
|
||||
handleLoadPlugins();
|
||||
}, [installedPlugins]);
|
||||
return <PluginsContext.Provider value={plugins}>{children}</PluginsContext.Provider>;
|
||||
}
|
||||
|
||||
export function usePlugins() {
|
||||
const installed = useInstalledPlugins();
|
||||
const loaded = React.useContext(PluginsContext);
|
||||
|
||||
return React.useMemo(
|
||||
() =>
|
||||
installed
|
||||
.map(manifest => ({
|
||||
packageName: manifest.name,
|
||||
manifest,
|
||||
content: loaded[manifest.name],
|
||||
}))
|
||||
.filter(x => x.content),
|
||||
[installed, loaded]
|
||||
);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export function extractPluginIcon(packageManifest) {
|
||||
const { links } = packageManifest || {};
|
||||
const { repository } = links || {};
|
||||
const homepage = (links && links.homepage) || packageManifest.homepage;
|
||||
const tested = repository || homepage || packageManifest.homepage;
|
||||
|
||||
if (tested) {
|
||||
const match = tested.match(/https:\/\/github.com\/([^/]*)\/([^/]*)/);
|
||||
if (match) {
|
||||
return `https://raw.githubusercontent.com/${match[1]}/${match[2]}/master/icon.svg`;
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line no-undef
|
||||
return `${process.env.PUBLIC_URL}/unknown.svg`;
|
||||
}
|
||||
|
||||
export function extractPluginAuthor(packageManifest) {
|
||||
return _.isPlainObject(packageManifest.author) ? packageManifest.author.name : packageManifest.author;
|
||||
}
|
||||
Reference in New Issue
Block a user