mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-13 22:00:29 +05:30
Add registered users badge.
This commit is contained in:
parent
1c8e8b190e
commit
e1e5382959
@ -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);
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user