Skip to content

Commit d4d08fc

Browse files
committed
添加是否支持局域网访问选项,默认为false
1 parent 975baf8 commit d4d08fc

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

pywxdump/cli.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ def init_parses(self, parser):
185185
metavar="")
186186
sb_decrypt.add_argument("-myid", "--my_wxid", type=str, help="(可选)微信账号(本人微信id)", required=False,
187187
default="wxid_vzzcn5fevion22", metavar="")
188+
sb_decrypt.add_argument("--online", type=bool, help="(可选)是否在线查看(局域网查看)", required=False,
189+
default=False, metavar="")
188190
return sb_decrypt
189191

190192
def run(self, args):
@@ -206,22 +208,8 @@ def run(self, args):
206208
from flask_cors import CORS
207209
from pywxdump.api import api
208210

209-
# if getattr(sys, 'frozen', False):
210-
# # The application is run as a bundled executable (PyInstaller)
211-
# base_dir = sys._MEIPASS
212-
# else:
213-
# # The application is run as a script
214-
# base_dir = os.path.abspath(os.path.dirname(__file__))
215-
216-
# template_folder = os.path.join(base_dir, 'ui/web')
217-
# static_folder = os.path.join(base_dir, 'ui/web/assets/')
218-
219211
app = Flask(__name__, template_folder='./ui/web', static_folder='./ui/web/assets/', static_url_path='/assets/')
220212

221-
# app.template_folder = template_folder
222-
# app.static_folder = static_folder
223-
# app.static_url_path = '/assets/'
224-
225213
app.logger.setLevel(logging.ERROR)
226214

227215
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True) # 允许所有域名跨域
@@ -252,17 +240,23 @@ def before_request():
252240
print("Unsupported platform, can't open browser automatically.")
253241
except Exception as e:
254242
pass
255-
import socket
243+
256244
def is_port_in_use(host, port):
245+
import socket
257246
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
258247
try:
259248
s.bind((host, port))
260249
except socket.error:
261250
return True
262251
return False
263252

253+
online = args.online
264254
# 检查端口是否被占用
265-
host = '0.0.0.0'
255+
if online:
256+
host = '0.0.0.0'
257+
else:
258+
host = "127.0.0.1"
259+
266260
port = 5000
267261
if is_port_in_use(host, port):
268262
print(f"Port {port} is already in use. Choose a different port.")
@@ -432,6 +426,7 @@ def run(self, args):
432426
args.media_path = merge_save_path
433427
args.wxid_path = filePath
434428
args.my_wxid = wxid
429+
args.online = False
435430
MainShowChatRecords().run(args)
436431

437432

0 commit comments

Comments
 (0)