替换 FlaskService.py

This commit is contained in:
何勇
2024-08-21 07:56:30 +00:00
parent 18409b02c6
commit 61df337ee0

View File

@@ -25,8 +25,11 @@ def upload_file():
filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename) filepath = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(filepath) file.save(filepath)
appsketch_api = request.form.get('url', 'default_value')
pcap_file_id = request.form.get('id', 'default_value')
# Use PcapNGFormatAnalys.py # Use PcapNGFormatAnalys.py
modified_filepath = modify_file_with_script(filepath) modified_filepath = modify_file_with_script(filepath, appsketch_api, pcap_file_id)
# Delete uploaded and modified files after response # Delete uploaded and modified files after response
@@ -42,11 +45,11 @@ def upload_file():
# Provide modified file download # Provide modified file download
return send_file(modified_filepath, as_attachment=True) return send_file(modified_filepath, as_attachment=True)
def modify_file_with_script(input_filepath): def modify_file_with_script(input_filepath, appsketch_api, pcap_file_id):
modified_filepath = os.path.join(app.config['MODIFIED_FOLDER'], os.path.basename(input_filepath)) modified_filepath = os.path.join(app.config['MODIFIED_FOLDER'], os.path.basename(input_filepath))
# Use PcapNGFormatAnalys.py to add Remark # Use PcapNGFormatAnalys.py to add Remark
script_path = 'PcapNGFormatAnalys.py' script_path = 'PcapNGFormatAnalys.py'
subprocess.run(['python', script_path, input_filepath, modified_filepath]) subprocess.run(['python3', script_path, input_filepath, modified_filepath, appsketch_api, pcap_file_id])
return modified_filepath return modified_filepath
if __name__ == '__main__': if __name__ == '__main__':