-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GET /moodle/files endpoint, MinioRepository
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import List, Dict | ||
from minio import Minio | ||
from minio.error import S3Error | ||
from src.api.logging_ import logger | ||
from src.storages.minio import minio_client as client | ||
|
||
|
||
class MinioRepository: | ||
def __init__(self, minio_client: Minio): | ||
self.minio_client = minio_client | ||
|
||
def get_moodle_objects(self) -> List[Dict[str, any]]: | ||
try: | ||
# List all objects with the "moodle/" prefix | ||
objects = self.minio_client.list_objects(bucket_name="search", prefix="moodle/") | ||
moodle_objects = [] | ||
for obj in objects: | ||
# would it work like this? | ||
parts = obj.object_name.split("/") | ||
if len(parts) >= 3: | ||
course_id = int(parts[1]) | ||
module_id = int(parts[2]) | ||
filename = parts[-1] | ||
moodle_object = { | ||
"course_id": course_id, | ||
"module_id": module_id, | ||
"filename": filename, | ||
"minio_data": obj, | ||
} | ||
moodle_objects.append(moodle_object) | ||
return moodle_objects | ||
except S3Error as e: | ||
logger.error(f"An error occurred while listing Moodle objects: {e}") | ||
return [] | ||
|
||
|
||
minio_repository: MinioRepository = MinioRepository(client) |