Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/api/server.py
Show First 20 Lines • Show All 143 Lines • ▼ Show 20 Lines | |||||
@timed | @timed | ||||
async def get_stream(request): | async def get_stream(request): | ||||
hex_id = request.match_info['hex_id'] | hex_id = request.match_info['hex_id'] | ||||
obj_id = hashutil.hash_to_bytes(hex_id) | obj_id = hashutil.hash_to_bytes(hex_id) | ||||
response = aiohttp.web.StreamResponse() | response = aiohttp.web.StreamResponse() | ||||
await response.prepare(request) | await response.prepare(request) | ||||
for chunk in request.app['objstorage'].get_stream(obj_id, 2 << 20): | for chunk in request.app['objstorage'].get_stream(obj_id, 2 << 20): | ||||
response.write(chunk) | await response.write(chunk) | ||||
await response.drain() | await response.write_eof() | ||||
return response | return response | ||||
@timed | @timed | ||||
async def list_content(request): | async def list_content(request): | ||||
last_obj_id = request.query.get('last_obj_id') | last_obj_id = request.query.get('last_obj_id') | ||||
if last_obj_id: | if last_obj_id: | ||||
last_obj_id = bytes.fromhex(last_obj_id) | last_obj_id = bytes.fromhex(last_obj_id) | ||||
limit = int(request.query.get('limit', DEFAULT_LIMIT)) | limit = int(request.query.get('limit', DEFAULT_LIMIT)) | ||||
response = aiohttp.web.StreamResponse() | response = aiohttp.web.StreamResponse() | ||||
response.enable_chunked_encoding() | response.enable_chunked_encoding() | ||||
await response.prepare(request) | await response.prepare(request) | ||||
for obj_id in request.app['objstorage'].list_content( | for obj_id in request.app['objstorage'].list_content( | ||||
last_obj_id, limit=limit): | last_obj_id, limit=limit): | ||||
response.write(obj_id) | await response.write(obj_id) | ||||
await response.drain() | await response.write_eof() | ||||
return response | return response | ||||
def make_app(config): | def make_app(config): | ||||
"""Initialize the remote api application. | """Initialize the remote api application. | ||||
""" | """ | ||||
client_max_size = config.get('client_max_size', 1024 * 1024 * 1024) | client_max_size = config.get('client_max_size', 1024 * 1024 * 1024) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |