stoof
This commit is contained in:
@@ -41,7 +41,7 @@ class KarmaDB:
|
||||
|
||||
async def get_karma(self, keyword: str) -> int | dict:
|
||||
async with sqlite3.connect(self.db_path, timeout=2) as db_conn:
|
||||
async with db_conn.execute("SELECT score FROM karma WHERE keyword = ? LIMIT 1", (keyword,)) as db_cursor:
|
||||
async with db_conn.execute("SELECT score FROM karma WHERE keyword LIKE ? LIMIT 1", (keyword,)) as db_cursor:
|
||||
try:
|
||||
(score,) = await db_cursor.fetchone()
|
||||
return score
|
||||
@@ -65,7 +65,7 @@ class KarmaDB:
|
||||
return
|
||||
|
||||
modifier = "score + 1" if not flag else "score - 1"
|
||||
query = f"UPDATE karma SET score = {modifier}, last_change = ? WHERE keyword = ?"
|
||||
query = f"UPDATE karma SET score = {modifier}, last_change = ? WHERE keyword LIKE ?"
|
||||
new_keyword_query = "INSERT INTO karma(keyword, score, last_change) VALUES(?, ?, ?)"
|
||||
friendly_flag = "++" if not flag else "--"
|
||||
audit_message = f"{granter} adjusted karma for {keyword} @ {datetime.datetime.now().isoformat()}: {friendly_flag}"
|
||||
@@ -119,7 +119,7 @@ class Karma(FastAPI):
|
||||
"""
|
||||
/karma/top/
|
||||
Get top keywords for karma
|
||||
Requires key
|
||||
(Requires key)
|
||||
"""
|
||||
|
||||
if not self.util.check_key(request.url.path, request.headers.get('X-Authd-With')):
|
||||
@@ -140,13 +140,16 @@ class Karma(FastAPI):
|
||||
'errorText': 'Exception occurred.',
|
||||
}
|
||||
|
||||
async def get_karma_handler(self, data: ValidKarmaRetrievalRequest):
|
||||
async def get_karma_handler(self, data: ValidKarmaRetrievalRequest, request: Request):
|
||||
"""
|
||||
/karma/get/
|
||||
Get current karma value
|
||||
Requires key
|
||||
(Requires key)
|
||||
"""
|
||||
|
||||
if not self.util.check_key(request.url.path, request.headers.get('X-Authd-With')):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
|
||||
keyword = data.keyword
|
||||
try:
|
||||
count = await self.db.get_karma(keyword)
|
||||
@@ -165,7 +168,7 @@ class Karma(FastAPI):
|
||||
"""
|
||||
/karma/update/
|
||||
Update karma count
|
||||
Requires key
|
||||
(Requires key)
|
||||
"""
|
||||
|
||||
if not self.util.check_key(request.url.path, request.headers.get('X-Authd-With'), 2):
|
||||
|
||||
Reference in New Issue
Block a user