feat(backend): proxy endpoint for checkout.theshrine.net
All checks were successful
Publish docker image / Publish (push) Successful in 1m44s
All checks were successful
Publish docker image / Publish (push) Successful in 1m44s
This commit is contained in:
parent
fa88fa658e
commit
8c553b92f4
1 changed files with 27 additions and 2 deletions
|
@ -13,11 +13,14 @@ router = APIRouter(prefix='/3p-proxy')
|
|||
def reformat_reject_date(date: str):
|
||||
return format_checkin_date(datetime.strptime(date, '%a %b %d %Y'))
|
||||
|
||||
def make_client_session():
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
||||
return aiohttp.ClientSession(headers={'User-Agent': 'Mozilla 5.0 (compatible); aci-backend/1.0 (+https://git.ashhhleyyy.dev/ash/aci)'}, connector=aiohttp.TCPConnector(ssl=ssl_context))
|
||||
|
||||
@router.get('/reject')
|
||||
async def reject_proxy(date: str, time: str, activity: str, space: str):
|
||||
"""We proxy the rejectdopamine API to maintain user pivacy (the extension does not transmit user IP addresses to third-party services)"""
|
||||
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
||||
async with aiohttp.ClientSession(headers={'User-Agent': 'Mozilla 5.0 (compatible); aci-backend/1.0 (+https://git.ashhhleyyy.dev/ash/aci)'}, connector=aiohttp.TCPConnector(ssl=ssl_context)) as session:
|
||||
async with make_client_session() as session:
|
||||
async with session.get('https://rejectdopamine.com/api/app/active/yrk/cs/1') as resp:
|
||||
response = await resp.json()
|
||||
activities = []
|
||||
|
@ -46,3 +49,25 @@ async def reject_proxy(date: str, time: str, activity: str, space: str):
|
|||
'activity': activity,
|
||||
'codes': [],
|
||||
}
|
||||
|
||||
@router.get('/shrine-checkout')
|
||||
async def shrine_checkout_proxy(date: str, time: str, activity: str, space: str):
|
||||
"""We proxy the checkout.theshrine.net API to maintain user privacy (the extension does not transmit user IP address to third-party services)"""
|
||||
async with make_client_session() as session:
|
||||
async with session.post('https://checkout.theshrine.net/api/activity/ext/id', json={
|
||||
'date': date,
|
||||
'time': time,
|
||||
'activity': activity,
|
||||
'space': space,
|
||||
}) as resp:
|
||||
response = await resp.json()
|
||||
external_id = response['externalId']
|
||||
async with session.get(f'https://checkout.theshrine.net/api/activity/ext/{external_id}/codes') as resp:
|
||||
response = await resp.json()
|
||||
return {
|
||||
'date': date,
|
||||
'time': time,
|
||||
'space': space,
|
||||
'activity': activity,
|
||||
'codes': list(map(lambda c: {'code': c['code'], 'score': 0}, response['codes']))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue