Fix permanent delete
This commit is contained in:
@@ -103,8 +103,25 @@ def empty_trash(room_id):
|
||||
if not user_has_permission(room, 'can_delete'):
|
||||
abort(403)
|
||||
|
||||
# Delete all trashed files for this room
|
||||
# Get all trashed files for this room
|
||||
trashed_files = TrashedFile.query.filter_by(room_id=room_id).all()
|
||||
room_files = RoomFile.query.filter_by(room_id=room_id, deleted=True).all()
|
||||
|
||||
# Delete physical files
|
||||
room_dir = os.path.join('/data/rooms', str(room_id))
|
||||
for file in trashed_files + room_files:
|
||||
try:
|
||||
if file.type == 'file':
|
||||
file_path = os.path.join(room_dir, file.original_path if hasattr(file, 'original_path') else file.path, file.name)
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
except Exception as e:
|
||||
print(f"Error deleting physical file {file.name}: {str(e)}")
|
||||
continue
|
||||
|
||||
# Delete all trashed files from both tables
|
||||
TrashedFile.query.filter_by(room_id=room_id).delete()
|
||||
RoomFile.query.filter_by(room_id=room_id, deleted=True).delete()
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({'success': True})
|
||||
Reference in New Issue
Block a user