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