forked from MarseyWorld/MarseyWorld
add a media check
parent
b544171449
commit
a9dd6bf1e7
|
@ -47,6 +47,9 @@ def process_audio(file):
|
||||||
os.remove(name)
|
os.remove(name)
|
||||||
abort(413)
|
abort(413)
|
||||||
|
|
||||||
|
media = g.db.query(Media).filter_by(filename=name, kind='audio').one_or_none()
|
||||||
|
if media: g.db.delete(media)
|
||||||
|
|
||||||
media = Media(
|
media = Media(
|
||||||
kind='audio',
|
kind='audio',
|
||||||
filename=name,
|
filename=name,
|
||||||
|
@ -67,6 +70,10 @@ def webm_to_mp4(old, new, vid):
|
||||||
data=f'{{"files": ["{SITE_FULL}{new}"]}}', timeout=5)
|
data=f'{{"files": ["{SITE_FULL}{new}"]}}', timeout=5)
|
||||||
|
|
||||||
db = db_session()
|
db = db_session()
|
||||||
|
|
||||||
|
media = db.query(Media).filter_by(filename=name, kind='video').one_or_none()
|
||||||
|
if media: db.delete(media)
|
||||||
|
|
||||||
media = Media(
|
media = Media(
|
||||||
kind='video',
|
kind='video',
|
||||||
filename=new,
|
filename=new,
|
||||||
|
@ -100,6 +107,9 @@ def process_video(file):
|
||||||
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True)
|
subprocess.run(["ffmpeg", "-y", "-loglevel", "warning", "-nostats", "-i", old, "-map_metadata", "-1", "-c:v", "copy", "-c:a", "copy", new], check=True)
|
||||||
os.remove(old)
|
os.remove(old)
|
||||||
|
|
||||||
|
media = g.db.query(Media).filter_by(filename=name, kind='video').one_or_none()
|
||||||
|
if media: g.db.delete(media)
|
||||||
|
|
||||||
media = Media(
|
media = Media(
|
||||||
kind='video',
|
kind='video',
|
||||||
filename=new,
|
filename=new,
|
||||||
|
@ -174,13 +184,17 @@ def process_image(filename=None, resize=0, trim=False, uploader=None, patron=Fal
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
abort(417)
|
abort(417)
|
||||||
|
|
||||||
|
db = db or g.db
|
||||||
|
|
||||||
|
media = db.query(Media).filter_by(filename=name, kind='image').one_or_none()
|
||||||
|
if media: db.delete(media)
|
||||||
|
|
||||||
media = Media(
|
media = Media(
|
||||||
kind='image',
|
kind='image',
|
||||||
filename=filename,
|
filename=filename,
|
||||||
user_id=uploader or g.v.id,
|
user_id=uploader or g.v.id,
|
||||||
size=os.stat(filename).st_size
|
size=os.stat(filename).st_size
|
||||||
)
|
)
|
||||||
db = db or g.db
|
|
||||||
db.add(media)
|
db.add(media)
|
||||||
|
|
||||||
return filename
|
return filename
|
||||||
|
|
Loading…
Reference in New Issue