File size: 1,140 Bytes
5f685fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from uuid import uuid4
from shortGPT.database.db_document import TINY_MONGO_DATABASE, TinyMongoDocument

from shortGPT.database.content_data_manager import ContentDataManager
class ContentDatabase:
    def __init__(self, ):
        self.content_collection = TINY_MONGO_DATABASE["content_db"]["content_documents"]

    def instanciateContentDataManager(self, id: str, content_type: str, new=False):
        db_doc = TinyMongoDocument("content_db", "content_documents", id)
        return ContentDataManager(db_doc, content_type, new)

    def getContentDataManager(self, id, content_type: str):
        try:
            db_doc = TinyMongoDocument("content_db", "content_documents", id)
            return ContentDataManager(db_doc, content_type, False)
        except:
            return None

    def createContentDataManager(self, content_type: str) -> ContentDataManager:
        try:
            new_short_id = uuid4().hex[:24]
            db_doc = TinyMongoDocument("content_db", "content_documents", new_short_id, True)
            return ContentDataManager(db_doc, content_type, True)
        except:
            return None