Refactor more code
This commit is contained in:
@@ -20,6 +20,7 @@ import logging
|
||||
|
||||
import magic
|
||||
from PIL import Image
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from telethon.tl.types import (Document, FileLocation, InputFileLocation,
|
||||
InputDocumentFileLocation)
|
||||
@@ -69,7 +70,12 @@ async def transfer_file_to_matrix(db, client, intent, location):
|
||||
db_file = DBTelegramFile(id=id, mxc=uploaded["content_uri"],
|
||||
mime_type=mime_type, was_converted=image_converted,
|
||||
timestamp=int(time.time()))
|
||||
db.add(db_file)
|
||||
db.commit()
|
||||
try:
|
||||
db.add(db_file)
|
||||
db.commit()
|
||||
except IntegrityError:
|
||||
log.exception("Integrity error while saving transferred file data. "
|
||||
"This was probably caused by two simultaneous transfers of the same file, "
|
||||
"and should not cause any problems.")
|
||||
|
||||
return db_file
|
||||
|
||||
Reference in New Issue
Block a user