Create delete plugin path

nightly
Andrew 4 years ago
parent 99212164a2
commit 88a4422e29
  1. 105
      stashr/api.py
  2. 51
      stashr/templates/settings_page_plugins.html

@ -2064,6 +2064,7 @@ def api_get_plugins():
list_item['plugin_url'] = item.plugin_url
list_item['plugin_license'] = item.plugin_license
list_item['plugin_state'] = item.plugin_state
list_item['plugin_package_name'] = item.plugin_package_name
# list_item[]
data.append(list_item)
@ -2311,6 +2312,110 @@ def api_post_upload_plugin():
return jsonify(create_json_return('200'))
@api.route('/plugins/enable/<plugin>', methods=['POST'])
def api_post_plugin_enable(plugin):
"""To Update Later
This is using docstrings for specifications.
---
tags:
- plugins
"""
user = current_user
if not user.is_authenticated:
if not request.json:
return jsonify(create_json_return('400'))
if "api_key" not in request.json:
return jsonify(create_json_return('400'))
if request.json['api_key'] == "":
return jsonify(create_json_return('100'))
user = database.session \
.query(database.Users) \
.filter(database.Users.api_key == request.json['api_key']) \
.first()
if user is None:
return jsonify(create_json_return('100'))
if user.role != 'admin':
return jsonify(create_json_return('401'))
utils.enable_plugin(plugin)
return jsonify(create_json_return('200'))
@api.route('/plugins/disable/<plugin>', methods=['POST'])
def api_post_plugin_disable(plugin):
"""To Update Later
This is using docstrings for specifications.
---
tags:
- plugins
"""
user = current_user
if not user.is_authenticated:
if not request.json:
return jsonify(create_json_return('400'))
if "api_key" not in request.json:
return jsonify(create_json_return('400'))
if request.json['api_key'] == "":
return jsonify(create_json_return('100'))
user = database.session \
.query(database.Users) \
.filter(database.Users.api_key == request.json['api_key']) \
.first()
if user is None:
return jsonify(create_json_return('100'))
if user.role != 'admin':
return jsonify(create_json_return('401'))
utils.disable_plugin(plugin)
return jsonify(create_json_return('200'))
@api.route('/plugins/remove/<plugin>', methods=['POST'])
def api_post_plugin_remove(plugin):
"""To Update Later
This is using docstrings for specifications.
---
tags:
- plugins
"""
user = current_user
if not user.is_authenticated:
if not request.json:
return jsonify(create_json_return('400'))
if "api_key" not in request.json:
return jsonify(create_json_return('400'))
if request.json['api_key'] == "":
return jsonify(create_json_return('100'))
user = database.session \
.query(database.Users) \
.filter(database.Users.api_key == request.json['api_key']) \
.first()
if user is None:
return jsonify(create_json_return('100'))
if user.role != 'admin':
return jsonify(create_json_return('401'))
utils.uninstall_plugin(plugin)
return jsonify(create_json_return('200'))
""" --- RESTART SERVER --- """
@api.route('/restart', methods=['POST'])

@ -77,7 +77,8 @@ Vue.component('plugin',{
<td>[[ plugin.plugin_url ]]</td>
<td>[[ plugin.plugin_license ]]</td>
<td>[[ plugin.plugin_state ]]</td>
<td><button type="button" class="btn" v-bind:class="pluginClass">[[ pluginAction ]]</button> </td>
<td><button type="button" class="btn" v-bind:class="pluginClass" @click="togglePlugin">[[ pluginAction ]]</button> </td>
<td><button typoe="button" class="btn btn-danger" @click="deletePlugin">Delete</td>
</tr>
`,
computed: {
@ -96,6 +97,37 @@ Vue.component('plugin',{
return text;
}
},
methods: {
togglePlugin() {
if(this.plugin.plugin_state == 'disabled') {
console.log('Enabling')
axios.post('{{ url_for('api.api_post_plugin_enable', plugin='PLUGINID') }}'.replace('PLUGINID', this.plugin.plugin_name))
.then(res=>{
if(res.data.status_code == 200) {
this.plugin.plugin_state='enabled'
stashrToast('Plugin Enabled', 'success')
}
})
} else {
console.log('Disabling')
axios.post('{{ url_for('api.api_post_plugin_disable', plugin='PLUGINID') }}'.replace('PLUGINID', this.plugin.plugin_name))
.then(res=>{
if(res.data.status_code == 200) {
this.plugin.plugin_state='disabled'
stashrToast('Plugin Disabled', 'success')
}
})
}
},
deletePlugin() {
axios.post('{{ url_for('api.api_post_plugin_remove', plugin='PLUGINID') }}'.replace('PLUGINID', this.plugin.plugin_package_name))
.then(res=>{
if(res.data.status_code == 200) {
stashrToast('Plugin Deleted', 'success')
}
})
},
},
delimiters: ["[[","]]"]
})
@ -117,14 +149,15 @@ Vue.component('plugins',{
<table class="table">
<thead>
<tr>
<th scop="col">Name</th>
<th scop="col">Description</th>
<th scop="col">Version</th>
<th scop="col">Author</th>
<th scop="col">URL</th>
<th scop="col">License</th>
<th scop="col">State</th>
<th scop="col">Action</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Version</th>
<th scope="col">Author</th>
<th scope="col">URL</th>
<th scope="col">License</th>
<th scope="col">State</th>
<th scope="col">Action</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody class="tablebody">

Loading…
Cancel
Save