Remove aiofiles

This commit is contained in:
2024-11-17 01:34:38 +01:00
parent fc28e2c5ea
commit e54dd7e8e0
3 changed files with 2 additions and 36 deletions

View File

@@ -1,9 +1,3 @@
from asyncio import Lock
import json
import aiofiles
from core.config import config
from core.mongo import mongo_manager
@@ -11,16 +5,10 @@ class TokenStorage:
COLLECTION_NAME = "secrets"
OBJECT_ID = "twitch_tokens"
lock = Lock()
@staticmethod
async def save(acceess_token: str, refresh_token: str):
data = {"access_token": acceess_token, "refresh_token": refresh_token}
async with TokenStorage.lock:
async with aiofiles.open(config.SECRETS_FILE_PATH, "w") as f:
await f.write(json.dumps(data))
async with mongo_manager.connect() as client:
db = client.get_default_database()
collection = db[TokenStorage.COLLECTION_NAME]
@@ -38,15 +26,5 @@ class TokenStorage:
collection = db[TokenStorage.COLLECTION_NAME]
data = await collection.find_one({"_id": TokenStorage.OBJECT_ID})
if data is not None:
return data["access_token"], data["refresh_token"]
async with TokenStorage.lock:
async with aiofiles.open(config.SECRETS_FILE_PATH, "r") as f:
data_str = await f.read()
data = json.loads(data_str)
await TokenStorage.save(data["access_token"], data["refresh_token"])
return data["access_token"], data["refresh_token"]
return data["access_token"], data["refresh_token"]