stale/uncommitted
This commit is contained in:
parent
493a5bebc1
commit
da674e0ef9
@ -42,12 +42,17 @@ class XC(FastAPI):
|
||||
bid = data.bid
|
||||
cmd = data.cmd
|
||||
cmd_data = data.data
|
||||
req_type = 0
|
||||
|
||||
if not self.util.check_key(request.url.path, key):
|
||||
if bid in [1]:
|
||||
req_type = 2
|
||||
|
||||
if not self.util.check_key(path=request.url.path, req_type=req_type, key=key):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
|
||||
BID_ADDR_MAP = {
|
||||
0: '10.10.10.101:5991' # Thomas/Aces
|
||||
0: '10.10.10.101:5991', # Thomas/Aces
|
||||
1: '10.10.10.100:5992' # MS & Waleed Combo
|
||||
}
|
||||
|
||||
if not bid in BID_ADDR_MAP.keys():
|
||||
|
@ -22,9 +22,7 @@ class LastFM:
|
||||
}
|
||||
|
||||
async with ClientSession() as session:
|
||||
async with session.get(f"{self.api_base_url}artist.getinfo&artist={artist} \
|
||||
&api_key={self.creds.get('key')}&autocorrect=1&format=json",
|
||||
timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
async with session.get(f"{self.api_base_url}artist.getinfo&artist={artist}&api_key={self.creds.get('key')}&autocorrect=1&format=json", timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
assert request.status in [200, 204]
|
||||
data = await request.json()
|
||||
data = data.get('artist')
|
||||
@ -53,10 +51,7 @@ class LastFM:
|
||||
}
|
||||
|
||||
async with ClientSession() as session:
|
||||
async with session.get(f"{self.api_base_url}track.getInfo&api_key={self.creds.get('key')} \
|
||||
&autocorrect=1&artist={artist}&track={track} \
|
||||
&format=json",
|
||||
timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
async with session.get(f"{self.api_base_url}track.getInfo&api_key={self.creds.get('key')}&autocorrect=1&artist={artist}&track={track}&format=json", timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
assert request.status in [200, 204]
|
||||
data = await request.json()
|
||||
data = data.get('track')
|
||||
@ -103,9 +98,7 @@ class LastFM:
|
||||
}
|
||||
|
||||
async with ClientSession() as session:
|
||||
async with session.get(f"{self.api_base_url}artist.gettopalbums&artist={artist} \
|
||||
&api_key={self.creds.get('key')}&autocorrect=1&format=json",
|
||||
timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
async with session.get(f"{self.api_base_url}artist.gettopalbums&artist={artist}&api_key={self.creds.get('key')}&autocorrect=1&format=json", timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
assert request.status in [200, 204]
|
||||
# return request.text
|
||||
data = await request.json()
|
||||
@ -152,9 +145,7 @@ class LastFM:
|
||||
}
|
||||
|
||||
async with ClientSession() as session:
|
||||
async with session.get(f"{self.api_base_url}artists/{artist_id}?key={self.creds.get('key')} \
|
||||
&secret={self.creds.get('secret')}",
|
||||
timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
async with session.get(f"{self.api_base_url}artists/{artist_id}?key={self.creds.get('key')}&secret={self.creds.get('secret')}", timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
assert request.status in [200, 204]
|
||||
data = await request.json()
|
||||
|
||||
@ -182,7 +173,7 @@ class LastFM:
|
||||
# return {
|
||||
# 'err': Failed
|
||||
# }
|
||||
artist_info = await self.get_artist_info_by_id(artist_id=artist)
|
||||
artist_info = await self.get_artist_info_by_id(artist_id=artist_id)
|
||||
if artist_info is None:
|
||||
return {
|
||||
'err': Failed
|
||||
@ -202,10 +193,7 @@ class LastFM:
|
||||
}
|
||||
|
||||
async with ClientSession() as session:
|
||||
async with session.get(f"{self.api_base_url}album.getinfo&artist={artist} \
|
||||
&album={album}&api_key={self.creds.get('key')} \
|
||||
&autocorrect=1&format=json",
|
||||
timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
async with session.get(f"{self.api_base_url}album.getinfo&artist={artist}&album={album}&api_key={self.creds.get('key')}&autocorrect=1&format=json", timeout=ClientTimeout(connect=3, sock_read=8)) as request:
|
||||
assert request.status in [200, 204]
|
||||
data = await request.json()
|
||||
data = data.get('album')
|
||||
|
11
util.py
11
util.py
@ -20,7 +20,7 @@ class Utilities:
|
||||
logging.error("Rejected request: No such endpoint")
|
||||
raise HTTPException(detail="Unknown endpoint", status_code=404)
|
||||
|
||||
def check_key(self, path: str, key: str):
|
||||
def check_key(self, path: str, key: str, req_type: int = 0):
|
||||
"""
|
||||
Accepts path as an argument to allow fine tuning access for each API key, not currently in use.
|
||||
"""
|
||||
@ -36,7 +36,14 @@ class Utilities:
|
||||
print("Auth failed")
|
||||
return False
|
||||
|
||||
if path.lower().startswith("/xc/") and not(key.startswith("XC-")):
|
||||
if req_type == 2:
|
||||
if not key.startswith("PRV-"):
|
||||
print("Auth failed - not a PRV key")
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
if path.lower().startswith("/xc/") and not key.startswith("XC-"):
|
||||
print("Auth failed - not an XC Key")
|
||||
return False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user