This commit is contained in:
root 2021-11-22 15:12:30 +08:00
parent d2d5959134
commit af748247c5
3 changed files with 7 additions and 33 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.vscode/settings.json
*.pyc

View File

@ -4,19 +4,17 @@ from pydantic import BaseModel
from starlette.requests import Request
from starlette.responses import JSONResponse
from config.config import settings
from scritps.common.get_img import get_img
from scripts.common.get_img import get_img
router = APIRouter()
@router.get("/img")
async def get_img(request: Request,url:str)-> JSONResponse:
key=url[24:]
async def get_img(request: Request, url: str) -> JSONResponse:
key = url[24:]
redis_client = request.app.state.redis
values=await redis_client.get(key)
values = await redis_client.get(key)
if values:
return {"url": values}
else:
vv=await get_img(key)
vv = await get_img(key)
return {"url": vv}

View File

@ -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