feat(studio): add auth-specific paths and integrate auth database location

This commit is contained in:
Shine1i 2026-03-09 20:15:10 +01:00 committed by Manan17
commit f2b2b33769
3 changed files with 16 additions and 3 deletions

View file

@ -7,10 +7,11 @@ SQLite storage for authentication data (user credentials + JWT secret).
import hashlib import hashlib
import sqlite3 import sqlite3
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path
from typing import Optional, Tuple from typing import Optional, Tuple
DB_PATH = Path(__file__).parent / "auth.db" from utils.paths import auth_db_path, ensure_dir
DB_PATH = auth_db_path()
def _hash_token(token: str) -> str: def _hash_token(token: str) -> str:
@ -20,6 +21,7 @@ def _hash_token(token: str) -> str:
def get_connection() -> sqlite3.Connection: def get_connection() -> sqlite3.Connection:
"""Get a connection to the auth database, creating tables if needed.""" """Get a connection to the auth database, creating tables if needed."""
ensure_dir(DB_PATH.parent)
conn = sqlite3.connect(DB_PATH) conn = sqlite3.connect(DB_PATH)
conn.row_factory = sqlite3.Row conn.row_factory = sqlite3.Row
conn.execute( conn.execute(
@ -256,4 +258,3 @@ def revoke_user_refresh_tokens(username: str) -> None:
conn.commit() conn.commit()
finally: finally:
conn.close() conn.close()

View file

@ -13,6 +13,8 @@ from .storage_roots import (
recipe_datasets_root, recipe_datasets_root,
outputs_root, outputs_root,
exports_root, exports_root,
auth_root,
auth_db_path,
tmp_root, tmp_root,
seed_uploads_root, seed_uploads_root,
unstructured_seed_cache_root, unstructured_seed_cache_root,
@ -38,6 +40,8 @@ __all__ = [
'recipe_datasets_root', 'recipe_datasets_root',
'outputs_root', 'outputs_root',
'exports_root', 'exports_root',
'auth_root',
'auth_db_path',
'tmp_root', 'tmp_root',
'seed_uploads_root', 'seed_uploads_root',
'unstructured_seed_cache_root', 'unstructured_seed_cache_root',

View file

@ -32,6 +32,14 @@ def exports_root() -> Path:
return studio_root() / "exports" return studio_root() / "exports"
def auth_root() -> Path:
return studio_root() / "auth"
def auth_db_path() -> Path:
return auth_root() / "auth.db"
def tmp_root() -> Path: def tmp_root() -> Path:
return Path(tempfile.gettempdir()) / "unsloth-studio" return Path(tempfile.gettempdir()) / "unsloth-studio"