Api - РАБОТАЕТ!!!!!!!!!!
This commit is contained in:
parent
662b2d9a3a
commit
48ea009cab
3 changed files with 24 additions and 9 deletions
12
API/main.py
12
API/main.py
|
|
@ -3,7 +3,7 @@ from pydantic import BaseModel, EmailStr
|
|||
import utils
|
||||
|
||||
app = FastAPI()
|
||||
methods = utils.API("")
|
||||
args = ["", "", "", "", 0, "", ""]
|
||||
|
||||
class RegisterBody(BaseModel) :
|
||||
email : EmailStr
|
||||
|
|
@ -20,7 +20,9 @@ class UrlsBody(BaseModel) :
|
|||
|
||||
@app.post("/registration", status_code=status.HTTP_201_CREATED)
|
||||
def registration(body: RegisterBody) :
|
||||
methods = utils.API(*args)
|
||||
result = methods.registration(body.email, body.password)
|
||||
methods.close()
|
||||
if result["code"] == 1:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -30,7 +32,9 @@ def registration(body: RegisterBody) :
|
|||
|
||||
@app.post("/login", status_code=status.HTTP_200_OK)
|
||||
def login(body: LoginBody) :
|
||||
methods = utils.API(*args)
|
||||
answer = methods.login(body.email, body.password)
|
||||
methods.close()
|
||||
if answer["code"] == 1 :
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -41,7 +45,9 @@ def login(body: LoginBody) :
|
|||
|
||||
@app.post("/add_url", status_code=status.HTTP_200_OK)
|
||||
def add_url(body: UrlsBody) :
|
||||
methods = utils.API(*args)
|
||||
answer = methods.add_url(body.email, body.password, body.urls_name)
|
||||
methods.close()
|
||||
if answer["code"] == 1 :
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -57,7 +63,9 @@ def add_url(body: UrlsBody) :
|
|||
|
||||
@app.get("/get_url", status_code=status.HTTP_200_OK)
|
||||
def get_url(email: EmailStr = Query(...), password: str = Query(...), urls_name: str = Query(...)) :
|
||||
methods = utils.API(*args)
|
||||
answer = methods.get_url(email, password, urls_name)
|
||||
methods.close()
|
||||
if answer["code"] == 1 :
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
@ -73,7 +81,9 @@ def get_url(email: EmailStr = Query(...), password: str = Query(...), urls_name:
|
|||
|
||||
@app.delete("/del_url", status_code=status.HTTP_200_OK)
|
||||
def del_url(email: EmailStr = Query(...), password: str = Query(...), urls_name: str = Query(...)) :
|
||||
methods = utils.API(*args)
|
||||
answer = methods.del_url(email, password, urls_name)
|
||||
methods.close()
|
||||
if answer["code"] == 1 :
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
|
|
|
|||
18
API/utils.py
18
API/utils.py
|
|
@ -45,6 +45,7 @@ class API :
|
|||
params = ()
|
||||
return json.loads(pandas.read_sql(sql_command, self.con, params=params).to_json())
|
||||
|
||||
@staticmethod
|
||||
def get_hash(text: str) -> str:
|
||||
return hashlib.sha256(text.encode()).hexdigest()
|
||||
|
||||
|
|
@ -70,9 +71,12 @@ class API :
|
|||
data = self.read_table("""
|
||||
SELECT id FROM users
|
||||
WHERE email = ?
|
||||
""", (email))
|
||||
""", (email,))
|
||||
return {"code": 0, "data": {"id": int(data["id"]["0"]), "email": email}}
|
||||
|
||||
def close(self) :
|
||||
self.con.close()
|
||||
|
||||
def login(self, email: str, passwd: str) -> dict :
|
||||
"""
|
||||
0 - Success
|
||||
|
|
@ -116,9 +120,9 @@ class API :
|
|||
pbk = stream["realitySettings"]["settings"]["publicKey"]
|
||||
uid = str(uuid.uuid4())
|
||||
|
||||
response = self.response("post", "api/inbound/addClient", json={
|
||||
response = self.response("post", "inbound/addClient", json={
|
||||
"id": self.inbaund_id,
|
||||
"settings": {
|
||||
"settings": json.dumps({
|
||||
"clients":[{
|
||||
"id": uid,
|
||||
"flow": "xtls-rprx-vision",
|
||||
|
|
@ -132,7 +136,7 @@ class API :
|
|||
"comment": "",
|
||||
"reset": 0
|
||||
}]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
response = self.response("post", "inbound/list")
|
||||
|
|
@ -153,6 +157,7 @@ class API :
|
|||
urls = ?
|
||||
WHERE id = ?
|
||||
""", (json.dumps(urls), int(data["id"]["0"])))
|
||||
self.con.commit()
|
||||
data = self.read_table("""
|
||||
SELECT id, urls FROM users
|
||||
WHERE email = ? AND pass_hash = ?
|
||||
|
|
@ -189,7 +194,7 @@ class API :
|
|||
sni = random.choice(stream["realitySettings"]["serverNames"])
|
||||
pbk = stream["realitySettings"]["settings"]["publicKey"]
|
||||
client = None
|
||||
for i in json.loads(inbaund["settings"]) :
|
||||
for i in json.loads(inbaund["settings"])["clients"] :
|
||||
if i["email"] == f"{email}-{url_name}" :
|
||||
client = i
|
||||
break
|
||||
|
|
@ -225,7 +230,7 @@ class API :
|
|||
if inbaund == None :
|
||||
raise TypeError
|
||||
client = None
|
||||
for i in json.loads(inbaund["settings"]) :
|
||||
for i in json.loads(inbaund["settings"])["clients"] :
|
||||
if i["email"] == f"{email}-{url_name}" :
|
||||
client = i
|
||||
break
|
||||
|
|
@ -240,6 +245,7 @@ class API :
|
|||
urls = ?
|
||||
WHERE id = ?
|
||||
""", (json.dumps(urls), int(data["id"]["0"])))
|
||||
self.con.commit()
|
||||
data = self.read_table("""
|
||||
SELECT id, urls FROM users
|
||||
WHERE email = ? AND pass_hash = ?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue