🔀 Added delete tab expiry
This commit is contained in:
parent
4f12f6ae6d
commit
0c886205fe
|
@ -55,6 +55,7 @@ async def grant_tab(request: RequestSchema):
|
||||||
|
|
||||||
|
|
||||||
async def get_profile(schema: RequestSchema) -> UserSchema:
|
async def get_profile(schema: RequestSchema) -> UserSchema:
|
||||||
|
await database.delete_expired_tab_users()
|
||||||
uuid = await database.get_uuid_by_username(schema)
|
uuid = await database.get_uuid_by_username(schema)
|
||||||
if not uuid:
|
if not uuid:
|
||||||
raise HTTPException(status_code=404, detail="User not found")
|
raise HTTPException(status_code=404, detail="User not found")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select, delete
|
||||||
from sqlalchemy.ext.asyncio import create_async_engine
|
from sqlalchemy.ext.asyncio import create_async_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
from db import LuckpermsPlayer, LitebansBan, LuckpermsUserPermission, TabUser
|
from db import LuckpermsPlayer, LitebansBan, LuckpermsUserPermission, TabUser
|
||||||
|
@ -6,7 +6,7 @@ from db.schemas import MySQLConfig, UserSchema, RequestSchema, TabSchema
|
||||||
from sqlalchemy.ext.asyncio import AsyncSession
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
from aiocache import cached, SimpleMemoryCache
|
from aiocache import cached, SimpleMemoryCache
|
||||||
from aiocache.serializers import PickleSerializer
|
from aiocache.serializers import PickleSerializer
|
||||||
|
import datetime
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
def __init__(self, uri: MySQLConfig):
|
def __init__(self, uri: MySQLConfig):
|
||||||
|
@ -91,4 +91,15 @@ class Database:
|
||||||
if not ban.scalar():
|
if not ban.scalar():
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def delete_expired_tab_users(self):
|
||||||
|
async with self.AsyncSessionLocal() as session:
|
||||||
|
async with session.begin():
|
||||||
|
current_timestamp = int((datetime.datetime.utcnow()).timestamp())
|
||||||
|
await session.execute(
|
||||||
|
delete(TabUser)
|
||||||
|
.where(TabUser.expiry < current_timestamp)
|
||||||
|
.where(TabUser.expiry != 0)
|
||||||
|
)
|
||||||
|
await session.commit()
|
|
@ -1,4 +1,4 @@
|
||||||
from pydantic import BaseModel, PositiveInt, computed_field, field_validator
|
from pydantic import BaseModel, computed_field, field_validator, NonNegativeInt
|
||||||
from .TabSchema import TabSchema
|
from .TabSchema import TabSchema
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
@ -6,7 +6,7 @@ import re
|
||||||
|
|
||||||
class RequestSchema(BaseModel):
|
class RequestSchema(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
expiry: PositiveInt = 1
|
expiry: NonNegativeInt = 1
|
||||||
tab: TabSchema = TabSchema()
|
tab: TabSchema = TabSchema()
|
||||||
|
|
||||||
@field_validator('username')
|
@field_validator('username')
|
||||||
|
@ -15,7 +15,7 @@ class RequestSchema(BaseModel):
|
||||||
raise ValueError("Invalid username format")
|
raise ValueError("Invalid username format")
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@computed_field(return_type=PositiveInt)
|
@computed_field(return_type=NonNegativeInt)
|
||||||
def validated_expiry(self):
|
def validated_expiry(self):
|
||||||
if self.expiry > 10**5:
|
if self.expiry > 10**5:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue