From 88a41bb561b030bf3806abd413c86e68893b7679 Mon Sep 17 00:00:00 2001 From: soxft Date: Tue, 28 Jun 2022 03:11:33 +0000 Subject: [PATCH] =?UTF-8?q?feta:=20=E5=9F=BA=E6=9C=AC=E6=B7=BB=E5=8A=A0/?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=20301=20=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/site_api.py | 16 ++++++----- route/static/app/site.js | 59 ++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/class/core/site_api.py b/class/core/site_api.py index 404848e25..fb9c623c1 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -1181,6 +1181,7 @@ class site_api: data_path = self.getRedirectDataPath(_siteName) data_content = mw.readFile(data_path) if data_content == False: + mw.execShell("mkdir {}/{}".format(self.redirectPath, _siteName)) return mw.returnJson(True, "", {"result": [], "count": 0}) # get # conf_path = "{}/{}/*.conf".format(self.redirectPath, siteName) @@ -1211,13 +1212,11 @@ class site_api: data_path = self.getRedirectDataPath(_siteName) data_content = mw.readFile(data_path) if os.path.exists(data_path) else "" - data = json.loads(data_content) if data_content != "" else {} + data = json.loads(data_content) if data_content != "" else [] _rTypeCode = 0 if _rType == "301" else 1 _typeCode = 0 if _type == "path" else 1 - _keepPath = 1 if _keepPath == "true" else 0 - redirect_type = "permanent" if _rType == 0 else "temporary" pathQuery = "" if _keepPath == 1: # path @@ -1231,11 +1230,14 @@ class site_api: file_content = "" # path if _typeCode == 0: - file_content = """if ($host ~ '^{}'){ - return {} {}{}; - }""".format(_from, _rType ,_to, pathQuery) - else: + redirect_type = "permanent" if _rTypeCode == 0 else "temporary" file_content = "rewrite ^{} {}{} {};".format(_from, _to, pathQuery, redirect_type) + else: + redirect_type = "301" if _rTypeCode == 0 else "302" + _if = "if ($host ~ '^{}')".format(_from) + _return = "return {} {}{}; ".format(redirect_type, _to, pathQuery) + file_content = _if + "{\r\n " + _return + "\r\n}" + _hash = mw.md5("{}+{}".format(file_content, time.time())) diff --git a/route/static/app/site.js b/route/static/app/site.js index cf119feb3..1952077c3 100755 --- a/route/static/app/site.js +++ b/route/static/app/site.js @@ -1427,16 +1427,14 @@ function to301(siteName, type, obj){ // 设置 更新展示 if(type == 1 || type == 3){ obj = { - redirectname: (new Date()).valueOf(), - tourl: 'http://', - redirectdomain: [], - redirectpath: '', - redirecttype: '', + to: 'http://', + from: '', + r_type: '', type: 1, - domainorpath: 'domain', - holdpath: 1 + type: 'domain', + keep_path: 1 } - layer.open({ + var redirect_form = layer.open({ type: 1, skin: 'demo-class', area: '650px', @@ -1448,26 +1446,22 @@ function to301(siteName, type, obj){ "
" + "
" + "保留URI参数" + - "" + - "
" + + "" + "
" + - "" + "
" + "重定向类型" + "
" + - "" + + "" + "重定向方式" + - "
" + + "
" + "" + "
" + "重定向源" + "
" + - "" + + "" + "目标URL" + - "" + + "" + "
" + "
" + "" + @@ -1476,17 +1470,27 @@ function to301(siteName, type, obj){ }); setTimeout(function() { $('.btn-colse-prosy').click(function() { - form_redirect.close(); + layer.close(redirect_form); }); $('.btn-submit-redirect').click(function() { - var holdpath = $('[name="holdpath"]').prop('checked') ? 1 : 0; - var redirectname = $('[name="redirectname"]').val(); - var redirecttype = $('[name="redirecttype"]').val(); + var keep_path = $('[name="keep_path"]').prop('checked') ? 1 : 0; + var r_type = $('[name="r_type"]').val(); var type = $('[name="type"]').val(); - var redirectpath = $('[name="redirectpath"]').val(); - var redirectdomain = JSON.stringify($('.selectpicker').val() || []); - var tourl = $(domainorpath == 'path' ? '[name="tourl1"]' : '[name="tourl"]').val(); - console.log(type, holdpath, redirectname, redirecttype, domainorpath, redirectpath, redirectdomain, tourl); + var from = $('[name="from"]').val(); + var to = $('[name="to"]').val(); + + $.post('/site/set_redirect', { + siteName: siteName, + type: type, + r_type: r_type, + from: from, + to: to, + keep_path: keep_path + }, function(res) { + res = JSON.parse(res); + console.log(res) + to301(siteName) + }); }); }, 100); } @@ -1526,11 +1530,12 @@ function to301(siteName, type, obj){ let data = res.data.result; data.forEach(function(item){ lan_r_type = item.r_type == 0 ? "永久重定向" : "临时重定向" + keep_path = item.keep_path == 0 ? "不保留" : "保留" let tmp = '\ '+item.from+'\ '+lan_r_type+'\ - '+lan_r_type+'\ - 编辑\ + '+keep_path+'\ + 编辑\ '; $("#md-301-body").append(tmp); })