mirror of
				https://github.com/arcan1s/ffxivbis.git
				synced 2025-10-30 21:23:41 +00:00 
			
		
		
		
	identify url in runtime
This commit is contained in:
		| @ -1,7 +1,5 @@ | |||||||
| me.arcanis.ffxivbis { | me.arcanis.ffxivbis { | ||||||
|   bis-provider { |   bis-provider { | ||||||
|     # either use ariyala or etro |  | ||||||
|     use-etro = no |  | ||||||
|     # xivapi base url, string, required |     # xivapi base url, string, required | ||||||
|     xivapi-url = "https://xivapi.com" |     xivapi-url = "https://xivapi.com" | ||||||
|     # xivapi developer key, string, optional |     # xivapi developer key, string, optional | ||||||
|  | |||||||
| @ -34,9 +34,7 @@ class Application extends Actor with StrictLogging { | |||||||
|  |  | ||||||
|   Migration(config).onComplete { |   Migration(config).onComplete { | ||||||
|     case Success(_) => |     case Success(_) => | ||||||
|       val useEtro = config.getBoolean("me.arcanis.ffxivbis.bis-provider.use-etro") |       val bisProvider = context.system.actorOf(BisProvider.props, "bis-provider") | ||||||
|  |  | ||||||
|       val bisProvider = context.system.actorOf(BisProvider.props(useEtro), "bis-provider") |  | ||||||
|       val storage = context.system.actorOf(DatabaseImpl.props, "storage") |       val storage = context.system.actorOf(DatabaseImpl.props, "storage") | ||||||
|       val party = context.system.actorOf(PartyService.props(storage), "party") |       val party = context.system.actorOf(PartyService.props(storage), "party") | ||||||
|       val http = new RootEndpoint(context.system, party, bisProvider) |       val http = new RootEndpoint(context.system, party, bisProvider) | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ import spray.json.{JsNumber, JsObject, JsString, deserializationError} | |||||||
|  |  | ||||||
| import scala.concurrent.{ExecutionContext, Future} | import scala.concurrent.{ExecutionContext, Future} | ||||||
|  |  | ||||||
| trait Ariyala { | object Ariyala { | ||||||
|  |  | ||||||
|   def idParser(job: Job.Job, js: JsObject) |   def idParser(job: Job.Job, js: JsObject) | ||||||
|               (implicit executionContext: ExecutionContext): Future[Map[String, Long]] = |               (implicit executionContext: ExecutionContext): Future[Map[String, Long]] = | ||||||
|  | |||||||
| @ -19,11 +19,7 @@ import spray.json._ | |||||||
|  |  | ||||||
| import scala.concurrent.{ExecutionContext, Future} | import scala.concurrent.{ExecutionContext, Future} | ||||||
|  |  | ||||||
| abstract class BisProvider extends Actor with XivApi with StrictLogging { | class BisProvider extends Actor with XivApi with StrictLogging { | ||||||
|  |  | ||||||
|   def idParser(job: Job.Job, js: JsObject) |  | ||||||
|               (implicit executionContext: ExecutionContext): Future[Map[String, Long]] |  | ||||||
|   def uri(root: Uri, id: String): Uri |  | ||||||
|  |  | ||||||
|   override def receive: Receive = { |   override def receive: Receive = { | ||||||
|     case BisProvider.GetBiS(link, job) => |     case BisProvider.GetBiS(link, job) => | ||||||
| @ -40,15 +36,20 @@ abstract class BisProvider extends Actor with XivApi with StrictLogging { | |||||||
|     val url = Uri(link) |     val url = Uri(link) | ||||||
|     val id = Paths.get(link).normalize.getFileName.toString |     val id = Paths.get(link).normalize.getFileName.toString | ||||||
|  |  | ||||||
|     sendRequest(uri(url, id), BisProvider.parseBisJsonToPieces(job, idParser, getPieceType)) |     val (idParser, uri) = | ||||||
|  |       if (url.authority.host.address().contains("etro")) { | ||||||
|  |         (Etro.idParser(_, _), Etro.uri(url, id)) | ||||||
|  |       } else { | ||||||
|  |         (Ariyala.idParser(_, _), Ariyala.uri(url, id)) | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |     sendRequest(uri, BisProvider.parseBisJsonToPieces(job, idParser, getPieceType)) | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| object BisProvider { | object BisProvider { | ||||||
|  |  | ||||||
|   def props(useEtro: Boolean): Props = |   def props: Props = Props(new BisProvider) | ||||||
|     if (useEtro) Props(new BisProvider with Etro) |  | ||||||
|     else Props(new BisProvider with Ariyala) |  | ||||||
|  |  | ||||||
|   case class GetBiS(link: String, job: Job.Job) |   case class GetBiS(link: String, job: Job.Job) | ||||||
|  |  | ||||||
|  | |||||||
| @ -14,7 +14,7 @@ import spray.json.{JsNumber, JsObject} | |||||||
|  |  | ||||||
| import scala.concurrent.{ExecutionContext, Future} | import scala.concurrent.{ExecutionContext, Future} | ||||||
|  |  | ||||||
| trait Etro { | object Etro { | ||||||
|  |  | ||||||
|   def idParser(job: Job.Job, js: JsObject) |   def idParser(job: Job.Job, js: JsObject) | ||||||
|               (implicit executionContext: ExecutionContext): Future[Map[String, Long]] = |               (implicit executionContext: ExecutionContext): Future[Map[String, Long]] = | ||||||
|  | |||||||
| @ -31,7 +31,7 @@ class BiSEndpointTest extends WordSpec | |||||||
|   implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout) |   implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout) | ||||||
|  |  | ||||||
|   private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props) |   private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props) | ||||||
|   private val provider: ActorRef = system.actorOf(BisProvider.props(false)) |   private val provider: ActorRef = system.actorOf(BisProvider.props) | ||||||
|   private val party: ActorRef = system.actorOf(PartyService.props(storage)) |   private val party: ActorRef = system.actorOf(PartyService.props(storage)) | ||||||
|   private val route: Route = new BiSEndpoint(party, provider)(timeout).route |   private val route: Route = new BiSEndpoint(party, provider)(timeout).route | ||||||
|  |  | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ class PartyEndpointTest extends WordSpec | |||||||
|   implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout) |   implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout) | ||||||
|  |  | ||||||
|   private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props) |   private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props) | ||||||
|   private val provider: ActorRef = system.actorOf(BisProvider.props(false)) |   private val provider: ActorRef = system.actorOf(BisProvider.props) | ||||||
|   private val route: Route = new PartyEndpoint(storage, provider)(timeout).route |   private val route: Route = new PartyEndpoint(storage, provider)(timeout).route | ||||||
|  |  | ||||||
|   override def testConfig: Config = Settings.withRandomDatabase |   override def testConfig: Config = Settings.withRandomDatabase | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ class PlayerEndpointTest extends WordSpec | |||||||
|   implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout) |   implicit private val routeTimeout: RouteTestTimeout = RouteTestTimeout(timeout) | ||||||
|  |  | ||||||
|   private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props) |   private val storage: ActorRef = system.actorOf(impl.DatabaseImpl.props) | ||||||
|   private val provider: ActorRef = system.actorOf(BisProvider.props(false)) |   private val provider: ActorRef = system.actorOf(BisProvider.props) | ||||||
|   private val party: ActorRef = system.actorOf(PartyService.props(storage)) |   private val party: ActorRef = system.actorOf(PartyService.props(storage)) | ||||||
|   private val route: Route = new PlayerEndpoint(party, provider)(timeout).route |   private val route: Route = new PlayerEndpoint(party, provider)(timeout).route | ||||||
|  |  | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ class LootSelectorTest extends TestKit(ActorSystem("lootselector")) | |||||||
|   private val timeout: FiniteDuration = 60 seconds |   private val timeout: FiniteDuration = 60 seconds | ||||||
|  |  | ||||||
|   override def beforeAll(): Unit = { |   override def beforeAll(): Unit = { | ||||||
|     val provider = system.actorOf(BisProvider.props(false)) |     val provider = system.actorOf(BisProvider.props) | ||||||
|  |  | ||||||
|     val dncSet = Await.result((provider ? BisProvider.GetBiS(Fixtures.link, Job.DNC) )(timeout).mapTo[BiS], timeout) |     val dncSet = Await.result((provider ? BisProvider.GetBiS(Fixtures.link, Job.DNC) )(timeout).mapTo[BiS], timeout) | ||||||
|     dnc = dnc.withBiS(Some(dncSet)) |     dnc = dnc.withBiS(Some(dncSet)) | ||||||
|  | |||||||
| @ -19,13 +19,13 @@ class BisProviderTest extends TestKit(ActorSystem("bis-provider")) | |||||||
|   "ariyala actor" must { |   "ariyala actor" must { | ||||||
|  |  | ||||||
|     "get best in slot set (ariyala)" in { |     "get best in slot set (ariyala)" in { | ||||||
|       val provider = system.actorOf(BisProvider.props(false)) |       val provider = system.actorOf(BisProvider.props) | ||||||
|       provider ! BisProvider.GetBiS(Fixtures.link, Job.DNC) |       provider ! BisProvider.GetBiS(Fixtures.link, Job.DNC) | ||||||
|       expectMsg(timeout, Fixtures.bis) |       expectMsg(timeout, Fixtures.bis) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     "get best in slot set (etro)" in { |     "get best in slot set (etro)" in { | ||||||
|       val provider = system.actorOf(BisProvider.props(true)) |       val provider = system.actorOf(BisProvider.props) | ||||||
|       provider ! BisProvider.GetBiS(Fixtures.link3, Job.DNC) |       provider ! BisProvider.GetBiS(Fixtures.link3, Job.DNC) | ||||||
|       expectMsg(timeout, Fixtures.bis) |       expectMsg(timeout, Fixtures.bis) | ||||||
|     } |     } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user