few more adjustments
This commit is contained in:
parent
62d6e4c2a2
commit
f2bf43ca84
|
@ -2,6 +2,7 @@ import copy
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
|
@ -15,6 +16,8 @@ from nio import (AsyncClient, InviteMemberEvent, JoinError, MatrixRoom, RoomMess
|
||||||
|
|
||||||
from exporter.export import download_mxc, zip_directory, upload_to_r2, trim_filename, fetch_events
|
from exporter.export import download_mxc, zip_directory, upload_to_r2, trim_filename, fetch_events
|
||||||
|
|
||||||
|
CLEAN_ROOM_NAME_RE = re.compile('[^a-zA-Z0-9]')
|
||||||
|
|
||||||
|
|
||||||
class RoomExport:
|
class RoomExport:
|
||||||
def __init__(self, room_id: str, allowed_again: datetime):
|
def __init__(self, room_id: str, allowed_again: datetime):
|
||||||
|
@ -82,7 +85,8 @@ class MatrixBotCallbacks:
|
||||||
if event.sender == self.client.user_id:
|
if event.sender == self.client.user_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.logger.info(f"Export for {room.room_id} requested by {event.sender}")
|
requestor = event.sender
|
||||||
|
self.logger.info(f'Export for "{room.name}" ({room.room_id}) requested by {requestor}')
|
||||||
await self.client.room_read_markers(room.room_id, event.event_id, event.event_id)
|
await self.client.room_read_markers(room.room_id, event.event_id, event.event_id)
|
||||||
|
|
||||||
if not self.exports.check_allowed(room.room_id):
|
if not self.exports.check_allowed(room.room_id):
|
||||||
|
@ -103,11 +107,15 @@ class MatrixBotCallbacks:
|
||||||
'm.room.message',
|
'm.room.message',
|
||||||
content
|
content
|
||||||
)
|
)
|
||||||
self.logger.info(f"Rejected export in {room.room_id}, {minutes_until_future} minutes remaining.")
|
self.logger.info(f'Rejected export in {room.room_id}, {minutes_until_future} minutes remaining.')
|
||||||
return
|
return
|
||||||
|
|
||||||
export_created = int(time.time())
|
export_created = int(time.time())
|
||||||
zipfile_name = f'{room.room_id.replace(":", "_").replace("!", "").replace(".", "")}-{int(time.time())}.zip'
|
clean_room_name_str = ''
|
||||||
|
if room.name:
|
||||||
|
clean_room_name = CLEAN_ROOM_NAME_RE.sub('', room.name)
|
||||||
|
clean_room_name_str = f'{clean_room_name}-'
|
||||||
|
zipfile_name = f'{clean_room_name_str}{room.room_id.replace(":", "_").replace("!", "").replace(".", "")}-{int(time.time())}.zip'
|
||||||
zipfile_path = None
|
zipfile_path = None
|
||||||
temp_dir = None
|
temp_dir = None
|
||||||
|
|
||||||
|
@ -144,6 +152,11 @@ class MatrixBotCallbacks:
|
||||||
exported_events.append(event.source)
|
exported_events.append(event.source)
|
||||||
|
|
||||||
exported_data = {
|
exported_data = {
|
||||||
|
'room': {
|
||||||
|
'id': room.room_id,
|
||||||
|
'name': room.name
|
||||||
|
},
|
||||||
|
'requesting_user': requestor,
|
||||||
'exporting_user': self.client.user_id,
|
'exporting_user': self.client.user_id,
|
||||||
'created': export_created,
|
'created': export_created,
|
||||||
'events': sorted(exported_events, key=lambda x: x['origin_server_ts'])
|
'events': sorted(exported_events, key=lambda x: x['origin_server_ts'])
|
||||||
|
|
Loading…
Reference in New Issue