async def force_recheck(self, request): realm = Realm.select().where(Realm.name == request.match_info['realm_name']).first() if not realm: return JsonResponse({'detail': 'Realm does not exist. Create it by adding a client to it.'}, status=400) try: await self.orchestrator.force_recheck( realm=realm, info_hash=request.match_info['info_hash'] ) return JsonResponse({}) except TorrentNotFoundException: return JsonResponse({'detail': 'Torrent not found.'}, status=404) except asyncio.TimeoutError: return JsonResponse({'detail': 'Alcazar is busy performing another action. Try again later.'}, status=503)
async def post_clients(self, request): data = await request.json() with DB.atomic(): realm = Realm.select().where(Realm.name == data['realm']).first() if not realm: realm = Realm.create(name=data['realm']) try: instance = self.orchestrator.add_instance( realm=realm, instance_type=data['instance_type'], config_kwargs=data.get('config', {}), ) except asyncio.TimeoutError: return JsonResponse( data={'detail': 'Alcazar is busy performing another action. Try again later.'}, status=503, ) return JsonResponse(instance.get_info_dict())
async def post_torrents(self, request): data = await request.json() realm = Realm.select().where(Realm.name == request.match_info['realm_name']).first() if not realm: return JsonResponse({'detail': 'Realm does not exist. Create it by adding a client to it.'}, status=400) try: data = await self.orchestrator.add_torrent( realm=realm, torrent_file=base64.b64decode(data['torrent']), download_path=data['download_path'], name=data.get('name'), ) except (NotInitializedException, NoManagerForRealmException) as exc: return JsonResponse({'detail': str(exc)}, status=400) except TorrentAlreadyAddedException as exc: return JsonResponse({'detail': str(exc)}, status=409) except asyncio.TimeoutError: return JsonResponse({'detail': 'Alcazar is busy performing another action. Try again later.'}, status=503) return JsonResponse(data)