2023-12-20 18:13:55 -05:00
|
|
|
"""This is a list of all the models used in PyZipline. They are used to represent the data returned from the Zipline API."""
|
2023-12-21 14:08:55 -05:00
|
|
|
from typing import List, Dict, Optional
|
2023-12-19 05:36:18 -05:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
class File:
|
2023-12-20 18:13:55 -05:00
|
|
|
"""File object used for uploading files to Zipline
|
|
|
|
|
2023-12-20 21:37:02 -05:00
|
|
|
Attributes:
|
2023-12-21 15:34:04 -05:00
|
|
|
created_at (datetime.datetime): Datetime object of when the file was created
|
2023-12-20 18:13:55 -05:00
|
|
|
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
|
2023-12-21 15:34:04 -05:00
|
|
|
original_name (Optional[str]): String of the file's original name
|
2023-12-21 14:08:55 -05:00
|
|
|
url (Optional[str]): String of the file's URL
|
2023-12-21 15:34:04 -05:00
|
|
|
max_views (Optional[int]): Integer of the file's maximum number of views
|
|
|
|
expired_at (Optional[datetime]): Datetime object of when the file will expire
|
2023-12-21 14:08:55 -05:00
|
|
|
thumbnail (Optional[str]): String of the file's thumbnail URL
|
2023-12-21 15:34:04 -05:00
|
|
|
folder_id (Optional[int]): Integer of the file's folder ID
|
2023-12-20 18:13:55 -05:00
|
|
|
"""
|
2023-12-19 05:36:18 -05:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
createdAt: datetime,
|
2023-12-20 23:50:03 -05:00
|
|
|
id: int, # pylint: disable=redefined-builtin
|
2023-12-19 05:36:18 -05:00
|
|
|
mimetype: str,
|
|
|
|
views: int,
|
|
|
|
name: str,
|
|
|
|
size: int,
|
|
|
|
favorite: bool,
|
|
|
|
originalName: str = None,
|
|
|
|
url: str = None,
|
|
|
|
maxViews: int = None,
|
2023-12-21 14:08:55 -05:00
|
|
|
expiredAt: datetime = None,
|
2023-12-19 05:36:18 -05:00
|
|
|
thumbnail: str = None,
|
|
|
|
folderId: int = None,
|
|
|
|
**kwargs
|
|
|
|
):
|
2023-12-21 15:34:04 -05:00
|
|
|
self.created_at = createdAt
|
2023-12-19 05:36:18 -05:00
|
|
|
self.id = id
|
|
|
|
self.mimetype = mimetype
|
|
|
|
self.views = views
|
|
|
|
self.name = name
|
|
|
|
self.size = size
|
|
|
|
self.favorite = favorite
|
2023-12-21 15:34:04 -05:00
|
|
|
self.original_name = originalName
|
2023-12-19 05:36:18 -05:00
|
|
|
self.url = url
|
2023-12-21 15:34:04 -05:00
|
|
|
self.max_views = maxViews
|
|
|
|
self.expired_at = expiredAt
|
2023-12-19 05:36:18 -05:00
|
|
|
self.thumbnail = thumbnail
|
2023-12-21 15:34:04 -05:00
|
|
|
self.folder_id = folderId
|
2023-12-19 05:36:18 -05:00
|
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
2023-12-21 14:08:55 -05:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2023-12-19 05:36:18 -05:00
|
|
|
|
|
|
|
class Result:
|
2023-12-20 18:13:55 -05:00
|
|
|
"""Result returned from low-level RestAdapter
|
|
|
|
|
2023-12-20 21:37:02 -05:00
|
|
|
Attributes:
|
2023-12-20 18:13:55 -05:00
|
|
|
success (bool): Boolean of whether the request was successful
|
|
|
|
status_code (int): Standard HTTP Status code
|
|
|
|
message (str = ''): Human readable result
|
2023-12-21 14:08:55 -05:00
|
|
|
data (Union[List[Dict], Dict]): Python List of Dictionaries (or maybe just a single Dictionary on error)
|
2023-12-20 18:13:55 -05:00
|
|
|
"""
|
2023-12-20 17:53:00 -05:00
|
|
|
def __init__(self, success: bool, status_code: int, message: str = '', data: List[Dict] = None):
|
|
|
|
self.success = success
|
|
|
|
self.status_code = status_code
|
|
|
|
self.message = message
|
2023-12-21 14:08:55 -05:00
|
|
|
self.data = data if data else {}
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.status_code}: {self.message}\n{self.data}"
|
2023-12-19 05:36:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Invite:
|
2023-12-20 18:13:55 -05:00
|
|
|
"""Invite object used for managing invites
|
|
|
|
|
2023-12-20 21:37:02 -05:00
|
|
|
Attributes:
|
2023-12-20 18:13:55 -05:00
|
|
|
id (int): Integer ID of the invite
|
|
|
|
code (str): String of the invite's code
|
2023-12-21 15:34:04 -05:00
|
|
|
created_at (datetime): Datetime object of when the invite was created
|
|
|
|
expired_at (datetime): Datetime object of when the invite will expire
|
2023-12-20 18:13:55 -05:00
|
|
|
used (bool): Boolean of whether the invite has been used
|
2023-12-21 15:34:04 -05:00
|
|
|
created_by_id (int): Integer ID of the user who created the invite
|
2023-12-20 18:13:55 -05:00
|
|
|
"""
|
2023-12-19 05:36:18 -05:00
|
|
|
def __init__(
|
|
|
|
self,
|
2023-12-20 23:50:03 -05:00
|
|
|
id: int, # pylint: disable=redefined-builtin
|
2023-12-19 05:36:18 -05:00
|
|
|
code: str,
|
|
|
|
createdAt: datetime,
|
|
|
|
expiredAt: datetime,
|
|
|
|
used: bool,
|
|
|
|
createdById: int,
|
|
|
|
**kwargs
|
|
|
|
):
|
|
|
|
self.id = id
|
|
|
|
self.code = code
|
2023-12-21 15:34:04 -05:00
|
|
|
self.created_at = createdAt
|
|
|
|
self.expired_at = expiredAt
|
2023-12-19 05:36:18 -05:00
|
|
|
self.used = used
|
2023-12-21 15:34:04 -05:00
|
|
|
self.created_by_id = createdById
|
2023-12-19 05:36:18 -05:00
|
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
2023-12-21 14:08:55 -05:00
|
|
|
def __str__(self):
|
|
|
|
return self.code
|
|
|
|
|
|
|
|
class Stats:
|
|
|
|
"""Stats object used for retrieving stats
|
|
|
|
|
|
|
|
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
|
|
|
|
"""
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
id: int, # pylint: disable=redefined-builtin
|
|
|
|
createdAt: datetime,
|
|
|
|
data: dict,
|
|
|
|
max_timestamp: Optional[datetime] = None
|
|
|
|
):
|
|
|
|
self.id = id
|
|
|
|
self.createdAt = createdAt
|
|
|
|
self._data = data
|
|
|
|
self.max_timestamp = max_timestamp
|
|
|
|
self.size = self._data['size']
|
|
|
|
self.size_num = self._data['size_num']
|
|
|
|
self.count = self._data['count']
|
|
|
|
self.count_users = self._data['count_users']
|
|
|
|
self.views_count = self._data['views_count']
|
|
|
|
self.types_count: list = self._data['types_count']
|
|
|
|
self.count_by_user: list = self._data['count_by_user']
|
|
|
|
if self.types_count is not None:
|
|
|
|
new_types_count = []
|
|
|
|
for mimetype_entry in self.types_count:
|
|
|
|
if isinstance(mimetype_entry, dict):
|
|
|
|
m = self.Mimetype(**mimetype_entry)
|
|
|
|
new_types_count.append(m)
|
|
|
|
self.types_count = new_types_count
|
|
|
|
if self.count_by_user is not None:
|
|
|
|
new_count_by_user = []
|
|
|
|
for count_by_user_entry in self.count_by_user:
|
|
|
|
if isinstance(count_by_user_entry, dict):
|
|
|
|
c = self.CountByUser(**count_by_user_entry)
|
|
|
|
new_count_by_user.append(c)
|
|
|
|
self.count_by_user = new_count_by_user
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.id)
|
|
|
|
|
|
|
|
class Mimetype:
|
|
|
|
"""Object used in [Stats](.#pyzipline.models.Stats) 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"""
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
mimetype: str,
|
|
|
|
count: int
|
|
|
|
):
|
|
|
|
self.mimetype = mimetype
|
|
|
|
self.count = count
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.mimetype}: {self.count}"
|
|
|
|
|
|
|
|
class CountByUser:
|
|
|
|
"""Object used in [Stats](.#pyzipline.models.Stats) 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"""
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
username: str,
|
|
|
|
count: int
|
|
|
|
):
|
|
|
|
self.username = username
|
|
|
|
self.count = count
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.username}: {self.count}"
|
2023-12-19 05:36:18 -05:00
|
|
|
|
|
|
|
class OAuth:
|
2023-12-20 18:13:55 -05:00
|
|
|
"""OAuth object used for managing OAuth
|
|
|
|
|
2023-12-20 21:37:02 -05:00
|
|
|
Attributes:
|
2023-12-20 18:13:55 -05:00
|
|
|
id (int): Integer ID of the OAuth
|
|
|
|
provider (str): String of the OAuth's provider, one of 'DISCORD', 'GITHUB', 'GOOGLE'
|
2023-12-21 15:34:04 -05:00
|
|
|
user_id (int): Integer ID of the user who owns the OAuth
|
|
|
|
oauth_id (str): String of the OAuth's provider ID
|
2023-12-20 18:13:55 -05:00
|
|
|
username (str): String of the OAuth's connected account's username
|
|
|
|
token (str): String of the OAuth's access token
|
2023-12-20 21:37:02 -05:00
|
|
|
refresh (Optional[str]): String of the OAuth's refresh token
|
2023-12-20 18:13:55 -05:00
|
|
|
"""
|
2023-12-19 05:36:18 -05:00
|
|
|
def __init__(
|
|
|
|
self,
|
2023-12-20 23:50:03 -05:00
|
|
|
id: int, # pylint: disable=redefined-builtin
|
2023-12-19 05:36:18 -05:00
|
|
|
provider: str,
|
2023-12-21 14:08:55 -05:00
|
|
|
oauthId: int,
|
2023-12-19 05:36:18 -05:00
|
|
|
providerId: str,
|
|
|
|
username: str,
|
|
|
|
token: str,
|
2023-12-20 21:37:02 -05:00
|
|
|
refresh: Optional[str],
|
2023-12-19 05:36:18 -05:00
|
|
|
**kwargs
|
|
|
|
):
|
|
|
|
self.id = id
|
|
|
|
self.provider = provider
|
2023-12-21 15:34:04 -05:00
|
|
|
self.oauth_id = oauthId
|
|
|
|
self.provider_id = providerId
|
2023-12-19 05:36:18 -05:00
|
|
|
self.username = username
|
|
|
|
self.token = token
|
|
|
|
self.refresh = refresh
|
|
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
2023-12-21 14:08:55 -05:00
|
|
|
def __str__(self):
|
|
|
|
return self.provider
|
|
|
|
|
2023-12-19 05:36:18 -05:00
|
|
|
|
|
|
|
class User:
|
2023-12-21 15:34:04 -05:00
|
|
|
"""Object containing user information
|
|
|
|
|
|
|
|
/// admonition | Contains Sensitive Information
|
|
|
|
type: danger
|
|
|
|
Please be mindful of how you use/store this object, as it contains sensitive information such as the user's token and OAuth/TOTP information.
|
|
|
|
///
|
2023-12-20 18:13:55 -05:00
|
|
|
|
2023-12-20 21:37:02 -05:00
|
|
|
Attributes:
|
2023-12-20 18:13:55 -05:00
|
|
|
id (int): Integer ID of the user
|
|
|
|
uuid (str): String of the user's UUID
|
|
|
|
username (str): String of the user's username
|
2023-12-20 21:37:02 -05:00
|
|
|
avatar (Optional[str]): String of the user's avatar, base64 encoded
|
2023-12-20 18:13:55 -05:00
|
|
|
token (str): String of the user's token
|
|
|
|
administrator (bool): Boolean of whether the user is an administrator
|
2023-12-21 15:34:04 -05:00
|
|
|
super_admin (bool): Boolean of whether the user is a super administrator
|
|
|
|
system_theme (str): String of the user's system theme
|
2023-12-20 18:13:55 -05:00
|
|
|
embed (Embed): Embed object of the user's embed
|
2023-12-21 15:34:04 -05:00
|
|
|
totp_secret (Optional[str]): String of the user's TOTP secret
|
2023-12-20 18:13:55 -05:00
|
|
|
domains (List[str]): List of Strings of the user's domains
|
2023-12-21 14:08:55 -05:00
|
|
|
oauth (Optional[List[OAuth]]): List of [OAuth](.#pyzipline.models.OAuth) objects
|
|
|
|
ratelimit (Optional[datetime]): Datetime object of when the user's ratelimit expires
|
2023-12-20 18:13:55 -05:00
|
|
|
"""
|
2023-12-19 05:36:18 -05:00
|
|
|
def __init__(
|
|
|
|
self,
|
2023-12-20 23:50:03 -05:00
|
|
|
id: int, # pylint: disable=redefined-builtin
|
2023-12-19 05:36:18 -05:00
|
|
|
uuid: str,
|
|
|
|
username: str,
|
2023-12-20 21:37:02 -05:00
|
|
|
avatar: Optional[str],
|
2023-12-19 05:36:18 -05:00
|
|
|
token: str,
|
|
|
|
administrator: bool,
|
|
|
|
superAdmin: bool,
|
|
|
|
systemTheme: str,
|
2023-12-21 14:08:55 -05:00
|
|
|
embed: 'Embed',
|
2023-12-20 21:37:02 -05:00
|
|
|
totpSecret: Optional[str],
|
2023-12-19 05:36:18 -05:00
|
|
|
domains: List[str],
|
2023-12-21 08:49:31 -05:00
|
|
|
oauth: Optional[List['OAuth']] = None,
|
2023-12-20 21:37:02 -05:00
|
|
|
ratelimit: Optional[datetime] = None,
|
2023-12-19 05:36:18 -05:00
|
|
|
**kwargs
|
|
|
|
):
|
|
|
|
self.id = id
|
|
|
|
self.uuid = uuid
|
|
|
|
self.username = username
|
|
|
|
self.avatar = avatar
|
|
|
|
self.token = token
|
|
|
|
self.administrator = administrator
|
2023-12-21 15:34:04 -05:00
|
|
|
self.super_admin = superAdmin
|
|
|
|
self.system_theme = systemTheme
|
2023-12-21 14:08:55 -05:00
|
|
|
self.embed = self.Embed(**embed)
|
2023-12-21 15:34:04 -05:00
|
|
|
self.totp_secret = totpSecret
|
2023-12-19 05:36:18 -05:00
|
|
|
self.domains = domains
|
|
|
|
self.oauth = oauth
|
|
|
|
self.ratelimit = ratelimit
|
|
|
|
self.__dict__.update(kwargs)
|
2023-12-21 08:49:31 -05:00
|
|
|
if self.oauth is not None:
|
|
|
|
for oauth_entry in self.oauth:
|
|
|
|
self.oauth.remove(oauth_entry)
|
|
|
|
o = OAuth(**oauth_entry)
|
|
|
|
self.oauth.append(o)
|
2023-12-21 14:08:55 -05:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.username
|
|
|
|
|
|
|
|
class Embed:
|
2023-12-21 15:34:04 -05:00
|
|
|
"""Object containing a user's embed settings
|
2023-12-21 14:08:55 -05:00
|
|
|
|
|
|
|
Attributes:
|
|
|
|
color (Optional[str]): String of the embed's color
|
|
|
|
title (Optional[str]): String of the embed's title
|
2023-12-21 15:34:04 -05:00
|
|
|
site_name (Optional[str]): String of the embed's site name
|
2023-12-21 14:08:55 -05:00
|
|
|
description (Optional[str]): String of the embed's description
|
|
|
|
"""
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
color: str,
|
|
|
|
title: str,
|
|
|
|
siteName: str,
|
|
|
|
description: str,
|
|
|
|
**kwargs
|
|
|
|
):
|
|
|
|
self.color = color
|
|
|
|
self.title = title
|
2023-12-21 15:34:04 -05:00
|
|
|
self.site_name = siteName
|
2023-12-21 14:08:55 -05:00
|
|
|
self.description = description
|
|
|
|
self.__dict__.update(kwargs)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.title is None:
|
|
|
|
return "None"
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Version:
|
2023-12-21 15:34:04 -05:00
|
|
|
"""Object containing the current, stable, and upstream versions of Zipline
|
2023-12-21 14:08:55 -05:00
|
|
|
|
|
|
|
Attributes:
|
2023-12-21 15:34:04 -05:00
|
|
|
is_upstream (bool): Boolean of whether the current version is upstream (`trunk` branch)
|
|
|
|
update_to_type (str): String of the type of update available, one of 'stable' or 'upstream'
|
2023-12-21 14:08:55 -05:00
|
|
|
stable (str): String of the stable version
|
|
|
|
upstream (str): String of the upstream version
|
|
|
|
current (str): String of the current version
|
|
|
|
"""
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
isUpstream: bool,
|
|
|
|
updateToType: str,
|
|
|
|
versions: {dict}
|
|
|
|
):
|
2023-12-21 15:34:04 -05:00
|
|
|
self.is_upstream = isUpstream
|
|
|
|
self.update_to_type = updateToType
|
2023-12-21 14:08:55 -05:00
|
|
|
self._versions = versions
|
|
|
|
self.stable = self._versions['stable']
|
|
|
|
self.upstream = self._versions['upstream']
|
|
|
|
self.current = self._versions['upstream']
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.current
|