feat(lists): adds redirector data format
This commit is contained in:
parent
c16a80dc16
commit
60255afe3f
8 changed files with 117 additions and 4 deletions
|
@ -3,10 +3,12 @@ from typing import Dict, Callable, Any
|
|||
from app.lists.bc2 import mirror_sites
|
||||
from app.lists.bridgelines import bridgelines
|
||||
from app.lists.mirror_mapping import mirror_mapping
|
||||
from app.lists.redirector import redirector_data
|
||||
from app.models.base import Pool
|
||||
|
||||
lists: Dict[str, Callable[[Pool], Any]] = {
|
||||
"bca": mirror_mapping,
|
||||
"bc2": mirror_sites,
|
||||
"bridgelines": bridgelines,
|
||||
"rdr": redirector_data,
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class MirrorMapping(BaseModel):
|
|||
title = "Mirror Mapping Version 1.1"
|
||||
|
||||
|
||||
def mirror_mapping(pool: Pool) -> Dict[str, Union[str, Dict[str, str]]]:
|
||||
def mirror_mapping(ignored_pool: Pool) -> Dict[str, Union[str, Dict[str, str]]]:
|
||||
return MirrorMapping(
|
||||
version="1.1",
|
||||
mappings={
|
||||
|
|
51
app/lists/redirector.py
Normal file
51
app/lists/redirector.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
from typing import List, Dict, Union, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.models.base import Pool
|
||||
from app.models.mirrors import Proxy
|
||||
|
||||
|
||||
class RedirectorPool(BaseModel):
|
||||
short_name: str
|
||||
description: str
|
||||
api_key: str
|
||||
origins: Dict[str, str]
|
||||
|
||||
|
||||
class RedirectorData(BaseModel):
|
||||
version: str
|
||||
pools: List[RedirectorPool]
|
||||
|
||||
|
||||
def redirector_pool_origins(pool: Pool) -> Dict[str, str]:
|
||||
origins: Dict[str, str] = dict()
|
||||
active_proxies = Proxy.query.filter(
|
||||
Proxy.deprecated.is_(None),
|
||||
Proxy.destroyed.is_(None),
|
||||
Proxy.pool_id == pool.id
|
||||
)
|
||||
for proxy in active_proxies:
|
||||
origins[proxy.origin.domain_name] = proxy.url
|
||||
return origins
|
||||
|
||||
|
||||
def redirector_pool(pool: Pool) -> RedirectorPool:
|
||||
return RedirectorPool(
|
||||
short_name=pool.pool_name,
|
||||
description=pool.description,
|
||||
api_key=pool.api_key,
|
||||
origins=redirector_pool_origins(pool)
|
||||
)
|
||||
|
||||
|
||||
def redirector_data(ignored_pool: Optional[Pool]) -> Dict[str, Union[str, Dict[str, Union[Dict[str, str]]]]]:
|
||||
active_pools = Pool.query.filter(
|
||||
Pool.destroyed.is_(None)
|
||||
).all()
|
||||
return RedirectorData(
|
||||
version="1.0",
|
||||
pools=[
|
||||
redirector_pool(pool) for pool in active_pools
|
||||
]
|
||||
).dict()
|
Loading…
Add table
Add a link
Reference in a new issue