Skip to content

Commit

Permalink
remove some unnecessary deps
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Sep 16, 2024
1 parent f1f639d commit 79242d3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 82 deletions.
61 changes: 1 addition & 60 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ sslog = "0.0.0a28"
litestar = { version = "^2.11.0", extras = ['jinja'] }
redis = { extras = ["hiredis"], version = "^5.0.8" }
uvicorn = { version = "^0.30.6" }
pydash = "^8.0.3"
uuid-utils = "^0.9.0"
frozendict = "^2.4.4"
regex = "^2024.9.11"
bgm-tv-wiki = "^0.0.23"

Expand Down
19 changes: 9 additions & 10 deletions server/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import asyncio
import time
from collections.abc import Mapping
from dataclasses import dataclass
from typing import Any
from uuid import UUID

import asyncpg
import httpx
import litestar
from frozendict import frozendict
from litestar.exceptions import ClientException
from litestar.status_codes import HTTP_400_BAD_REQUEST
from redis.asyncio import Redis
Expand Down Expand Up @@ -83,13 +83,12 @@ class BadRequestException(ClientException):
status_code = HTTP_400_BAD_REQUEST


patch_keys: frozendict[str, str] = frozendict(
{
"name": "标题",
"name_cn": "简体中文标题",
"duration": "时长",
"airdate": "放送日期",
"description": "简介",
}
)
patch_keys: Mapping[str, str] = {
"name": "标题",
"name_cn": "简体中文标题",
"duration": "时长",
"airdate": "放送日期",
"description": "简介",
}

disable_cookies_opt = {"skip_session": True, "exclude_from_auth": True, "exclude_from_csrf": True}
3 changes: 2 additions & 1 deletion server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from uuid import UUID

import msgspec
from typing_extensions import Self


class PatchState(enum.IntEnum):
Expand All @@ -29,7 +30,7 @@ class PatchBase(msgspec.Struct, kw_only=True, frozen=True):
patch_desc: str # extra description from user will not be included in commit message

@classmethod
def from_dict(cls: type[T], d: Any) -> T:
def from_dict(cls, d: Any) -> Self:
# will remove extra fields and do field level instance checking
return msgspec.convert(d, cls)

Expand Down
21 changes: 12 additions & 9 deletions server/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from uuid import UUID

import litestar
import pydash
import msgspec.structs
from asyncpg import Record
from litestar import Controller, Response
from litestar.enums import RequestEncodingType
Expand Down Expand Up @@ -78,6 +78,8 @@ async def review_patch(

patch = SubjectPatch.from_dict(p)

msgspec.structs.replace(patch)

if patch.state != PatchState.Pending:
raise BadRequestException("patch already reviewed")

Expand Down Expand Up @@ -146,14 +148,15 @@ async def __accept_patch(
headers={"Authorization": f"Bearer {request.auth.access_token}"},
json={
"commitMessage": f"{patch.reason} [patch https://patch.bgm38.tv/subject/{patch.id}]",
"expectedRevision": pydash.pick(
{
"infobox": patch.original_infobox,
"name": patch.original_name,
"summary": patch.original_summary,
},
*subject.keys(),
),
"expectedRevision": {
key: value
for key, value in [
("infobox", patch.original_infobox),
("name", patch.original_name),
("summary", patch.original_summary),
]
if key in subject
},
"subject": subject,
},
)
Expand Down

0 comments on commit 79242d3

Please sign in to comment.