mirror of
https://github.com/FAUSheppy/tmnf-replay-server.git
synced 2026-04-26 22:12:28 +02:00
fix: handle Gbx error & better s3 naming scheme
This commit is contained in:
@@ -9,6 +9,7 @@ import json
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from pygbx import Gbx, GbxType
|
from pygbx import Gbx, GbxType
|
||||||
|
import pygbx
|
||||||
import tm2020parser
|
import tm2020parser
|
||||||
import notifications
|
import notifications
|
||||||
|
|
||||||
@@ -541,7 +542,7 @@ def upload():
|
|||||||
try:
|
try:
|
||||||
replay = replay_from_path(tmp_path, uploader=uploader)
|
replay = replay_from_path(tmp_path, uploader=uploader)
|
||||||
|
|
||||||
new_basename = f"{replay.uploader}_{replay.filehash}_{fname}"
|
new_basename = f"{replay.filehash}"
|
||||||
fullpath = os.path.join("uploads", new_basename)
|
fullpath = os.path.join("uploads", new_basename)
|
||||||
|
|
||||||
os.rename(tmp_path, fullpath)
|
os.rename(tmp_path, fullpath)
|
||||||
@@ -549,8 +550,7 @@ def upload():
|
|||||||
replay.filepath = fullpath
|
replay.filepath = fullpath
|
||||||
|
|
||||||
if s3_enabled():
|
if s3_enabled():
|
||||||
s3_key = upload_to_s3(fullpath, replay)
|
s3_key = upload_to_s3(new_basename, replay)
|
||||||
replay.filepath = s3_key
|
|
||||||
os.remove(fullpath)
|
os.remove(fullpath)
|
||||||
|
|
||||||
db.session.add(replay)
|
db.session.add(replay)
|
||||||
@@ -561,6 +561,9 @@ def upload():
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
results.append((fname, str(e)))
|
results.append((fname, str(e)))
|
||||||
continue
|
continue
|
||||||
|
except pygbx.Gbx as e:
|
||||||
|
print(f"Failed to load Replay: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
except sqlalchemy.exc.IntegrityError as e:
|
except sqlalchemy.exc.IntegrityError as e:
|
||||||
results.append((fname, str(e.args)))
|
results.append((fname, str(e.args)))
|
||||||
|
|||||||
Reference in New Issue
Block a user