errors
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from app.mywhoosh.models import MyWhooshToken
|
||||
@@ -8,6 +9,7 @@ from app.mywhoosh.models import MyWhooshToken
|
||||
class MyWhooshTokenStore:
|
||||
def __init__(self, path: Path) -> None:
|
||||
self.path = path
|
||||
self.device_id_path = path.with_name("device_id")
|
||||
|
||||
def load(self) -> MyWhooshToken | None:
|
||||
try:
|
||||
@@ -40,3 +42,16 @@ class MyWhooshTokenStore:
|
||||
|
||||
def clear(self) -> None:
|
||||
self.path.unlink(missing_ok=True)
|
||||
|
||||
def get_or_create_device_id(self) -> str:
|
||||
try:
|
||||
existing = self.device_id_path.read_text("utf-8").strip()
|
||||
except (FileNotFoundError, OSError):
|
||||
existing = ""
|
||||
if existing:
|
||||
return existing
|
||||
device_id = str(uuid.uuid4())
|
||||
self.device_id_path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
self.device_id_path.write_text(device_id, "utf-8")
|
||||
os.chmod(self.device_id_path, 0o600)
|
||||
return device_id
|
||||
|
||||
Reference in New Issue
Block a user