diff --git a/class/core/mw.py b/class/core/mw.py index 181e52c75..b54ad11dd 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -908,6 +908,11 @@ def aesDecrypt_Crypto(data, key, vi): text_decrypted = text_decrypted.decode('utf8').rstrip() # 去掉补位的右侧空格 return text_decrypted +def getDefault(data,val,def_val=''): + if val in data: + return data[val] + return def_val + def encodeImage(imgsrc, newsrc): # 图片加密 import struct diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 40f8efdb8..2faa3efa6 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -220,7 +220,6 @@ def runDocInfo(): result["dbs"] = showDbList return mw.getJson(result) - def runReplInfo(): import pymongo @@ -242,11 +241,11 @@ def runReplInfo(): if 'secondary' in repl and not repl['secondary']: result['status'] = '主' - result['setName'] = repl['setName'] - result['primary'] = repl['primary'] - result['me'] = repl['me'] + result['setName'] = mw.getDefault(repl,'setName', '') + result['primary'] = mw.getDefault(repl,'primary', '') + result['me'] = mw.getDefault(repl,'me', '') - hosts = repl['hosts'] + hosts = mw.getDefault(repl,'hosts', '') result['hosts'] = ','.join(hosts)