features
This commit is contained in:
1 parent
d4fc121506
commit
57a73e9c17
3 files changed
+120
-2
No files matched your search
+20
-1
@@ -34,7 +34,26 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-block: 1em">
|
||||
<h2>Scan this page</h2>
|
||||
<p>Connect your phone to the same Wi-Fi and scan this.</p>
|
||||
<div
|
||||
class="qrcode"
|
||||
style="padding: 1rem; background: white; border-radius: 8px"
|
||||
id="page_url"
|
||||
></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/qrcode.js"></script>
|
||||
<script>
|
||||
new QRCode(document.getElementById("page_url"), {
|
||||
text: "{{ page_url }}",
|
||||
width: 256,
|
||||
height: 256,
|
||||
colorDark: "#000000",
|
||||
colorLight: "#ffffff",
|
||||
correctLevel: QRCode.CorrectLevel.L,
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<details>
|
||||
<summary>System Routes</summary>
|
||||
<div class="route-list">
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>paste pad</title>
|
||||
</head>
|
||||
<body>
|
||||
<input id="n" />
|
||||
<textarea id="pc"></textarea>
|
||||
<button type="button" id="s">sendit</button>
|
||||
<script>
|
||||
/** @type {HTMLInputElement} */
|
||||
const name = document.getElementById("n");
|
||||
/** @type {HTMLTextAreaElement} */
|
||||
const content = document.getElementById("pc");
|
||||
|
||||
/** @type {HTMLButtonElement} */
|
||||
(document.getElementById("s")).addEventListener("click", () => {});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+78
-1
@@ -1,7 +1,11 @@
|
||||
"gemini converted"
|
||||
|
||||
from random import choice
|
||||
import socket
|
||||
from collections import deque
|
||||
from itertools import islice
|
||||
import string
|
||||
from typing import Optional
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
|
||||
from fastapi import FastAPI, Form, Request
|
||||
@@ -15,6 +19,19 @@ templates = Jinja2Templates(directory="templates")
|
||||
queue: deque[str] = deque() # fifo ahh
|
||||
|
||||
|
||||
def get_local_ip():
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
try:
|
||||
# doesn't even have to be reachable
|
||||
s.connect(("10.255.255.255", 1))
|
||||
IP = s.getsockname()[0]
|
||||
except Exception:
|
||||
IP = "127.0.0.1"
|
||||
finally:
|
||||
s.close()
|
||||
return IP
|
||||
|
||||
|
||||
def link_extract_from_onetab(line: str) -> str:
|
||||
"link | title"
|
||||
link = line.split("|", 1)[0].strip()
|
||||
@@ -24,7 +41,14 @@ def link_extract_from_onetab(line: str) -> str:
|
||||
@app.get("/", response_class=HTMLResponse)
|
||||
async def index(request: Request):
|
||||
"idgaf"
|
||||
return templates.TemplateResponse(request, "index.html", {"routes": app.routes})
|
||||
# Construct the URL using the local IP
|
||||
port = request.url.port or 2222
|
||||
local_ip = get_local_ip()
|
||||
page_url = f"{request.url.scheme}://{local_ip}:{port}"
|
||||
|
||||
return templates.TemplateResponse(
|
||||
request, "index.html", {"routes": app.routes, "page_url": page_url}
|
||||
)
|
||||
|
||||
|
||||
@app.get("/q", response_class=HTMLResponse)
|
||||
@@ -101,6 +125,59 @@ async def send_queue(lines: str = Form("")):
|
||||
return RedirectResponse(url="/queuein", status_code=303)
|
||||
|
||||
|
||||
texts: dict[str, str] = {} # name (auto or rewrite): content
|
||||
|
||||
|
||||
@app.get("/pastepad")
|
||||
async def pastepad_ui(request: Request):
|
||||
return templates.TemplateResponse(request, "pastepad.html", {"texts": texts})
|
||||
|
||||
|
||||
def random_str(l: int = 8, s=string.ascii_letters + string.digits):
|
||||
return "".join(choice(s) for _ in range(l))
|
||||
|
||||
|
||||
@app.post("/api/pastepad")
|
||||
async def paste_in(content: str, name: Optional[str] = None):
|
||||
if name in texts:
|
||||
return {"name": name, "content": texts[name]}
|
||||
if name is None:
|
||||
name = random_str()
|
||||
texts[name] = content
|
||||
return {"name": name, "content": texts[name]}
|
||||
|
||||
|
||||
@app.get("/api/pastepad")
|
||||
async def paste_query(name: str):
|
||||
if name in texts:
|
||||
return {"name": name, "content": texts[name]}
|
||||
return {"name": None, "content": None}
|
||||
|
||||
|
||||
@app.get("/api/pastepad/all")
|
||||
async def paste_dump():
|
||||
return list({"name": n, "content": c} for n, c in texts.items())
|
||||
|
||||
|
||||
@app.delete("/api/pastepad")
|
||||
async def paste_delete(name: str):
|
||||
if name in texts:
|
||||
t = texts[name]
|
||||
del texts[name]
|
||||
return {"name": name, "content": t}
|
||||
return {"name": None, "content": None}
|
||||
|
||||
|
||||
@app.put("/api/pastepad")
|
||||
@app.patch("/api/pastepad")
|
||||
async def paste_put(name: str, content: str):
|
||||
if name in texts:
|
||||
t = texts[name]
|
||||
texts[name] = content
|
||||
return {"name": name, "content": t}
|
||||
return {"name": None, "content": None}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
|
||||
|
||||
Reference in new issue
Block a user