1
1
import zipfile
2
- from typing import *
2
+ import base64
3
+ from typing import Union , Dict , Set , Tuple
3
4
4
5
from flask import request , flash , redirect , url_for , render_template
5
6
from markupsafe import Markup
@@ -30,7 +31,15 @@ def check():
30
31
flash (options )
31
32
else :
32
33
results , _ = roll_options (options )
33
- return render_template ("checkResult.html" , results = results )
34
+ if len (options ) > 1 :
35
+ # offer combined file back
36
+ combined_yaml = "---\n " .join (f"# original filename: { file_name } \n { file_content .decode ('utf-8-sig' )} "
37
+ for file_name , file_content in options .items ())
38
+ combined_yaml = base64 .b64encode (combined_yaml .encode ("utf-8-sig" )).decode ()
39
+ else :
40
+ combined_yaml = ""
41
+ return render_template ("checkResult.html" ,
42
+ results = results , combined_yaml = combined_yaml )
34
43
return render_template ("check.html" )
35
44
36
45
@@ -41,31 +50,32 @@ def mysterycheck():
41
50
42
51
def get_yaml_data (files ) -> Union [Dict [str , str ], str , Markup ]:
43
52
options = {}
44
- for file in files :
53
+ for uploaded_file in files :
45
54
# if user does not select file, browser also
46
55
# submit an empty part without filename
47
- if file .filename == '' :
56
+ if uploaded_file .filename == '' :
48
57
return 'No selected file'
49
- elif file .filename in options :
50
- return f'Conflicting files named { file .filename } submitted'
51
- elif file and allowed_file (file .filename ):
52
- if file .filename .endswith (".zip" ):
58
+ elif uploaded_file .filename in options :
59
+ return f'Conflicting files named { uploaded_file .filename } submitted'
60
+ elif uploaded_file and allowed_file (uploaded_file .filename ):
61
+ if uploaded_file .filename .endswith (".zip" ):
53
62
54
- with zipfile .ZipFile (file , 'r' ) as zfile :
63
+ with zipfile .ZipFile (uploaded_file , 'r' ) as zfile :
55
64
infolist = zfile .infolist ()
56
65
57
66
if any (file .filename .endswith (".archipelago" ) for file in infolist ):
58
67
return Markup ("Error: Your .zip file contains an .archipelago file. "
59
- 'Did you mean to <a href="/uploads">host a game</a>?' )
68
+ 'Did you mean to <a href="/uploads">host a game</a>?' )
60
69
61
70
for file in infolist :
62
71
if file .filename .endswith (banned_zip_contents ):
63
- return "Uploaded data contained a rom file, which is likely to contain copyrighted material. " \
64
- "Your file was deleted."
72
+ return ("Uploaded data contained a rom file, "
73
+ "which is likely to contain copyrighted material. "
74
+ "Your file was deleted." )
65
75
elif file .filename .endswith ((".yaml" , ".json" , ".yml" , ".txt" )):
66
76
options [file .filename ] = zfile .open (file , "r" ).read ()
67
77
else :
68
- options [file .filename ] = file .read ()
78
+ options [uploaded_file .filename ] = uploaded_file .read ()
69
79
if not options :
70
80
return "Did not find a .yaml file to process."
71
81
return options
0 commit comments