Skip to content

Commit fbfc4b7

Browse files
feat(root): render readme
Signed-off-by: John Andersen <johnandersen777@protonmail.com>
1 parent 141953b commit fbfc4b7

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
# ATProto based pastebin
22

3+
Paste
4+
5+
```bash
6+
curl -X POST --data-binary @README.md -H "Content-Type: text/plain" https://paste.chadig.com
7+
```
8+
9+
Retrive using id from paste reponse JSON (`| jq -r .id`)
10+
11+
```bash
12+
curl -sf https://paste.chadig.com/$id
13+
```
14+
315
Paste and retrive
416

17+
```bash
18+
curl -sf https://paste.chadig.com/$(curl -X POST --data-binary @README.md -H "Content-Type: text/plain" https://paste.chadig.com | tee /dev/stderr | jq -r .id)
19+
```
20+
21+
Paste and retrive (development)
22+
523
```bash
624
curl -sf http://localhost:8000/$(curl -X POST --data-binary @src/atprotobin/cli.py -H "Content-Type: text/plain" http://localhost:8000/ | tee /dev/stderr | jq -r .id)
725
```
826

927
Start server
1028

1129
```bash
30+
python -m pip install -U pip setuptools wheel
31+
python -m pip install -e .
1232
ATPROTO_BASE_URL=https://atproto.chadig.com ATPROTO_HANDLE=publicdomainrelay.atproto.chadig.com ATPROTO_PASSWORD=$(python -m keyring get publicdomainrelay@protonmail.com password.publicdomainrelay.atproto.chadig.com) python -m atprotobin
1333
```
1434

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "atprotobin"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "ATProto based pastebin"
55
readme = {file = "README.md", content-type = "text/markdown"}
66
authors = [
@@ -15,6 +15,8 @@ dependencies = [
1515
"pillow>=11.0.0",
1616
"python-magic>=0.4.27",
1717
"python-multipart>=0.0.19",
18+
"pygments>=2.18.0",
19+
"markdown2>=2.5.1",
1820
]
1921

2022
[project.urls]

src/atprotobin/server.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import os
22
import hashlib
3+
import pathlib
4+
import textwrap
35
import contextlib
46
from typing import Annotated
57

8+
import markdown2
69
from atproto import AsyncClient, models
710
from fastapi import FastAPI, File, UploadFile, Request, Response
11+
from fastapi.responses import HTMLResponse
812

913
from .zip_image import encode, decode
1014

@@ -16,12 +20,37 @@
1620
atproto_password= os.environ["ATPROTO_PASSWORD"]
1721

1822
did_plcs = {}
23+
markdown_html_content_by_file = {}
1924
client = AsyncClient(
2025
base_url=atproto_base_url,
2126
)
2227

2328
@contextlib.asynccontextmanager
2429
async def lifespan(app: FastAPI):
30+
markdown_content = pathlib.Path(
31+
__file__
32+
).parents[2].joinpath(
33+
"README.md",
34+
).read_text()
35+
readme_markdown_html = markdown2.markdown(
36+
markdown_content,
37+
extras=[
38+
"fenced-code-blocks",
39+
"code-friendly",
40+
"highlightjs-lang",
41+
],
42+
)
43+
markdown_html_content_by_file["README.md"] = textwrap.dedent(
44+
f"""
45+
<html>
46+
<title>{markdown_content.split("\n")[0].replace("# ", "")}</title>
47+
<body>
48+
{readme_markdown_html}
49+
</body>
50+
</html>
51+
""".strip()
52+
)
53+
2554
profile = await client.login(
2655
atproto_handle,
2756
atproto_password,
@@ -62,3 +91,7 @@ async def get(post_id: str):
6291
)
6392
mimetype, output_bytes = decode(blob)
6493
return Response(content=output_bytes, media_type=mimetype)
94+
95+
@app.get("/", response_class=HTMLResponse)
96+
async def root():
97+
return markdown_html_content_by_file["README.md"]

0 commit comments

Comments
 (0)