mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
新增 下载日志功能
This commit is contained in:
@@ -32,6 +32,7 @@ urlpatterns = [
|
||||
path(r'get_log_list', views.get_log_list, name='get_log_list'),
|
||||
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'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'),
|
||||
|
||||
@@ -11,7 +11,7 @@ import git
|
||||
import qbittorrentapi
|
||||
import transmission_rpc
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import JsonResponse
|
||||
from django.http import JsonResponse, FileResponse
|
||||
from django.shortcuts import render
|
||||
|
||||
from pt_site.UtilityTool import MessageTemplate, FileSizeConvert
|
||||
@@ -922,6 +922,20 @@ def remove_log_api(request):
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def download_log_file(request):
|
||||
try:
|
||||
name = request.GET.get('name')
|
||||
file_path = os.path.join(BASE_DIR, f'db/{name}')
|
||||
response = FileResponse(open(file_path, 'rb'))
|
||||
response['content-type'] = "application/octet-stream;charset=utf-8"
|
||||
response['Content-Disposition'] = 'attachment; filename=' + os.path.basename(file_path)
|
||||
return response
|
||||
except Exception as e:
|
||||
return JsonResponse(data=CommonResponse.error(
|
||||
msg=f'文件不存在?!{e}'
|
||||
).to_dict(), safe=False)
|
||||
|
||||
|
||||
def show_log_list(request):
|
||||
return render(request, 'auto_pt/showlog.html')
|
||||
|
||||
|
||||
@@ -38,9 +38,17 @@
|
||||
v-for="(name,index) in names" :index="index" :label="name" :value="name">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-button type="primary" @click="showLog" size="small">查看日志</el-button>
|
||||
<el-popconfirm title="确定删除此站点信息吗?" @confirm="removeLog">
|
||||
<el-button type="danger" size="small" slot="reference">删除日志</el-button>
|
||||
<el-link type="success" size="small"
|
||||
icon="fas fa-download"
|
||||
:href="'{% url 'download_log_file' %}' + '?name=' + log">下载
|
||||
</el-link>
|
||||
<el-button type="primary" @click="showLog" size="small" icon="fas fa-eye">
|
||||
查看
|
||||
</el-button>
|
||||
<el-popconfirm title="确定删除日志吗?" @confirm="removeLog">
|
||||
<el-button type="danger" size="small" icon="fas fa-trash"
|
||||
slot="reference">删除
|
||||
</el-button>
|
||||
</el-popconfirm>
|
||||
</div>
|
||||
<el-container style="height: 780px; border: 1px solid #eee;margin-top: 5px;">
|
||||
@@ -138,6 +146,36 @@
|
||||
});
|
||||
})
|
||||
},
|
||||
downloadLog() {
|
||||
axios({
|
||||
method: "get",
|
||||
headers: {
|
||||
"content-type": "application/json", // 默认值
|
||||
Authorization: "Bearer " + sessionStorage.getItem("access_token"),
|
||||
},
|
||||
url: "{% url 'download_log_file' %}" + '?name=' + this.log,
|
||||
responseType: "blob",
|
||||
}).then(res => {
|
||||
console.log('日志文件', res)
|
||||
{#let data = res.data#}
|
||||
{#console.log(typeof res.data.data)#}
|
||||
if (res.headers['content-type'] === 'application/octet-stream;charset=utf-8') {
|
||||
return res.data
|
||||
} else {
|
||||
this.loading = false
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '删除日志文件失败!'
|
||||
});
|
||||
}
|
||||
}).catch(res => {
|
||||
console.log('删除日志文件失败', res)
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '删除日志文件失败!' + res
|
||||
});
|
||||
})
|
||||
},
|
||||
removeLog() {
|
||||
if (this.log == 'logs.log') {
|
||||
this.$message({
|
||||
|
||||
Reference in New Issue
Block a user