Create clipboard_api.py
Browse files- clipboard_api.py +32 -0
clipboard_api.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
STORE = {
|
| 8 |
+
"text": "",
|
| 9 |
+
"updated_at": None
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
class TextIn(BaseModel):
|
| 13 |
+
text: str
|
| 14 |
+
|
| 15 |
+
@app.post("/set")
|
| 16 |
+
def set_text(data: TextIn):
|
| 17 |
+
STORE["text"] = data.text
|
| 18 |
+
STORE["updated_at"] = datetime.utcnow().isoformat()
|
| 19 |
+
return {"ok": True}
|
| 20 |
+
|
| 21 |
+
@app.get("/get")
|
| 22 |
+
def get_text():
|
| 23 |
+
return STORE
|
| 24 |
+
|
| 25 |
+
@app.get("/")
|
| 26 |
+
def info():
|
| 27 |
+
return {
|
| 28 |
+
"usage": {
|
| 29 |
+
"POST /set": {"text": "要粘贴的内容"},
|
| 30 |
+
"GET /get": "获取当前文本"
|
| 31 |
+
}
|
| 32 |
+
}
|