Add method to lock/unlock

This commit is contained in:
DingZQ
2023-02-19 17:12:54 +08:00
parent 178ab15318
commit 064b165678

17
main.py
View File

@@ -100,17 +100,20 @@ async def fastapi_dump_output(output: str) -> str:
return dump_output(output)
@app.get("/isprojectlocked/")
async def fastapi_is_locked(network: str):
return lockedPrjs.get(network) != None
async def fastapi_is_locked(network: str, req: Request):
client_host = req.client.host
return lockedPrjs.get(network) != client_host
@app.post("/lockproject/")
async def fastapi_lock_project(network: str, id: str):
lockedPrjs[network] = id
return True
async def fastapi_lock_project(network: str, req: Request):
client_host = req.client.host
lockedPrjs[network] = client_host
return client_host
@app.post("/unlockproject/")
async def fastapi_unlock_project(network: str, id: str):
if lockedPrjs[network] == id:
async def fastapi_unlock_project(network: str, req: Request):
client_host = req.client.host
if lockedPrjs[network] == client_host:
del lockedPrjs[network]
return True