mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
尝试添加YAML配置文件编辑功能
This commit is contained in:
@@ -33,6 +33,7 @@ urlpatterns = [
|
||||
path(r'show_log_list', views.show_log_list, name='show_log_list'),
|
||||
path(r'get_log_content', views.get_log_content, name='get_log_content'),
|
||||
path(r'download_log_file', views.download_log_file, name='download_log_file'),
|
||||
path(r'get_config_setting', views.get_config_setting, name='get_config_setting'),
|
||||
path(r'remove_log_api', views.remove_log_api, name='remove_log_api'),
|
||||
path(r'get_site_list', views.get_site_list, name='get_site_list'),
|
||||
path(r'edit_my_site', views.edit_my_site, name='edit_my_site'),
|
||||
|
||||
@@ -10,6 +10,7 @@ import docker
|
||||
import git
|
||||
import qbittorrentapi
|
||||
import transmission_rpc
|
||||
import yaml
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import JsonResponse, FileResponse
|
||||
from django.shortcuts import render
|
||||
@@ -1093,3 +1094,25 @@ def get_site_torrents(request):
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
msg='种子抓取操作成功!'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def get_config_setting(request):
|
||||
file_path = os.path.join(BASE_DIR, 'db/ptools.yaml')
|
||||
if not os.path.exists(file_path):
|
||||
with open(file_path, 'r') as f:
|
||||
f.write()
|
||||
try:
|
||||
with open(file_path, 'r') as f:
|
||||
data = yaml.load(f, Loader=yaml.FullLoader)
|
||||
print(data)
|
||||
|
||||
with open(file_path, 'r') as f:
|
||||
logs = f.readlines()
|
||||
logger.info(f'日志行数:{len(logs)}')
|
||||
return render(request, 'auto_pt/settings.html', context={
|
||||
'config': logs
|
||||
})
|
||||
except Exception as e:
|
||||
return render(request, 'auto_pt/settings.html', context={
|
||||
'config': f'{e}'
|
||||
})
|
||||
|
||||
@@ -284,5 +284,14 @@ SIMPLEUI_CONFIG = {
|
||||
'icon': 'fab fa-blogger',
|
||||
'url': '/tasks/show_log_list'
|
||||
}, ]
|
||||
}, {
|
||||
'app': 'update',
|
||||
'name': '系统配置',
|
||||
'icon': 'fas fa-cog',
|
||||
'models': [{
|
||||
'name': '修改配置',
|
||||
'icon': 'fas fa-edit',
|
||||
'url': '/tasks/get_config_setting'
|
||||
}, ]
|
||||
}]
|
||||
}
|
||||
|
||||
41
templates/auto_pt/settings.html
Normal file
41
templates/auto_pt/settings.html
Normal file
@@ -0,0 +1,41 @@
|
||||
{% load static %}
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
{% include 'admin/includes/css-part.html' %}
|
||||
<style>
|
||||
#codeEditor {
|
||||
width: 500px;
|
||||
height: 400px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="settings">
|
||||
<code v-html="config" id="codeEditor" class="ace_editor" type="textarea"></code>
|
||||
</div>
|
||||
{% include 'admin/includes/js-part.html' %}
|
||||
<script src="{% static 'admin/simpleui-x/js/axios.min.js' %}"></script>
|
||||
<script>
|
||||
const vm = new Vue({
|
||||
el: '#settings',
|
||||
data() {
|
||||
return {
|
||||
config: "{{ config }}",
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
methods: {}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user