mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Unauthenticated channel info endpoint.
This commit is contained in:
parent
ac2723e0e5
commit
48efbe66ca
3 changed files with 38 additions and 0 deletions
|
@ -306,6 +306,14 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
} catch (Exception e) {
|
||||
return getErrorResponse(e, request.getPath());
|
||||
}
|
||||
})).map(GET, "/subscriptions/unauthenticated", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(ResponseHelper.unauthenticatedSubscriptionsResponse(
|
||||
Objects.requireNonNull(request.getQueryParameter("channels")).split(",")
|
||||
), "public, s-maxage=120");
|
||||
} catch (Exception e) {
|
||||
return getErrorResponse(e, request.getPath());
|
||||
}
|
||||
})).map(POST, "/user/playlists/create", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
var name = Constants.mapper.readTree(request.loadBody().getResult().asArray()).get("name").textValue();
|
||||
|
|
|
@ -1213,6 +1213,35 @@ public class ResponseHelper {
|
|||
|
||||
}
|
||||
|
||||
public static byte[] unauthenticatedSubscriptionsResponse(String[] channelIds)
|
||||
throws IOException {
|
||||
|
||||
Set<String> filtered = Arrays.stream(channelIds)
|
||||
.filter(StringUtils::isNotBlank)
|
||||
.filter(id -> id.matches("[A-Za-z\\d_-]+"))
|
||||
.collect(Collectors.toUnmodifiableSet());
|
||||
|
||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||
|
||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||
var query = cb.createQuery(me.kavin.piped.utils.obj.db.Channel.class);
|
||||
var root = query.from(me.kavin.piped.utils.obj.db.Channel.class);
|
||||
query.select(root);
|
||||
query.where(root.get("uploader_id").in(filtered));
|
||||
|
||||
var channels = s.createQuery(query).list();
|
||||
|
||||
List<SubscriptionChannel> subscriptionItems = channels
|
||||
.stream().parallel()
|
||||
.sorted(Comparator.comparing(me.kavin.piped.utils.obj.db.Channel::getUploader, String.CASE_INSENSITIVE_ORDER))
|
||||
.map(channel -> new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
||||
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified()))
|
||||
.collect(Collectors.toUnmodifiableList());
|
||||
|
||||
return mapper.writeValueAsBytes(subscriptionItems);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] createPlaylist(String session, String name) throws IOException {
|
||||
|
||||
if (StringUtils.isBlank(name))
|
||||
|
|
|
@ -131,3 +131,4 @@ curl ${CURLOPTS[@]} $HOST/user/delete -X POST -H "Content-Type: application/json
|
|||
CHANNEL_IDS=UCsXVk37bltHxD1rDPwtNM8Q,UCXuqSBlHAE6Xw-yeJA0Tunw
|
||||
curl ${CURLOPTS[@]} $HOST/feed/unauthenticated -G --data-urlencode "channels=$CHANNEL_IDS" || exit 1
|
||||
curl ${CURLOPTS[@]} $HOST/feed/unauthenticated/rss -G --data-urlencode "channels=$CHANNEL_IDS" || exit 1
|
||||
curl ${CURLOPTS[@]} $HOST/subscriptions/unauthenticated -G --data-urlencode "channels=$CHANNEL_IDS" || exit 1
|
||||
|
|
Loading…
Reference in a new issue