1
This commit is contained in:
parent
d2d5959134
commit
af748247c5
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.vscode/settings.json
|
||||||
|
*.pyc
|
@ -4,19 +4,17 @@ from pydantic import BaseModel
|
|||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
from config.config import settings
|
from config.config import settings
|
||||||
from scritps.common.get_img import get_img
|
from scripts.common.get_img import get_img
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/img")
|
@router.get("/img")
|
||||||
async def get_img(request: Request,url:str)-> JSONResponse:
|
async def get_img(request: Request, url: str) -> JSONResponse:
|
||||||
key=url[24:]
|
key = url[24:]
|
||||||
redis_client = request.app.state.redis
|
redis_client = request.app.state.redis
|
||||||
values=await redis_client.get(key)
|
values = await redis_client.get(key)
|
||||||
if values:
|
if values:
|
||||||
return {"url": values}
|
return {"url": values}
|
||||||
else:
|
else:
|
||||||
vv=await get_img(key)
|
vv = await get_img(key)
|
||||||
return {"url": vv}
|
return {"url": vv}
|
||||||
|
|
@ -1,26 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
from scripts.log import logger
|
|
||||||
|
|
||||||
|
|
||||||
@logger.catch
|
|
||||||
def run_cmd(cmd, shell=True, timeout=120):
|
|
||||||
'''
|
|
||||||
Run command with arguments, wait to complete and return ``True`` on success.
|
|
||||||
|
|
||||||
:param cls: The class as implicit first argument.
|
|
||||||
:param cmd: Command string to be executed.
|
|
||||||
:returns : ``True`` on success, otherwise ``None``.
|
|
||||||
:rtype : ``bool``
|
|
||||||
'''
|
|
||||||
logger.debug('Execute command: {0}'.format(cmd))
|
|
||||||
status = True
|
|
||||||
try:
|
|
||||||
out_bytes = subprocess.check_output(
|
|
||||||
cmd, shell=shell, stderr=subprocess.STDOUT, timeout=timeout)
|
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
out_bytes = e.output # Output generated before error
|
|
||||||
code = e.returncode # Return code
|
|
||||||
logger.error(f"run {cmd} failed,out={out_bytes},code={code}")
|
|
||||||
status = False
|
|
||||||
|
|
||||||
return out_bytes, status
|
|
Loading…
x
Reference in New Issue
Block a user