diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index af95d49..01b62eb 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -4,6 +4,7 @@ import static io.activej.config.converter.ConfigConverters.ofInetSocketAddress; import static io.activej.http.HttpHeaders.AUTHORIZATION; import static io.activej.http.HttpHeaders.CACHE_CONTROL; import static io.activej.http.HttpHeaders.CONTENT_TYPE; +import static io.activej.http.HttpHeaders.LOCATION; import static io.activej.http.HttpMethod.GET; import static io.activej.http.HttpMethod.POST; @@ -272,6 +273,13 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } catch (Exception e) { return getErrorResponse(e, request.getPath()); } + })).map(GET, "/registered/badge", AsyncServlet.ofBlocking(executor, request -> { + try { + return HttpResponse.ofCode(302).withHeader(LOCATION, ResponseHelper.registeredBadgeRedirect()) + .withHeader(CACHE_CONTROL, "public, max-age=30"); + } catch (Exception e) { + return getErrorResponse(e, request.getPath()); + } })); return new CustomServletDecorator(router); diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index cbb44bb..d8dfb23 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -967,6 +967,17 @@ public class ResponseHelper { } + public static final String registeredBadgeRedirect() { + + Session s = DatabaseSessionFactory.createSession(); + + long registered = ((Long) s.createQuery("select count(*) from User").uniqueResult()).longValue(); + + s.close(); + + return String.format("https://img.shields.io/badge/Registered%%20Users-%s-blue", String.valueOf(registered)); + } + private static final String getLBRYId(String videoId) throws IOException, InterruptedException { return new JSONObject(Constants.h2client.send(HttpRequest .newBuilder(URI.create("https://api.lbry.com/yt/resolve?video_ids=" + URLUtils.silentEncode(videoId)))