From 02067518b0675ca57ba42f1da94e04ec6f83bee3 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 31 Jul 2022 20:50:01 +0530 Subject: [PATCH 1/3] Implement part of unauthenticated subscription api. --- .../me/kavin/piped/utils/ResponseHelper.java | 132 +++++++++++++++++- .../obj/db/UnauthenticatedSubscription.java | 38 +++++ 2 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 src/main/java/me/kavin/piped/utils/obj/db/UnauthenticatedSubscription.java diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index 8ce860a..0c4ccbd 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -15,11 +15,10 @@ import jakarta.persistence.criteria.JoinType; import jakarta.persistence.criteria.Root; import me.kavin.piped.consts.Constants; import me.kavin.piped.ipfs.IPFS; +import me.kavin.piped.utils.obj.Channel; +import me.kavin.piped.utils.obj.Playlist; import me.kavin.piped.utils.obj.*; -import me.kavin.piped.utils.obj.db.PlaylistVideo; -import me.kavin.piped.utils.obj.db.PubSub; -import me.kavin.piped.utils.obj.db.User; -import me.kavin.piped.utils.obj.db.Video; +import me.kavin.piped.utils.obj.db.*; import me.kavin.piped.utils.obj.search.SearchChannel; import me.kavin.piped.utils.obj.search.SearchPlaylist; import me.kavin.piped.utils.resp.*; @@ -959,6 +958,131 @@ public class ResponseHelper { return mapper.writeValueAsBytes(new AuthenticationFailureResponse()); } + public static byte[] unauthenticatedFeedResponse(String[] channelIds) throws Exception { + + Set filtered = Arrays.stream(channelIds) + .filter(StringUtils::isNotBlank) + .filter(StringUtils::isAlphanumeric) + .filter(id -> id.startsWith("UC")) + .collect(Collectors.toUnmodifiableSet()); + + if (filtered.isEmpty()) + return mapper.writeValueAsBytes(mapper.createObjectNode() + .put("error", "No valid channel IDs provided")); + + try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) { + + CriteriaBuilder cb = s.getCriteriaBuilder(); + + // Get all videos from subscribed channels, with channel info + CriteriaQuery