feat(user-preference): add user preference support (#55)
APIs: - GET `/api/private/user/preferences`: Get current user's preferences. - PATCH `/api/private/user/preferences`: Modify current user's preferences. (body: Preferences) - PUT `/api/private/user/preferences`: Overwrite current user's preferences. (body: Preferences) - DELETE `/api/private/user/preferences`: Reset current user's preferences. (body: list[str]) - body specifies the content to be reset. If body is empty, reset all preferences. User: - `User.g0v0_playmode`: show the special ruleset like `OSURX`, and custom rulesets in the future. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
27
app/utils.py
27
app/utils.py
@@ -272,3 +272,30 @@ bg_tasks = BackgroundTasks()
|
||||
|
||||
def utcnow() -> datetime:
|
||||
return datetime.now(tz=UTC)
|
||||
|
||||
|
||||
def hex_to_hue(hex_color: str) -> int:
|
||||
"""Convert a hex color string to a hue value (0-360)."""
|
||||
hex_color = hex_color.lstrip("#")
|
||||
if len(hex_color) != 6:
|
||||
raise ValueError("Invalid hex color format. Expected format: RRGGBB")
|
||||
|
||||
r = int(hex_color[0:2], 16) / 255.0
|
||||
g = int(hex_color[2:4], 16) / 255.0
|
||||
b = int(hex_color[4:6], 16) / 255.0
|
||||
|
||||
max_c = max(r, g, b)
|
||||
min_c = min(r, g, b)
|
||||
delta = max_c - min_c
|
||||
|
||||
if delta == 0:
|
||||
return 0 # Achromatic (grey)
|
||||
|
||||
if max_c == r:
|
||||
hue = (60 * ((g - b) / delta) + 360) % 360
|
||||
elif max_c == g:
|
||||
hue = (60 * ((b - r) / delta) + 120) % 360
|
||||
else: # max_c == b
|
||||
hue = (60 * ((r - g) / delta) + 240) % 360
|
||||
|
||||
return int(hue)
|
||||
|
||||
Reference in New Issue
Block a user