mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
upgrade plugin from plugin tab
This commit is contained in:
parent
72619a9902
commit
011ca0a5c4
@ -106,6 +106,10 @@ module.exports = {
|
||||
// );
|
||||
},
|
||||
|
||||
async saveRemovePlugins() {
|
||||
await fs.writeFile(path.join(datadir(), 'removed-plugins'), this.removedPlugins.join('\n'));
|
||||
},
|
||||
|
||||
install_meta: 'post',
|
||||
async install({ packageName }) {
|
||||
if (!hasPermission(`plugins/install`)) return;
|
||||
@ -114,6 +118,8 @@ module.exports = {
|
||||
await downloadPackage(packageName, dir);
|
||||
}
|
||||
socket.emitChanged(`installed-plugins-changed`);
|
||||
this.removedPlugins = this.removedPlugins.filter((x) => x != packageName);
|
||||
await this.saveRemovePlugins();
|
||||
},
|
||||
|
||||
uninstall_meta: 'post',
|
||||
@ -123,7 +129,16 @@ module.exports = {
|
||||
await fs.rmdir(dir, { recursive: true });
|
||||
socket.emitChanged(`installed-plugins-changed`);
|
||||
this.removedPlugins.push(packageName);
|
||||
await fs.writeFile(path.join(datadir(), 'removed-plugins'), this.removedPlugins.join('\n'));
|
||||
await this.saveRemovePlugins();
|
||||
},
|
||||
|
||||
upgrade_meta: 'post',
|
||||
async upgrade({ packageName }) {
|
||||
if (!hasPermission(`plugins/install`)) return;
|
||||
const dir = path.join(pluginsdir(), packageName);
|
||||
await fs.rmdir(dir, { recursive: true });
|
||||
await downloadPackage(packageName, dir);
|
||||
socket.emitChanged(`installed-plugins-changed`);
|
||||
},
|
||||
|
||||
command_meta: 'post',
|
||||
|
@ -11,6 +11,7 @@
|
||||
"ace-builds": "^1.4.8",
|
||||
"axios": "^0.19.0",
|
||||
"chart.js": "^2.9.4",
|
||||
"compare-versions": "^3.6.0",
|
||||
"cross-env": "^6.0.3",
|
||||
"dbgate-datalib": "^1.0.0",
|
||||
"dbgate-sqltree": "^1.0.0",
|
||||
|
@ -5,6 +5,7 @@ import Markdown from 'markdown-to-jsx';
|
||||
import useTheme from '../theme/useTheme';
|
||||
import useFetch from '../utility/useFetch';
|
||||
import LoadingInfo from '../widgets/LoadingInfo';
|
||||
import compareVersions from 'compare-versions';
|
||||
import { extractPluginIcon, extractPluginAuthor } from '../plugins/manifestExtractors';
|
||||
import FormStyledButton from '../widgets/FormStyledButton';
|
||||
import axios from '../utility/axios';
|
||||
@ -72,13 +73,18 @@ function PluginTabCore({ packageName }) {
|
||||
const handleUninstall = async () => {
|
||||
axios.post('plugins/uninstall', { packageName });
|
||||
};
|
||||
const handleUpgrade = async () => {
|
||||
axios.post('plugins/upgrade', { packageName });
|
||||
};
|
||||
|
||||
if (info == null) {
|
||||
return <LoadingInfo message="Loading extension detail" />;
|
||||
}
|
||||
|
||||
const installedFound = installed.find((x) => x.name == packageName);
|
||||
const onlineFound = manifest;
|
||||
|
||||
if (manifest == null) {
|
||||
const installedFound = installed.find((x) => x.name == packageName);
|
||||
if (installedFound) {
|
||||
manifest = installedFound;
|
||||
readme = installedFound.readme;
|
||||
@ -97,15 +103,21 @@ function PluginTabCore({ packageName }) {
|
||||
<HeaderLine>
|
||||
<Author>{extractPluginAuthor(manifest)}</Author>
|
||||
<Delimiter />
|
||||
<Version>{manifest.version && manifest.version}</Version>
|
||||
<Version>{installedFound ? installedFound.version : manifest.version}</Version>
|
||||
</HeaderLine>
|
||||
<HeaderLine>
|
||||
{hasPermission('plugins/install') && !installed.find((x) => x.name == packageName) && (
|
||||
{hasPermission('plugins/install') && !installedFound && (
|
||||
<FormStyledButton type="button" value="Install" onClick={handleInstall} />
|
||||
)}
|
||||
{hasPermission('plugins/install') && !!installed.find((x) => x.name == packageName) && (
|
||||
{hasPermission('plugins/install') && !!installedFound && (
|
||||
<FormStyledButton type="button" value="Uninstall" onClick={handleUninstall} />
|
||||
)}
|
||||
{hasPermission('plugins/install') &&
|
||||
installedFound &&
|
||||
onlineFound &&
|
||||
compareVersions(onlineFound.version, installedFound.version) > 0 && (
|
||||
<FormStyledButton type="button" value="Upgrade" onClick={handleUpgrade} />
|
||||
)}
|
||||
</HeaderLine>
|
||||
</HeaderBody>
|
||||
</Header>
|
||||
@ -122,3 +134,5 @@ export default function PluginTab({ packageName }) {
|
||||
</WhitePage>
|
||||
);
|
||||
}
|
||||
|
||||
PluginTab.matchingProps = ['packageName'];
|
||||
|
@ -3262,6 +3262,11 @@ commondir@^1.0.1:
|
||||
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
|
||||
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
|
||||
|
||||
compare-versions@^3.6.0:
|
||||
version "3.6.0"
|
||||
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.6.0.tgz#1a5689913685e5a87637b8d3ffca75514ec41d62"
|
||||
integrity sha512-W6Af2Iw1z4CB7q4uU4hv646dW9GQuBM+YpC0UvUCWSD8w90SJjp+ujJuXaEMtAXBtSqGfMPuFOVn4/+FlaqfBA==
|
||||
|
||||
component-bind@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
|
||||
|
Loading…
Reference in New Issue
Block a user