diff --git a/auto_pt/views.py b/auto_pt/views.py index eeb895c..3b7a942 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -203,6 +203,25 @@ def do_update(request): for i in out: result.append(i.decode('utf8')) print(result) + return JsonResponse(data=CommonResponse.success( + msg='更新成功!!', + data={ + 'result': result, + # 'xpath_update': xpath_update + }).to_dict(), safe=False) + except Exception as e: + return JsonResponse(data=CommonResponse.error( + msg='更新指令发送失败!' + str(e) + ).to_dict(), safe=False) + + +def do_update_xpath(request): + try: + # 备份数据库 + subprocess.Popen( + 'cp /var/www/html/ptools/db/db.sqlite3 /var/www/html/ptools/db/db.sqlite3-$(date "+%Y%m%d%H%M%S")', + shell=True + ) # 更新数据库 with open('./pt_site_site.json', 'r') as f: # print(f.readlines()) @@ -215,17 +234,16 @@ def do_update(request): if site.get('pk'): del site['pk'] site_obj = Site.objects.update_or_create(defaults=site, url=site.get('url')) - xpath_update.append(site_obj) print(site_obj) + xpath_update.append(site_obj[0].name + ' 规则新增成功!' if site_obj[1] else '更新成功!') return JsonResponse(data=CommonResponse.success( msg='更新成功!!', data={ - 'result': result, - # 'xpath_update': xpath_update + 'update_log': xpath_update }).to_dict(), safe=False) except Exception as e: return JsonResponse(data=CommonResponse.error( - msg='更新指令发送失败!' + str(e) + msg='更新失败!' + str(e) ).to_dict(), safe=False) diff --git a/templates/auto_pt/restart.html b/templates/auto_pt/restart.html index f215a21..3c3e64f 100644 --- a/templates/auto_pt/restart.html +++ b/templates/auto_pt/restart.html @@ -22,9 +22,29 @@ {# 刷新页面#} -{# 更新#} - 更新 - 重启 + + 规则更新 + + + 代码更新 + + + 重启容器 + +
@@ -118,7 +138,40 @@ } , methods: { - do_refresh() { + do_update_xpath() { + this.$confirm('此操作将覆盖本地规则,请提前备份,是否继续?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + axios.get( + "{% url "do_update_xpath" %}" + ).then(res => { + if (res.data.code === 0) { + this.$message({ + type: 'success', + message: res.data.msg + }); + this.update_log = res.data.data.update_log + } else { + console.log(res) + this.$message({ + type: 'warning', + message: res.data.msg + }); + } + }).catch(res => { + this.$message({ + type: 'error', + message: "更新失败!" + }); + }) + }).catch(res => { + this.$message({ + type: 'info', + message: '已取消更新' + }); + }); }, do_restart() { this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', { @@ -174,8 +227,6 @@ type: 'success', message: res.data.msg }); - location.reload() - } else { console.log(res, 2) this.$message({ diff --git a/update.sh b/update.sh index c99085e..0ddd66b 100755 --- a/update.sh +++ b/update.sh @@ -1,5 +1,5 @@ # 先备份数据库文件再拉取更新 $(date "+%Y%m%d%H%M%S")当前时间年月日时分秒 -cp /var/www/html/ptools/db/db.sqlite3 /var/www/html/ptools/db/db.sqlite3-$(date "+%Y%m%d%H%M%S") && +#cp /var/www/html/ptools/db/db.sqlite3 /var/www/html/ptools/db/db.sqlite3-$(date "+%Y%m%d%H%M%S") && git pull && mv -f /var/www/html/ptools/start.sh /var/www/html/start.sh && python manage.py makemigrations &&