Skip to content

Commit

Permalink
run lints (finally)
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmTomahawkx committed Oct 5, 2023
1 parent 1cc96b9 commit bd306ab
Show file tree
Hide file tree
Showing 17 changed files with 1,414 additions and 1,190 deletions.
4 changes: 2 additions & 2 deletions mystbin/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import ujson
from redis import asyncio as aioredis # fuckin lol
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.applications import Starlette
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import Response

from mystbin_models import MystbinRequest, MystbinState
from routers import admin, doc, apps, pastes, user
from routers import admin, apps, doc, pastes, user
from utils import cli as _cli, ratelimits
from utils.db import Database

Expand Down
12 changes: 9 additions & 3 deletions mystbin/backend/models/payloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
from __future__ import annotations

import datetime
from typing import TypeVar, Type
from msgspec import Struct
from typing import Type, TypeVar

import msgspec
from msgspec import Struct


__all__ = (
Expand All @@ -37,18 +38,22 @@

T = TypeVar("T", bound=Struct)


def create_struct_from_payload(data: str | bytes, struct: Type[T]) -> T:
return msgspec.json.decode(data, type=struct)


class PasteFile(Struct):
content: str
filename: str


class RichPasteFile(Struct):
content: str
filename: str
attachment: str | None = None


class PastePost(Struct):
files: list[PasteFile]
expires: datetime.datetime | None = None
Expand Down Expand Up @@ -82,6 +87,7 @@ class PasteDelete(Struct):
class BookmarkPutDelete(Struct):
paste_id: str


class TokenPost(Struct):
name: str
description: str
description: str
18 changes: 12 additions & 6 deletions mystbin/backend/models/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
along with MystBin. If not, see <https://www.gnu.org/licenses/>.
"""
from datetime import datetime
from typing import TypeVar, Type
from typing import Type, TypeVar

from msgspec import Struct


Expand Down Expand Up @@ -52,6 +53,7 @@ class File(Struct):
charcount: int
attachment: str | None


class PastePostResponse(Struct):
created_at: datetime
files: list[File]
Expand Down Expand Up @@ -84,27 +86,29 @@ class PasteGetAll(Struct):
class PasteGetAllResponse(Struct):
pastes: list[PasteGetAll]


class TokenResponse(Struct):
token: str

_tokenlistitem_renamer = {
"token_name": "name",
"token_description": "description",
"is_main": "is_web_token"
}

_tokenlistitem_renamer = {"token_name": "name", "token_description": "description", "is_main": "is_web_token"}


def _tokenlistitem_rename_fn(name: str) -> str | None:
return _tokenlistitem_renamer.get(name, None)


class TokenListItem(Struct, rename=_tokenlistitem_rename_fn):
id: int
name: str
description: str
is_web_token: bool


class TokenList(Struct):
tokens: list[TokenListItem]


class User(Struct):
id: int
handle: str
Expand All @@ -115,6 +119,7 @@ class User(Struct):
admin: bool
gravatar_hash: str | None


class SmallUser(Struct):
id: int
handle: str
Expand Down Expand Up @@ -147,6 +152,7 @@ class Bookmark(Struct):
class Bookmarks(Struct):
bookmarks: list[Bookmark]


class Style(Struct):
primary_bg: str
secondary_bg: str
Expand Down
8 changes: 6 additions & 2 deletions mystbin/backend/mystbin_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import uuid
from typing import TYPE_CHECKING, TypedDict

import aiohttp
from starlette.datastructures import State
from starlette.requests import Request
from starlette.websockets import WebSocket
from starlette.datastructures import State

from utils.db import Database

Expand Down Expand Up @@ -38,16 +39,19 @@ class MystbinState(State):
db: Database
session: aiohttp.ClientSession


class RequestState(State):
user: _StateUser | None
token_key: uuid.UUID | None
token_id: int | None
user_id: int | None


class MystbinRequest(Request):
app: MystbinApp
state: RequestState


class MystbinWebsocket(WebSocket):
app: MystbinApp
state: RequestState
state: RequestState
Loading

0 comments on commit bd306ab

Please sign in to comment.