mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
升级 修改ptools.yaml为ptools.toml文件,添加网页编辑页面,解决缩进容易出错的问题
This commit is contained in:
@@ -33,7 +33,9 @@ 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'get_config_html', views.get_config_html, name='get_config_html'),
|
||||
path(r'get_config_api', views.get_config_api, name='get_config_api'),
|
||||
path(r'save_config_api', views.save_config_api, name='save_config_api'),
|
||||
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'),
|
||||
|
||||
@@ -9,10 +9,11 @@ from datetime import datetime, timedelta
|
||||
import docker
|
||||
import git
|
||||
import qbittorrentapi
|
||||
import toml
|
||||
import transmission_rpc
|
||||
import yaml
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import JsonResponse, FileResponse
|
||||
from django.http import JsonResponse, FileResponse, HttpResponse, Http404
|
||||
from django.shortcuts import render
|
||||
|
||||
from pt_site.UtilityTool import MessageTemplate, FileSizeConvert
|
||||
@@ -1096,23 +1097,49 @@ def get_site_torrents(request):
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def get_config_setting(request):
|
||||
file_path = os.path.join(BASE_DIR, 'db/ptools.yaml')
|
||||
def get_config_api(request):
|
||||
file_path = os.path.join(BASE_DIR, 'db/ptools.toml')
|
||||
yaml_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()
|
||||
data = ''
|
||||
if os.path.exists(yaml_file_path):
|
||||
with open('db/ptools.yaml', 'r') as yaml_file:
|
||||
data = yaml.load(yaml_file, Loader=yaml.FullLoader)
|
||||
logger.info(f'原始文档{data}')
|
||||
with open(file_path, 'w') as toml_f:
|
||||
toml_f.write('')
|
||||
toml.dump(data, toml_f)
|
||||
logger.info(f'配置文件生成成功!')
|
||||
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
|
||||
})
|
||||
with open(file_path, 'rb') as f:
|
||||
response = HttpResponse(f)
|
||||
logger.info(response)
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
data=response.content.decode('utf8')
|
||||
).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
return render(request, 'auto_pt/settings.html', context={
|
||||
'config': f'{e}'
|
||||
})
|
||||
raise
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='获取配置文件信息失败!'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def get_config_html(request):
|
||||
return render(request, 'auto_pt/settings.html')
|
||||
|
||||
|
||||
def save_config_api(request):
|
||||
file_path = os.path.join(BASE_DIR, 'db/ptools.toml')
|
||||
content = json.loads(request.body.decode())
|
||||
logger.info(content.get('settings'))
|
||||
try:
|
||||
with open(file_path, 'w') as f:
|
||||
f.write(content.get('settings'))
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
msg='配置文件保存成功!'
|
||||
).to_dict(), safe=False)
|
||||
except Exception as e:
|
||||
raise
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg='获取配置文件信息失败!'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
@@ -279,19 +279,19 @@ SIMPLEUI_CONFIG = {
|
||||
'name': '站点导入',
|
||||
'icon': 'fas fa-file-import',
|
||||
'url': '/tasks/import_from_ptpp'
|
||||
}, {
|
||||
'name': '日志查看',
|
||||
'icon': 'fab fa-blogger',
|
||||
'url': '/tasks/show_log_list'
|
||||
}, ]
|
||||
}, {
|
||||
'app': 'update',
|
||||
'name': '系统配置',
|
||||
'icon': 'fas fa-cog',
|
||||
'models': [{
|
||||
'name': '修改配置',
|
||||
'name': '配置项',
|
||||
'icon': 'fas fa-edit',
|
||||
'url': '/tasks/get_config_setting'
|
||||
'url': '/tasks/get_config_html'
|
||||
}, {
|
||||
'name': '日志查看',
|
||||
'icon': 'fab fa-blogger',
|
||||
'url': '/tasks/show_log_list'
|
||||
}, ]
|
||||
}]
|
||||
}
|
||||
|
||||
@@ -8,33 +8,119 @@
|
||||
<title>Title</title>
|
||||
{% include 'admin/includes/css-part.html' %}
|
||||
<style>
|
||||
#codeEditor {
|
||||
width: 500px;
|
||||
height: 400px;
|
||||
.el-textarea__inner {
|
||||
color: #F2F6FC;
|
||||
background-color: #1f2c39 !important;
|
||||
font-size: 16px;
|
||||
font-family: 'Heiti SC';
|
||||
line-height: 24px;
|
||||
word-break: break-word;
|
||||
border: 1px solid #eee;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
word-spacing: 3px;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="settings">
|
||||
<code v-html="config" id="codeEditor" class="ace_editor" type="textarea"></code>
|
||||
<div id="app">
|
||||
<div style="width: 100%">
|
||||
<el-popconfirm title="确定修改配置文件吗?" @confirm="saveSettings">
|
||||
<el-button type="primary" slot="reference" size="small">保存</el-button>
|
||||
</el-popconfirm>
|
||||
</div>
|
||||
|
||||
<div style="width: 100%;margin-top: 5px;">
|
||||
<el-input v-model="settings" type="textarea" autosize="{minRows: 30}" autocorrect="off"
|
||||
class="settings"></el-input>
|
||||
</div>
|
||||
|
||||
</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',
|
||||
el: '#app',
|
||||
data() {
|
||||
return {
|
||||
config: "{{ config }}",
|
||||
settings: '',
|
||||
}
|
||||
},
|
||||
beforeMount() {
|
||||
|
||||
this.get_config_settings()
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
methods: {}
|
||||
methods: {
|
||||
get_config_settings() {
|
||||
axios.get(
|
||||
"{% url 'get_config_api' %}"
|
||||
).then(res => {
|
||||
console.log('获取数据列表成功', res)
|
||||
{#let data = res.data#}
|
||||
{#console.log(typeof res.data.data)#}
|
||||
if (res.data.code === 0) {
|
||||
this.settings = res.data.data
|
||||
console.log(this.settings)
|
||||
//this.$message({
|
||||
// type: 'success',
|
||||
// message: res.data.msg
|
||||
//});
|
||||
} else {
|
||||
this.loading = false
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '获取数据列表失败!'
|
||||
});
|
||||
}
|
||||
}).catch(res => {
|
||||
console.log('获取数据列表失败', res)
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '获取数据列表失败!' + res
|
||||
});
|
||||
})
|
||||
},
|
||||
saveSettings() {
|
||||
axios({
|
||||
method: "post",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
url: "{% url 'save_config_api' %}",
|
||||
data: {
|
||||
settings: this.settings
|
||||
}
|
||||
}).then(res => {
|
||||
console.log('获取数据列表成功', res)
|
||||
{#let data = res.data#}
|
||||
{#console.log(typeof res.data.data)#}
|
||||
if (res.data.code === 0) {
|
||||
console.log(res.data.msg)
|
||||
this.get_config_settings()
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: res.data.msg
|
||||
});
|
||||
} else {
|
||||
this.loading = false
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '获取数据列表失败!'
|
||||
});
|
||||
}
|
||||
}).catch(res => {
|
||||
console.log('获取数据列表失败', res)
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '获取数据列表失败!' + res
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
@@ -151,7 +151,6 @@
|
||||
method: "get",
|
||||
headers: {
|
||||
"content-type": "application/json", // 默认值
|
||||
Authorization: "Bearer " + sessionStorage.getItem("access_token"),
|
||||
},
|
||||
url: "{% url 'download_log_file' %}" + '?name=' + this.log,
|
||||
responseType: "blob",
|
||||
|
||||
Reference in New Issue
Block a user