返回提交历史
Modified
g4f/gui/server/backend_api.py
+3
-3
XFEstudio/gpt4free
Add UTF-8 encoding to file writes in Backend_Api class
957d73a7
代码差异
1 个文件
+3
-3
@@ -440,7 +440,7 @@ class Backend_Api(Api):
440
440
os.remove(copyfile)
441
441
continue
442
442
if not is_media and result:
443
with open(os.path.join(bucket_dir, f"{filename}.md"), 'w') as f:
443
with open(os.path.join(bucket_dir, f"{filename}.md"), 'w', encoding="utf-8") as f:
444
444
f.write(f"{result}\n")
445
445
filenames.append(f"{filename}.md")
446
446
if is_media:
@@ -477,7 +477,7 @@ class Backend_Api(Api):
477
477
except OSError:
478
478
shutil.copyfile(copyfile, newfile)
479
479
os.remove(copyfile)
480
with open(os.path.join(bucket_dir, "files.txt"), 'w') as f:
480
with open(os.path.join(bucket_dir, "files.txt"), 'w', encoding="utf-8") as f:
481
481
for filename in filenames:
482
482
f.write(f"{filename}\n")
483
483
return {"bucket_id": bucket_id, "files": filenames, "media": media}
@@ -572,7 +572,7 @@ class Backend_Api(Api):
572
572
share_id = secure_filename(share_id)
573
573
bucket_dir = get_bucket_dir(share_id)
574
574
os.makedirs(bucket_dir, exist_ok=True)
575
with open(os.path.join(bucket_dir, "chat.json"), 'w') as f:
575
with open(os.path.join(bucket_dir, "chat.json"), 'w', encoding="utf-8") as f:
576
576
json.dump(chat_data, f)
577
577
self.chat_cache[share_id] = updated
578
578
return {"share_id": share_id}