22import asyncio , threading , time , os
33import json , logging , traceback
44from selenium import webdriver
5+ import re
56
67from utils .config import Config
78from utils .common import Common
@@ -208,6 +209,17 @@ async def send_to_all_websockets(data):
208209 for ws in connected_websockets :
209210 await ws .send (data )
210211
212+ def extract_filename (video_path ):
213+ if '=' in video_path :
214+ filepath = video_path .split ('=' )[1 ]
215+ else :
216+ filepath = video_path
217+
218+ match = re .search (r'[^\\/:*?"<>|\r\n]+$' , filepath )
219+ if match :
220+ return match .group ()
221+ else :
222+ return common .get_filename_with_ext (filepath )
211223
212224@app .route ('/show' , methods = ['POST' ])
213225async def show ():
@@ -223,20 +235,19 @@ async def show():
223235 logging .debug (f"视频文件移动到的路径:{ static_video_path } " )
224236
225237 filename = ""
238+ move_file = data .get ("move_file" )
239+ is_linux = common .detect_os () == "Linux"
226240
227- if "move_file" in data :
228- if common .detect_os () == "Linux" :
229- filepath = video_path .split ('=' )[1 ]
230- filename = common .get_filename_with_ext (filepath )
231- logging .info (f"视频文件名:{ filename } " )
232- ret = common .move_and_rename (video_path , static_video_path , new_filename = filename , move_file = data ["move_file" ])
241+ if move_file :
242+ if is_linux :
243+ filename = extract_filename (video_path )
244+ ret = common .move_and_rename (video_path , static_video_path , new_filename = filename , move_file = move_file )
233245 else :
234- ret = common .move_and_rename (video_path , static_video_path , move_file = data [ " move_file" ] )
246+ ret = common .move_and_rename (video_path , static_video_path , move_file = move_file )
235247 filename = common .get_filename_with_ext (video_path )
236248 else :
237- if common .detect_os () == "Linux" :
238- filepath = video_path .split ('=' )[1 ]
239- filename = common .get_filename_with_ext (filepath )
249+ if is_linux :
250+ filename = extract_filename (video_path )
240251 ret = common .move_and_rename (video_path , static_video_path , new_filename = filename )
241252 else :
242253 ret = common .move_and_rename (video_path , static_video_path )
0 commit comments