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',
|
install_meta: 'post',
|
||||||
async install({ packageName }) {
|
async install({ packageName }) {
|
||||||
if (!hasPermission(`plugins/install`)) return;
|
if (!hasPermission(`plugins/install`)) return;
|
||||||
@ -114,6 +118,8 @@ module.exports = {
|
|||||||
await downloadPackage(packageName, dir);
|
await downloadPackage(packageName, dir);
|
||||||
}
|
}
|
||||||
socket.emitChanged(`installed-plugins-changed`);
|
socket.emitChanged(`installed-plugins-changed`);
|
||||||
|
this.removedPlugins = this.removedPlugins.filter((x) => x != packageName);
|
||||||
|
await this.saveRemovePlugins();
|
||||||
},
|
},
|
||||||
|
|
||||||
uninstall_meta: 'post',
|
uninstall_meta: 'post',
|
||||||
@ -123,7 +129,16 @@ module.exports = {
|
|||||||
await fs.rmdir(dir, { recursive: true });
|
await fs.rmdir(dir, { recursive: true });
|
||||||
socket.emitChanged(`installed-plugins-changed`);
|
socket.emitChanged(`installed-plugins-changed`);
|
||||||
this.removedPlugins.push(packageName);
|
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',
|
command_meta: 'post',
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"ace-builds": "^1.4.8",
|
"ace-builds": "^1.4.8",
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
"chart.js": "^2.9.4",
|
"chart.js": "^2.9.4",
|
||||||
|
"compare-versions": "^3.6.0",
|
||||||
"cross-env": "^6.0.3",
|
"cross-env": "^6.0.3",
|
||||||
"dbgate-datalib": "^1.0.0",
|
"dbgate-datalib": "^1.0.0",
|
||||||
"dbgate-sqltree": "^1.0.0",
|
"dbgate-sqltree": "^1.0.0",
|
||||||
|
@ -5,6 +5,7 @@ import Markdown from 'markdown-to-jsx';
|
|||||||
import useTheme from '../theme/useTheme';
|
import useTheme from '../theme/useTheme';
|
||||||
import useFetch from '../utility/useFetch';
|
import useFetch from '../utility/useFetch';
|
||||||
import LoadingInfo from '../widgets/LoadingInfo';
|
import LoadingInfo from '../widgets/LoadingInfo';
|
||||||
|
import compareVersions from 'compare-versions';
|
||||||
import { extractPluginIcon, extractPluginAuthor } from '../plugins/manifestExtractors';
|
import { extractPluginIcon, extractPluginAuthor } from '../plugins/manifestExtractors';
|
||||||
import FormStyledButton from '../widgets/FormStyledButton';
|
import FormStyledButton from '../widgets/FormStyledButton';
|
||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
@ -72,13 +73,18 @@ function PluginTabCore({ packageName }) {
|
|||||||
const handleUninstall = async () => {
|
const handleUninstall = async () => {
|
||||||
axios.post('plugins/uninstall', { packageName });
|
axios.post('plugins/uninstall', { packageName });
|
||||||
};
|
};
|
||||||
|
const handleUpgrade = async () => {
|
||||||
|
axios.post('plugins/upgrade', { packageName });
|
||||||
|
};
|
||||||
|
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
return <LoadingInfo message="Loading extension detail" />;
|
return <LoadingInfo message="Loading extension detail" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const installedFound = installed.find((x) => x.name == packageName);
|
||||||
|
const onlineFound = manifest;
|
||||||
|
|
||||||
if (manifest == null) {
|
if (manifest == null) {
|
||||||
const installedFound = installed.find((x) => x.name == packageName);
|
|
||||||
if (installedFound) {
|
if (installedFound) {
|
||||||
manifest = installedFound;
|
manifest = installedFound;
|
||||||
readme = installedFound.readme;
|
readme = installedFound.readme;
|
||||||
@ -97,15 +103,21 @@ function PluginTabCore({ packageName }) {
|
|||||||
<HeaderLine>
|
<HeaderLine>
|
||||||
<Author>{extractPluginAuthor(manifest)}</Author>
|
<Author>{extractPluginAuthor(manifest)}</Author>
|
||||||
<Delimiter />
|
<Delimiter />
|
||||||
<Version>{manifest.version && manifest.version}</Version>
|
<Version>{installedFound ? installedFound.version : manifest.version}</Version>
|
||||||
</HeaderLine>
|
</HeaderLine>
|
||||||
<HeaderLine>
|
<HeaderLine>
|
||||||
{hasPermission('plugins/install') && !installed.find((x) => x.name == packageName) && (
|
{hasPermission('plugins/install') && !installedFound && (
|
||||||
<FormStyledButton type="button" value="Install" onClick={handleInstall} />
|
<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} />
|
<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>
|
</HeaderLine>
|
||||||
</HeaderBody>
|
</HeaderBody>
|
||||||
</Header>
|
</Header>
|
||||||
@ -122,3 +134,5 @@ export default function PluginTab({ packageName }) {
|
|||||||
</WhitePage>
|
</WhitePage>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PluginTab.matchingProps = ['packageName'];
|
||||||
|
@ -3262,6 +3262,11 @@ commondir@^1.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
|
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
|
||||||
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
|
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:
|
component-bind@1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
|
resolved "https://registry.yarnpkg.com/component-bind/-/component-bind-1.0.0.tgz#00c608ab7dcd93897c0009651b1d3a8e1e73bbd1"
|
||||||
|
Loading…
Reference in New Issue
Block a user