mirror of
https://github.com/FoggedLens/deflock.git
synced 2026-10-12 01:48:55 +02:00
Sponsors and tags (#22)
* brand -> manufacturer * clean up * add donation page * display manufacturer first, brand for backward compat
This commit is contained in:
1 parent
6dff9cb2c8
commit
cce969e6ba
15 files changed
+207
-18
No files matched your search
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -17,9 +17,12 @@ import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import scala.io.StdIn
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
object ShotgunServer {
|
||||
|
||||
val logger = LoggerFactory.getLogger(getClass)
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
|
||||
implicit val system: ActorSystem = ActorSystem("my-system")
|
||||
@@ -28,6 +31,7 @@ object ShotgunServer {
|
||||
|
||||
val client = new services.OverpassClient()
|
||||
val nominatim = new services.NominatimClient()
|
||||
val githubClient = new services.GithubClient()
|
||||
|
||||
// CORS
|
||||
val allowedOrigins = List(
|
||||
@@ -72,6 +76,13 @@ object ShotgunServer {
|
||||
}
|
||||
}
|
||||
},
|
||||
path("sponsors" / "github") {
|
||||
get {
|
||||
onSuccess(githubClient.getSponsors("frillweeman")) { json =>
|
||||
complete(json)
|
||||
}
|
||||
}
|
||||
},
|
||||
path("oauth2" / "callback") {
|
||||
get {
|
||||
parameters(Symbol("code").?) { (code) =>
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package services
|
||||
|
||||
import org.apache.pekko.actor.ActorSystem
|
||||
import org.apache.pekko.http.javadsl.model.headers.{Authorization, HttpCredentials, UserAgent}
|
||||
import org.apache.pekko.http.scaladsl.Http
|
||||
import org.apache.pekko.http.scaladsl.model.{HttpMethods, HttpRequest, StatusCodes}
|
||||
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
|
||||
import spray.json.JsValue
|
||||
import spray.json._
|
||||
import org.apache.pekko.http.scaladsl.model.ContentTypes
|
||||
import org.apache.pekko.http.scaladsl.model.HttpEntity
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import scala.concurrent.{ExecutionContextExecutor, Future}
|
||||
|
||||
class GithubClient(implicit val system: ActorSystem, implicit val executionContext: ExecutionContextExecutor) {
|
||||
val logger = LoggerFactory.getLogger(getClass)
|
||||
val graphQLEndpoint = "https://api.github.com/graphql"
|
||||
private val githubApiToken = sys.env("GITHUB_TOKEN")
|
||||
|
||||
def getSponsors(username: String): Future[JsArray] = {
|
||||
|
||||
val query = s"""
|
||||
|query {
|
||||
| user(login: "$username") {
|
||||
| sponsorshipsAsMaintainer(first: 100) {
|
||||
| nodes {
|
||||
| sponsor {
|
||||
| login
|
||||
| name
|
||||
| avatarUrl
|
||||
| }
|
||||
| }
|
||||
| }
|
||||
| }
|
||||
|}
|
||||
|""".stripMargin.replace("\n", " ").replace("\"", "\\\"")
|
||||
|
||||
val jsonRequest = s"""{"query": "$query", "variables": ""}"""
|
||||
val jsonEntity = HttpEntity(ContentTypes.`application/json`, jsonRequest)
|
||||
val request = HttpRequest(
|
||||
headers = List(
|
||||
UserAgent.create("Shotgun"),
|
||||
Authorization.create(HttpCredentials.create("Bearer", githubApiToken))
|
||||
),
|
||||
method = HttpMethods.POST,
|
||||
uri = graphQLEndpoint,
|
||||
entity = jsonEntity
|
||||
)
|
||||
|
||||
Http().singleRequest(request).flatMap { response =>
|
||||
response.status match {
|
||||
case StatusCodes.OK =>
|
||||
Unmarshal(response.entity).to[String].map { jsonString =>
|
||||
jsonString.parseJson.asJsObject
|
||||
.fields("data").asJsObject
|
||||
.fields("user").asJsObject
|
||||
.fields("sponsorshipsAsMaintainer")
|
||||
.asJsObject.fields("nodes")
|
||||
.asInstanceOf[JsArray]
|
||||
}
|
||||
case _ =>
|
||||
response.discardEntityBytes()
|
||||
Future.failed(new Exception(s"Failed to get sponsors: ${response.status}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import pekko.http.scaladsl.Http
|
||||
import pekko.http.scaladsl.model._
|
||||
import pekko.http.scaladsl.unmarshalling.Unmarshal
|
||||
import spray.json._
|
||||
import DefaultJsonProtocol._
|
||||
import scala.concurrent.{ExecutionContextExecutor, Future}
|
||||
|
||||
case class BoundingBox(minLat: Double, minLng: Double, maxLat: Double, maxLng: Double)
|
||||
|
||||
Reference in new issue
Block a user