latest
This commit is contained in:
@@ -18,7 +18,6 @@ import re
|
||||
|
||||
class ClassroomCopilotFilesystem:
|
||||
def __init__(self, db_name: str, init_run_type: str = None):
|
||||
logging.info(f"Initializing ClassroomCopilotFilesystem with db_name: {db_name} and init_run_type: {init_run_type}")
|
||||
|
||||
self.db_name = db_name
|
||||
|
||||
@@ -27,19 +26,21 @@ class ClassroomCopilotFilesystem:
|
||||
if not self.base_path:
|
||||
raise ValueError("NODE_FILESYSTEM_PATH environment variable not set")
|
||||
|
||||
logging.info(f"Initializing ClassroomCopilotFilesystem with db_name: {db_name} and init_run_type: {init_run_type} with base path: {self.base_path}")
|
||||
|
||||
# Set root path based on init type
|
||||
if init_run_type == "school":
|
||||
self.root_path = os.path.join(self.base_path, "schools", self.db_name)
|
||||
self.root_path = os.path.join(self.base_path, "schools")
|
||||
logging.debug(f"School root path: {self.root_path}")
|
||||
elif init_run_type == "user":
|
||||
self.root_path = os.path.join(self.base_path, "users", self.db_name)
|
||||
self.root_path = os.path.join(self.base_path, "users")
|
||||
logging.debug(f"User root path: {self.root_path}")
|
||||
elif init_run_type == "multiplayer":
|
||||
self.root_path = os.path.join(self.base_path, "multiplayer")
|
||||
logging.debug(f"Multiplayer root path: {self.root_path}")
|
||||
else:
|
||||
self.root_path = os.path.join(self.base_path, self.db_name)
|
||||
logging.debug(f"Default root path: {self.root_path}")
|
||||
self.root_path = self.base_path
|
||||
logging.debug(f"Database root path: {self.root_path}")
|
||||
|
||||
# Ensure root directory exists
|
||||
os.makedirs(self.root_path, exist_ok=True)
|
||||
@@ -63,45 +64,33 @@ class ClassroomCopilotFilesystem:
|
||||
return True
|
||||
return False
|
||||
|
||||
def sanitize_username(self, username):
|
||||
return re.sub(r'[^\w\-_\.]', '_', username)
|
||||
|
||||
def create_user_directory(self, username, user_type=None, school_path=None):
|
||||
def create_private_user_directory(self, user_id):
|
||||
"""Create a directory for a specific user."""
|
||||
sanitized_username = self.sanitize_username(username)
|
||||
|
||||
if school_path:
|
||||
# For school database: /schools/[school_db]/users/[user_type]/[username]
|
||||
user_path = os.path.join(self.root_path, "users", user_type, sanitized_username)
|
||||
else:
|
||||
# For user database: /users/[user_db]/[username]
|
||||
user_path = os.path.join(self.root_path, sanitized_username)
|
||||
# For user database: /users/[user_db]/[username]
|
||||
user_path = os.path.join(self.root_path, user_id)
|
||||
|
||||
logging.info(f"Creating user directory at {user_path}")
|
||||
return self.create_directory(user_path), user_path
|
||||
|
||||
def create_user_worker_directory(self, user_path, worker_code):
|
||||
def create_user_worker_directory(self, user_path, worker_id, worker_type):
|
||||
"""Create a worker directory under the user directory."""
|
||||
# Create worker directory: [user_path]/[worker_code]
|
||||
worker_path = os.path.join(user_path, worker_code)
|
||||
worker_path = os.path.join(user_path, worker_type, worker_id)
|
||||
logging.info(f"Creating worker directory at {worker_path}")
|
||||
return self.create_directory(worker_path), worker_path
|
||||
|
||||
def create_school_worker_directory(self, school_path, worker_type):
|
||||
def create_school_worker_directory(self, school_path, worker_type, worker_id):
|
||||
"""Create a worker directory under the school directory."""
|
||||
worker_path = os.path.join(school_path, "workers", worker_type)
|
||||
logging.info(f"Creating school worker directory at {worker_path}")
|
||||
worker_path = os.path.join(school_path, "workers", worker_type, worker_id)
|
||||
logging.info(f"Creating school {worker_type} worker directory at {worker_path}")
|
||||
return self.create_directory(worker_path), worker_path
|
||||
|
||||
def create_school_directory(self, school_uuid=None):
|
||||
def create_school_directory(self, school_uuid_string):
|
||||
"""Create a directory for a specific school."""
|
||||
logging.info(f"Creating school directory with school_uuid: {school_uuid}")
|
||||
if school_uuid is None:
|
||||
logging.debug(f"School UUID is None, creating school directory at {self.root_path}")
|
||||
school_path = self.root_path
|
||||
else:
|
||||
logging.debug(f"School UUID is not None, creating school directory at {os.path.join(self.root_path, school_uuid)}")
|
||||
school_path = os.path.join(self.root_path, school_uuid)
|
||||
logging.info(f"Creating school directory with uuid_string: {school_uuid_string}")
|
||||
logging.debug(f"School UUID is not None, creating school directory at {os.path.join(self.root_path, school_uuid_string)}")
|
||||
school_path = os.path.join(self.root_path, school_uuid_string)
|
||||
return self.create_directory(school_path), school_path
|
||||
|
||||
def create_year_directory(self, year, calendar_path=None):
|
||||
@@ -248,7 +237,12 @@ class ClassroomCopilotFilesystem:
|
||||
"""Create a directory for a specific topic under a year group syllabus."""
|
||||
topic_path = os.path.join(year_group_syllabus_path, "topics", f"{topic_id}")
|
||||
return self.create_directory(topic_path), topic_path
|
||||
|
||||
|
||||
def create_curriculum_keystage_topic_directory(self, keystage_syllabus_path, topic_id):
|
||||
"""Create a directory for a specific key stage topic under a key stage group syllabus."""
|
||||
topic_path = os.path.join(keystage_syllabus_path, "core_topics", f"{topic_id}")
|
||||
return self.create_directory(topic_path), topic_path
|
||||
|
||||
def create_curriculum_lesson_directory(self, topic_path, lesson_id):
|
||||
"""Create a directory for a specific lesson under a topic."""
|
||||
lesson_path = os.path.join(topic_path, "lessons", f"{lesson_id}")
|
||||
@@ -276,285 +270,4 @@ class ClassroomCopilotFilesystem:
|
||||
|
||||
def create_teacher_planned_lesson_directory(self, class_path, lesson_id):
|
||||
planned_lesson_path = os.path.join(class_path, "planned_lessons", lesson_id)
|
||||
return self.create_directory(planned_lesson_path), planned_lesson_path
|
||||
|
||||
# TLDraw File Creation
|
||||
def create_default_tldraw_file(self, node_path, node_data):
|
||||
"""Create a tldraw file for a node."""
|
||||
logging.info(f"Creating tldraw file for node at {node_path}")
|
||||
|
||||
# Ensure the directory exists
|
||||
os.makedirs(node_path, exist_ok=True)
|
||||
|
||||
tldraw_path = os.path.join(node_path, 'tldraw_file.json')
|
||||
|
||||
# Create default tldraw content
|
||||
tldraw_content = {
|
||||
"document": {
|
||||
"store": {
|
||||
"document:document": {
|
||||
"gridSize": 10,
|
||||
"name": "",
|
||||
"meta": {},
|
||||
"id": "document:document",
|
||||
"typeName": "document"
|
||||
},
|
||||
"page:page": {
|
||||
"meta": {},
|
||||
"id": "page:page",
|
||||
"name": "Page 1",
|
||||
"index": "a1",
|
||||
"typeName": "page"
|
||||
}
|
||||
},
|
||||
"schema":
|
||||
{"schemaVersion":2,
|
||||
"sequences": {
|
||||
"com.tldraw.store":4,
|
||||
"com.tldraw.asset":1,
|
||||
"com.tldraw.camera":1,
|
||||
"com.tldraw.document":2,
|
||||
"com.tldraw.instance":25,
|
||||
"com.tldraw.instance_page_state":5,
|
||||
"com.tldraw.page":1,
|
||||
"com.tldraw.instance_presence":5,
|
||||
"com.tldraw.pointer":1,
|
||||
"com.tldraw.shape":4,
|
||||
"com.tldraw.asset.bookmark":2,
|
||||
"com.tldraw.asset.image":5,
|
||||
"com.tldraw.asset.video":5,
|
||||
"com.tldraw.shape.arrow":5,
|
||||
"com.tldraw.shape.bookmark":2,
|
||||
"com.tldraw.shape.draw":2,
|
||||
"com.tldraw.shape.embed":4,
|
||||
"com.tldraw.shape.frame":0,
|
||||
"com.tldraw.shape.geo":9,
|
||||
"com.tldraw.shape.group":0,
|
||||
"com.tldraw.shape.highlight":1,
|
||||
"com.tldraw.shape.image":4,
|
||||
"com.tldraw.shape.line":5,
|
||||
"com.tldraw.shape.note":8,
|
||||
"com.tldraw.shape.text":2,
|
||||
"com.tldraw.shape.video":2,
|
||||
"com.tldraw.shape.youtube-embed":0,
|
||||
"com.tldraw.shape.calendar":0,
|
||||
"com.tldraw.shape.microphone":1,
|
||||
"com.tldraw.shape.transcriptionText":0,
|
||||
"com.tldraw.shape.slide":0,"com.tldraw.shape.slideshow":0,
|
||||
"com.tldraw.shape.user_node":1,
|
||||
"com.tldraw.shape.developer_node":1,
|
||||
"com.tldraw.shape.student_node":1,
|
||||
"com.tldraw.shape.teacher_node":1,
|
||||
"com.tldraw.shape.calendar_node":1,
|
||||
"com.tldraw.shape.calendar_year_node":1,
|
||||
"com.tldraw.shape.calendar_month_node":1,
|
||||
"com.tldraw.shape.calendar_week_node":1,
|
||||
"com.tldraw.shape.calendar_day_node":1,
|
||||
"com.tldraw.shape.calendar_time_chunk_node":1,
|
||||
"com.tldraw.shape.teacher_timetable_node":1,
|
||||
"com.tldraw.shape.timetable_lesson_node":1,
|
||||
"com.tldraw.shape.planned_lesson_node":1,
|
||||
"com.tldraw.shape.pastoral_structure_node":1,
|
||||
"com.tldraw.shape.year_group_node":1,
|
||||
"com.tldraw.shape.curriculum_structure_node":1,
|
||||
"com.tldraw.shape.key_stage_node":1,
|
||||
"com.tldraw.shape.key_stage_syllabus_node":1,
|
||||
"com.tldraw.shape.year_group_syllabus_node":1,
|
||||
"com.tldraw.shape.subject_node":1,
|
||||
"com.tldraw.shape.topic_node":1,
|
||||
"com.tldraw.shape.topic_lesson_node":1,
|
||||
"com.tldraw.shape.learning_statement_node":1,
|
||||
"com.tldraw.shape.science_lab_node":1,
|
||||
"com.tldraw.shape.school_timetable_node":1,
|
||||
"com.tldraw.shape.academic_year_node":1,
|
||||
"com.tldraw.shape.academic_term_node":1,
|
||||
"com.tldraw.shape.academic_week_node":1,
|
||||
"com.tldraw.shape.academic_day_node":1,
|
||||
"com.tldraw.shape.academic_period_node":1,
|
||||
"com.tldraw.shape.registration_period_node":1,
|
||||
"com.tldraw.shape.school_node":1,
|
||||
"com.tldraw.shape.department_node":1,
|
||||
"com.tldraw.shape.room_node":1,
|
||||
"com.tldraw.shape.subject_class_node":1,
|
||||
"com.tldraw.shape.general_relationship":1,
|
||||
"com.tldraw.binding.arrow":0,
|
||||
"com.tldraw.binding.slide-layout":0
|
||||
}
|
||||
},
|
||||
"recordVersions": {
|
||||
"asset": { "version": 1, "subTypeKey": "type", "subTypeVersions": {} },
|
||||
"camera": { "version": 1 },
|
||||
"document": { "version": 2 },
|
||||
"instance": { "version": 21 },
|
||||
"instance_page_state": { "version": 5 },
|
||||
"page": { "version": 1 },
|
||||
"shape": { "version": 3, "subTypeKey": "type", "subTypeVersions": {} },
|
||||
"instance_presence": { "version": 5 },
|
||||
"pointer": { "version": 1 }
|
||||
},
|
||||
"rootShapeIds":[],
|
||||
"bindings":[],
|
||||
"assets":[]
|
||||
},
|
||||
"session": {
|
||||
"version": 0,
|
||||
"currentPageId": "page:page",
|
||||
"pageStates": [{
|
||||
"pageId": "page:page",
|
||||
"camera": {"x": 0, "y": 0, "z": 1},
|
||||
"selectedShapeIds": []
|
||||
}]
|
||||
},
|
||||
"node_data": node_data
|
||||
}
|
||||
|
||||
with open(tldraw_path, 'w') as f:
|
||||
json.dump(tldraw_content, f, indent=4)
|
||||
|
||||
logging.info(f"tldraw file created at {tldraw_path}")
|
||||
return tldraw_path
|
||||
|
||||
def create_default_tldraw_file_in_storage(self, admin_supabase, bucket_id, file_path, node_data):
|
||||
"""Create a tldraw file in Supabase storage."""
|
||||
logging.info(f"Creating tldraw file in storage at {file_path}")
|
||||
|
||||
# Create default tldraw content
|
||||
tldraw_content = {
|
||||
"document": {
|
||||
"store": {
|
||||
"document:document": {
|
||||
"gridSize": 10,
|
||||
"name": "",
|
||||
"meta": {},
|
||||
"id": "document:document",
|
||||
"typeName": "document"
|
||||
},
|
||||
"page:page": {
|
||||
"meta": {},
|
||||
"id": "page:page",
|
||||
"name": "Page 1",
|
||||
"index": "a1",
|
||||
"typeName": "page"
|
||||
}
|
||||
},
|
||||
"schema":
|
||||
{"schemaVersion":2,
|
||||
"sequences": {
|
||||
"com.tldraw.store":4,
|
||||
"com.tldraw.asset":1,
|
||||
"com.tldraw.camera":1,
|
||||
"com.tldraw.document":2,
|
||||
"com.tldraw.instance":25,
|
||||
"com.tldraw.instance_page_state":5,
|
||||
"com.tldraw.page":1,
|
||||
"com.tldraw.instance_presence":5,
|
||||
"com.tldraw.pointer":1,
|
||||
"com.tldraw.shape":4,
|
||||
"com.tldraw.asset.bookmark":2,
|
||||
"com.tldraw.asset.image":5,
|
||||
"com.tldraw.asset.video":5,
|
||||
"com.tldraw.shape.arrow":5,
|
||||
"com.tldraw.shape.bookmark":2,
|
||||
"com.tldraw.shape.draw":2,
|
||||
"com.tldraw.shape.embed":4,
|
||||
"com.tldraw.shape.frame":0,
|
||||
"com.tldraw.shape.geo":9,
|
||||
"com.tldraw.shape.group":0,
|
||||
"com.tldraw.shape.highlight":1,
|
||||
"com.tldraw.shape.image":4,
|
||||
"com.tldraw.shape.line":5,
|
||||
"com.tldraw.shape.note":8,
|
||||
"com.tldraw.shape.text":2,
|
||||
"com.tldraw.shape.video":2,
|
||||
"com.tldraw.shape.youtube-embed":0,
|
||||
"com.tldraw.shape.calendar":0,
|
||||
"com.tldraw.shape.microphone":1,
|
||||
"com.tldraw.shape.transcriptionText":0,
|
||||
"com.tldraw.shape.slide":0,"com.tldraw.shape.slideshow":0,
|
||||
"com.tldraw.shape.user_node":1,
|
||||
"com.tldraw.shape.developer_node":1,
|
||||
"com.tldraw.shape.student_node":1,
|
||||
"com.tldraw.shape.teacher_node":1,
|
||||
"com.tldraw.shape.calendar_node":1,
|
||||
"com.tldraw.shape.calendar_year_node":1,
|
||||
"com.tldraw.shape.calendar_month_node":1,
|
||||
"com.tldraw.shape.calendar_week_node":1,
|
||||
"com.tldraw.shape.calendar_day_node":1,
|
||||
"com.tldraw.shape.calendar_time_chunk_node":1,
|
||||
"com.tldraw.shape.teacher_timetable_node":1,
|
||||
"com.tldraw.shape.timetable_lesson_node":1,
|
||||
"com.tldraw.shape.planned_lesson_node":1,
|
||||
"com.tldraw.shape.pastoral_structure_node":1,
|
||||
"com.tldraw.shape.year_group_node":1,
|
||||
"com.tldraw.shape.curriculum_structure_node":1,
|
||||
"com.tldraw.shape.key_stage_node":1,
|
||||
"com.tldraw.shape.key_stage_syllabus_node":1,
|
||||
"com.tldraw.shape.year_group_syllabus_node":1,
|
||||
"com.tldraw.shape.subject_node":1,
|
||||
"com.tldraw.shape.topic_node":1,
|
||||
"com.tldraw.shape.topic_lesson_node":1,
|
||||
"com.tldraw.shape.learning_statement_node":1,
|
||||
"com.tldraw.shape.science_lab_node":1,
|
||||
"com.tldraw.shape.school_timetable_node":1,
|
||||
"com.tldraw.shape.academic_year_node":1,
|
||||
"com.tldraw.shape.academic_term_node":1,
|
||||
"com.tldraw.shape.academic_week_node":1,
|
||||
"com.tldraw.shape.academic_day_node":1,
|
||||
"com.tldraw.shape.academic_period_node":1,
|
||||
"com.tldraw.shape.registration_period_node":1,
|
||||
"com.tldraw.shape.school_node":1,
|
||||
"com.tldraw.shape.department_node":1,
|
||||
"com.tldraw.shape.room_node":1,
|
||||
"com.tldraw.shape.subject_class_node":1,
|
||||
"com.tldraw.shape.general_relationship":1,
|
||||
"com.tldraw.binding.arrow":0,
|
||||
"com.tldraw.binding.slide-layout":0
|
||||
}
|
||||
},
|
||||
"recordVersions": {
|
||||
"asset": { "version": 1, "subTypeKey": "type", "subTypeVersions": {} },
|
||||
"camera": { "version": 1 },
|
||||
"document": { "version": 2 },
|
||||
"instance": { "version": 21 },
|
||||
"instance_page_state": { "version": 5 },
|
||||
"page": { "version": 1 },
|
||||
"shape": { "version": 3, "subTypeKey": "type", "subTypeVersions": {} },
|
||||
"instance_presence": { "version": 5 },
|
||||
"pointer": { "version": 1 }
|
||||
},
|
||||
"rootShapeIds":[],
|
||||
"bindings":[],
|
||||
"assets":[]
|
||||
},
|
||||
"session": {
|
||||
"version": 0,
|
||||
"currentPageId": "page:page",
|
||||
"pageStates": [{
|
||||
"pageId": "page:page",
|
||||
"camera": {"x": 0, "y": 0, "z": 1},
|
||||
"selectedShapeIds": []
|
||||
}]
|
||||
},
|
||||
"node_data": node_data
|
||||
}
|
||||
|
||||
# Convert the content to JSON string
|
||||
tldraw_json = json.dumps(tldraw_content, indent=4)
|
||||
|
||||
try:
|
||||
# Upload the file to Supabase storage
|
||||
result = admin_supabase.storage.from_(bucket_id).upload(
|
||||
path=file_path,
|
||||
file=tldraw_json,
|
||||
file_options={"content-type": "application/json"}
|
||||
)
|
||||
|
||||
if result.get('error'):
|
||||
logging.error(f"Error creating tldraw file in storage: {result['error']}")
|
||||
raise Exception(f"Failed to create tldraw file: {result['error']}")
|
||||
|
||||
logging.info(f"tldraw file created in storage at {file_path}")
|
||||
return True
|
||||
except Exception as e:
|
||||
logging.error(f"Error creating tldraw file in storage: {str(e)}")
|
||||
raise e
|
||||
return self.create_directory(planned_lesson_path), planned_lesson_path
|
||||
Reference in New Issue
Block a user