This commit is contained in:
parent
f9964a8157
commit
7281614024
@ -44,7 +44,7 @@ proxy_server = os.environ.get("PROXY_SERVER")
|
|||||||
class ProxyCreateLink(pydantic.BaseModel):
|
class ProxyCreateLink(pydantic.BaseModel):
|
||||||
upstream: pydantic.HttpUrl
|
upstream: pydantic.HttpUrl
|
||||||
ctype: Optional[pydantic.StrictStr]
|
ctype: Optional[pydantic.StrictStr]
|
||||||
region: pydantic.StrictStr
|
region: Optional[pydantic.StrictStr]
|
||||||
|
|
||||||
|
|
||||||
class ProxyRequest(pydantic.BaseModel):
|
class ProxyRequest(pydantic.BaseModel):
|
||||||
@ -75,10 +75,16 @@ class ProxyElem:
|
|||||||
for url in urls:
|
for url in urls:
|
||||||
if isinstance(url, tuple):
|
if isinstance(url, tuple):
|
||||||
clean_urls.append(url[0])
|
clean_urls.append(url[0])
|
||||||
link_requests.append(ProxyCreateLink.parse_obj({"upstream": url[0], "ctype": url[1], "region": self.region}))
|
link_requests.append(
|
||||||
|
ProxyCreateLink.parse_obj(
|
||||||
|
{"upstream": url[0], "ctype": url[1], "region": self.region}
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
clean_urls.append(url)
|
clean_urls.append(url)
|
||||||
link_requests.append(ProxyCreateLink.parse_obj({"upstream": url, "region": self.region}))
|
link_requests.append(
|
||||||
|
ProxyCreateLink.parse_obj({"upstream": url, "region": self.region})
|
||||||
|
)
|
||||||
if not isinstance(proxy_server, str):
|
if not isinstance(proxy_server, str):
|
||||||
return clean_urls
|
return clean_urls
|
||||||
|
|
||||||
@ -86,7 +92,9 @@ class ProxyElem:
|
|||||||
response_data: ProxyResponse
|
response_data: ProxyResponse
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request_data = ProxyRequest.parse_obj({"urls": link_requests, "action": "create-urls"})
|
request_data = ProxyRequest.parse_obj(
|
||||||
|
{"urls": link_requests, "action": "create-urls"}
|
||||||
|
)
|
||||||
except pydantic.ValidationError as e:
|
except pydantic.ValidationError as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
return clean_urls
|
return clean_urls
|
||||||
@ -94,7 +102,9 @@ class ProxyElem:
|
|||||||
try:
|
try:
|
||||||
async with self.local() as session:
|
async with self.local() as session:
|
||||||
resp = await session.post(proxy_server, json=request_data)
|
resp = await session.post(proxy_server, json=request_data)
|
||||||
response_data = cast(ProxyResponse, ProxyResponse.parse_obj(await resp.text()))
|
response_data = cast(
|
||||||
|
ProxyResponse, ProxyResponse.parse_obj(await resp.text())
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user