PyZipline/pyzipline/models.py
SeaswimmerTheFsh c6b723a476
Some checks failed
Actions / Build Documentation (MkDocs) (push) Failing after 14s
Actions / Lint Code (Ruff & Pylint) (push) Failing after 22s
feat(models): converted to pydantic for all data models
2024-03-28 11:15:27 -04:00

184 lines
5.5 KiB
Python

"""This is a list of all the models used in PyZipline. They are used to represent the data returned from the Zipline API."""
from datetime import datetime
from typing import Dict, List, Optional, Union
from pydantic import BaseModel, Field
class File(BaseModel):
"""File object used for uploading files to Zipline
Attributes:
createdAt (datetime.datetime): Datetime object of when the file was created
id (int): ID of the file
mimetype (str): String of the file's mimetype
views (int): Integer of the number of views the file has
name (str): String of the file's name
size (int): Integer of the file's size in bytes
favorite (bool): Boolean of whether the file is favorited
originalName (Optional[str]): String of the file's original name
url (Optional[str]): String of the file's URL
maxViews (Optional[int]): Integer of the file's maximum number of views
expiredAt (Optional[datetime]): Datetime object of when the file will expire
thumbnail (Optional[str]): String of the file's thumbnail URL
folderId (Optional[int]): Integer of the file's folder ID
"""
createdAt: datetime
id: int
mimetype: str
views: int
name: str
size: int
favorite: bool
originalName: Optional[str] = None
url: Optional[str] = None
maxViews: Optional[int] = None
expiredAt: Optional[datetime] = None
thumbnail: Optional[str] = None
folderId: Optional[int] = None
def __str__(self):
return self.name
class Invite(BaseModel):
"""Invite object used for managing invites
Attributes:
id (int): Integer ID of the invite
code (str): String of the invite's code
createdAt (datetime): Datetime object of when the invite was created
expiresAt (datetime): Datetime object of when the invite will expire
used (bool): Boolean of whether the invite has been used
createdById (int): Integer ID of the user who created the invite
"""
id: int
code: str
createdAt: datetime
expiresAt: datetime
used: bool
createdById: int
def __str__(self):
return self.code
class Result(BaseModel):
"""Result returned from low-level RestAdapter
Attributes:
success (bool): Boolean of whether the request was successful
status_code (int): Standard HTTP Status code
message (str = ''): Human readable result
data (Union[List[Dict], Dict]): Python List of Dictionaries (or maybe just a single Dictionary on error)
"""
success: bool
status_code: int
message: str = ''
data: Union[List[Dict], Dict] = {}
def __str__(self):
return f"{self.status_code}: {self.message}"
class TypesCountItem(BaseModel):
"""Model used in [StatsData](.#pyzipline.models.StatsData) for storing the number of files with a specific mimetype
Attributes:
mimetype (str): String of the mimetype
count (int): Integer of the number of files with this mimetype
"""
count: int
mimetype: str
def __str__(self):
return f"{self.mimetype}: {self.count}"
class CountByUserItem(BaseModel):
"""Model used in [StatsData](.#pyzipline.models.StatsData) for storing the number of files uploaded by a user
Attributes:
username (str): String of the username
count (int): Integer of the number of files uploaded by this user
"""
count: int
username: str
def __str__(self):
return f"{self.username}: {self.count}"
class StatsData(BaseModel):
"""Stats data model
Attributes:
id (int): Integer ID of the stats
createdAt (datetime): Datetime object of when the stats were created
max_timestamp (Optional[datetime]): Datetime object of the maximum timestamp of the stats
size (str): String of the size of the files
size_num (int): Integer of the size of the files in bytes
count (int): Integer of the number of files
count_users (int): Integer of the number of users
views_count (int): Integer of the number of views
types_count (Optional[List[Mimetype]]): List of Mimetype objects
count_by_user (Optional[List[CountByUser]]): List of CountByUser objects
"""
size: str
count: int
size_num: int
count_users: int
types_count: List[TypesCountItem]
views_count: int
count_by_user: List[CountByUserItem]
class Stats(BaseModel):
"""Stats model
Attributes:
id (int): Integer ID of the stats
createdAt (datetime): Datetime object of when the stats were created
data (StatsData): StatsData object of the stats data
max_timestamp (Optional[datetime]): Datetime object of the maximum timestamp of the stats
"""
id: int
createdAt: datetime
data: StatsData
max_timestamp: str = Field(default=None)
class Embed(BaseModel):
color: Optional[str] = None
title: Optional[str] = None
siteName: Optional[str] = None
description: Optional[str] = None
class User(BaseModel):
id: int
uuid: str
username: str
avatar: Optional[str]
token: str
administrator: bool
superAdmin: bool
systemTheme: str
embed: Embed
ratelimit: None
totpSecret: Optional[str]
domains: List[str]
def __str__(self):
return self.username
class Versions(BaseModel):
stable: str
upstream: str
current: str
class Version(BaseModel):
isUpstream: bool
updateToType: str
versions: Versions
def __str__(self):
return self.versions.current