Skip to content

Commit

Permalink
Initial commit of API base.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbstractUmbra committed Nov 9, 2020
1 parent bd8b74b commit 0d469de
Show file tree
Hide file tree
Showing 11 changed files with 459 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
.vscode/
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
File renamed without changes.
7 changes: 7 additions & 0 deletions mystbin/rest/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import FastAPI

from routers import pastes

app = FastAPI()

app.include_router(pastes.router)
20 changes: 20 additions & 0 deletions mystbin/rest/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import List, Optional

from pydantic import BaseModel

__all__ = ("PasteCreate", "PasteEdit", "PasteDelete")


class PasteCreate(BaseModel):
content: str
syntax: Optional[str] = None
nick: Optional[str] = None


class PasteEdit(BaseModel):
new_content: str
nick: Optional[str] = None


class PasteDelete(BaseModel):
pastes: List[str]
Empty file.
42 changes: 42 additions & 0 deletions mystbin/rest/routers/pastes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from secrets import token_urlsafe
from typing import Dict

from fastapi import APIRouter

from models import *

__all__ = ("post_paste", "raw_paste", "edit_paste")

router = APIRouter()

@router.post("/paste", tags=["pastes"])
async def post_paste(payload: PasteCreate) -> Dict[str, str]:
""" Post a paste to MystBin. """
return {"pastes": [{"id": token_urlsafe(5), "nick": payload.nick}]}

@router.get("/paste/{paste_id}", tags=["pastes"])
async def raw_paste(paste_id: str) -> Dict[str, str]:
""" Get a raw paste from MystBin. """
return {"id": paste_id, "data": "Umbra sucks!"}

@router.put("/paste/{paste_id}", tags=["pastes"])
@router.patch("/paste/{paste_id}", tags=["pastes"])
async def edit_paste(paste_id: str, payload: PasteEdit) -> Dict[str, str]:
""" Edit a paste on MystBin.
* Requires authentication.
"""
...

@router.delete("/paste/{paste_id}", tags=["pastes"])
async def delete_paste(paste_id: str = None) -> Dict[str, str]:
""" Deletes pastes on MystBin.
* Requires authentication.
"""
return {"paste": paste_id}

@router.delete("/paste", tags=["pastes"])
async def delete_pastes(payload: PasteDelete) -> Dict[str, str]:
""" Deletes pastes on MystBin.
* Requires authentication.
"""
return {"paste": payload}
364 changes: 364 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "mystbin-rewrite"
version = "0.1.0"
description = "A rewrite of Mystbin!"
authors = ["Pythonista Guild <#todo>"]
license = "GPL-3.0"

[tool.poetry.dependencies]
python = "^3.8"
ujson = "^4.0.1"
asyncpg = "^0.21.0"
fastapi = "^0.61.1"

[tool.poetry.dev-dependencies]
pylint = "^2.6.0"
autopep8 = "^1.5.4"
uvicorn = "^0.12.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fastapi==>=0.61.2
ujson==>=4.0.1
asyncpg==>=0.21.0

0 comments on commit 0d469de

Please sign in to comment.