更新用户驱动配置功能,添加更新用户驱动的API接口,优化前端JSON编辑器的交互逻辑,确保用户驱动信息的正确更新和错误处理。
This commit is contained in:
parent
18c44797b1
commit
1f86d12fad
BIN
database.db
BIN
database.db
Binary file not shown.
10
main.py
10
main.py
@ -116,7 +116,6 @@ def admin():
|
||||
db = get_db()
|
||||
providers = db.get_all_drive_providers()
|
||||
alluser_drives = db.get_all_user_drives()
|
||||
print(alluser_drives)
|
||||
return render_template('admin.html',providers=providers,alluser_drives=alluser_drives)
|
||||
|
||||
|
||||
@ -156,7 +155,6 @@ def drive_provider(metfunc):
|
||||
"""
|
||||
|
||||
body = request.get_json()
|
||||
print(data)
|
||||
status = db.add_drive_provider(body.get("provider_name","测试网盘"),body.get("config_vars"),body.get("remarks","测试网盘"))
|
||||
|
||||
if status:
|
||||
@ -177,6 +175,14 @@ def user_drive(metfunc):
|
||||
if status:
|
||||
data["status"] = True
|
||||
data["data"] = body
|
||||
elif metfunc == "update":
|
||||
body = request.get_json()
|
||||
print(body)
|
||||
print(body.get("id"),body.get("login_config"))
|
||||
status = db.update_user_drive(body.get("id"),json.loads(body.get("login_config")),body.get("remarks","测试网盘"))
|
||||
if status:
|
||||
data["status"] = True
|
||||
data["data"] = body
|
||||
return data
|
||||
|
||||
|
||||
|
@ -596,9 +596,10 @@
|
||||
|
||||
if (selectedtid) {
|
||||
let defaultJson = {};
|
||||
const user_drives = JSON.parse('{{ alluser_drives | tojson | safe }}'); // Use safe filter
|
||||
// 解析返回的JSON字符串为JavaScript对象
|
||||
const allUserDrivesStr = '{{ alluser_drives | tojson | safe }}';
|
||||
const user_drives = JSON.parse(allUserDrivesStr); // Use safe filter
|
||||
const selectedUdrive = user_drives.find(user_drive => user_drive.id == selectedtid);
|
||||
|
||||
if (selectedUdrive && selectedUdrive.login_config) {
|
||||
defaultJson = selectedUdrive.login_config;
|
||||
} else {
|
||||
@ -609,9 +610,60 @@
|
||||
};
|
||||
}
|
||||
editor.setValue(JSON.stringify(defaultJson, null, 2), -1);
|
||||
|
||||
// Store the selected ID in a data attribute for the save button to access
|
||||
document.querySelector('#editudriveModal #saveAccount').setAttribute('data-tid', selectedtid);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// 编辑用户驱动保存事件
|
||||
$('#editudriveModal #saveAccount').on('click', function() {
|
||||
const editModalEditorArea = document.querySelector('#editudriveModal .json-editor-area');
|
||||
const editorElement = editModalEditorArea.querySelector('.ace-editor');
|
||||
const editor = ace.edit(editorElement);
|
||||
const configJson = editor.getValue();
|
||||
const tid = this.getAttribute('data-tid');
|
||||
|
||||
try {
|
||||
// 验证JSON格式
|
||||
JSON.parse(configJson);
|
||||
|
||||
// 发送数据到服务器
|
||||
$.ajax({
|
||||
url: '/admin/user_drive/update',
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify({
|
||||
id: tid,
|
||||
login_config: configJson
|
||||
}),
|
||||
success: function(response) {
|
||||
console.log(response);
|
||||
if (response.status) {
|
||||
showMessage('配置更新成功', 'success');
|
||||
// 清空并关闭模态框
|
||||
editor.setValue(configJson, -1);
|
||||
$('#editudriveModal').modal('hide');
|
||||
// 如果需要,可以在这里刷新页面或表格数据
|
||||
// 局部刷新表格内容
|
||||
} else {
|
||||
showMessage('配置更新失败: ' + response.message, 'error');
|
||||
}
|
||||
},
|
||||
error: function(error) {
|
||||
console.error('更新配置出错:', error);
|
||||
showMessage('更新配置时发生错误,请查看控制台', 'error');
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
showMessage('无效的JSON格式: ' + e.message, 'error');
|
||||
const errorDisplay = editModalEditorArea.closest('.mb-3').querySelector('.json-error');
|
||||
errorDisplay.textContent = '无效的JSON格式: ' + e.message;
|
||||
errorDisplay.style.display = 'block';
|
||||
editorElement.classList.add('border-danger');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user