File size: 1,139 Bytes
341331a
83787dd
 
3b1b570
341331a
 
83787dd
341331a
83787dd
 
 
 
341331a
 
83787dd
341331a
 
83787dd
 
 
341331a
 
83787dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse, RedirectResponse
import urllib.parse
import os

app = FastAPI()
STORAGE_FILE = "data.txt"

# Initialize file
if not os.path.exists(STORAGE_FILE):
    with open(STORAGE_FILE, "w") as f:
        f.write("")

def read_data():
    with open(STORAGE_FILE, "r") as f:
        return f.read()

def write_data(data: str):
    with open(STORAGE_FILE, "w") as f:
        f.write(data)

@app.get("/store")
async def store(request: Request):
    lists = request.query_params.get("lists")
    if lists:
        decoded = urllib.parse.unquote(lists)
        write_data(decoded)
        return RedirectResponse(url="/")  # Redirect back to main page
    return {"status": "error", "message": "Missing 'lists' query parameter."}

@app.get("/", response_class=HTMLResponse)
async def index():
    stored_data = urllib.parse.quote(read_data())
    with open("index.html", "r", encoding="utf-8") as f:
        html = f.read()
    # Inject the stored data into the ?lists= param
    return HTMLResponse(content=html.replace("?lists=", f"?lists={stored_data}"), status_code=200)