Use typed entry source instead of raw str to map source to conf in api.py

This commit is contained in:
Debanjum Singh Solanky
2023-11-08 17:57:15 -08:00
parent 8178004e6d
commit c043eb54ae

View File

@@ -50,6 +50,7 @@ from database.models import (
LocalPdfConfig, LocalPdfConfig,
LocalPlaintextConfig, LocalPlaintextConfig,
KhojUser, KhojUser,
Entry as DbEntry,
GithubConfig, GithubConfig,
NotionConfig, NotionConfig,
) )
@@ -60,12 +61,12 @@ api = APIRouter()
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def map_config_to_object(content_source: str): def map_config_to_object(content_source: DbEntry.EntrySource):
if content_source == "github": if content_source == DbEntry.EntrySource.GITHUB:
return GithubConfig return GithubConfig
if content_source == "notion": if content_source == DbEntry.EntrySource.GITHUB:
return NotionConfig return NotionConfig
if content_source == "computer": if content_source == DbEntry.EntrySource.COMPUTER:
return "Computer" return "Computer"