mirror of
https://github.com/hkalexling/Mango.git
synced 2026-04-04 00:00:51 -04:00
WIP
This commit is contained in:
42
public/js/plugin-download-2.js
Normal file
42
public/js/plugin-download-2.js
Normal file
@@ -0,0 +1,42 @@
|
||||
const component = () => {
|
||||
return {
|
||||
plugins: [],
|
||||
info: undefined,
|
||||
pid: undefined,
|
||||
init() {
|
||||
fetch(`${base_url}api/admin/plugin`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
alert('danger', `Failed to list the available plugins. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
this.plugins = data.plugins;
|
||||
|
||||
const pid = localStorage.getItem('plugin');
|
||||
if (pid && this.plugins.map(p => p.id).includes(pid))
|
||||
return this.loadPlugin(pid);
|
||||
|
||||
if (this.plugins.length > 0)
|
||||
this.loadPlugin(this.plugins[0].id);
|
||||
});
|
||||
},
|
||||
loadPlugin(pid) {
|
||||
fetch(`${base_url}api/admin/plugin/info?${new URLSearchParams({
|
||||
plugin: pid
|
||||
})}`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
alert('danger', `Failed to get plugin metadata. Error: ${data.error}`);
|
||||
return;
|
||||
}
|
||||
this.info = data.info;
|
||||
this.pid = pid;
|
||||
});
|
||||
},
|
||||
pluginChanged() {
|
||||
this.loadPlugin(this.pid);
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user