mirror of
https://github.com/TeamPiped/Piped-Backend
synced 2025-09-06 05:21:09 +02:00
Use try with for sessions (#222)
This commit is contained in:
parent
860bd57b3d
commit
43d6dc93c0
@ -31,8 +31,7 @@ public class Main {
|
|||||||
new Timer().scheduleAtFixedRate(new TimerTask() {
|
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
|
||||||
|
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
CriteriaQuery<PubSub> criteria = cb.createQuery(PubSub.class);
|
CriteriaQuery<PubSub> criteria = cb.createQuery(PubSub.class);
|
||||||
@ -51,16 +50,13 @@ public class Main {
|
|||||||
for (PubSub pubsub : pubSubList)
|
for (PubSub pubsub : pubSubList)
|
||||||
if (pubsub != null)
|
if (pubsub != null)
|
||||||
Multithreading.runAsyncLimitedPubSub(() -> {
|
Multithreading.runAsyncLimitedPubSub(() -> {
|
||||||
Session sess = DatabaseSessionFactory.createSession();
|
try (Session sess = DatabaseSessionFactory.createSession()) {
|
||||||
try {
|
|
||||||
ResponseHelper.subscribePubSub(pubsub.getId(), sess);
|
ResponseHelper.subscribePubSub(pubsub.getId(), sess);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
sess.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
s.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -70,8 +66,7 @@ public class Main {
|
|||||||
new Timer().scheduleAtFixedRate(new TimerTask() {
|
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
|
||||||
|
|
||||||
Transaction tr = s.getTransaction();
|
Transaction tr = s.getTransaction();
|
||||||
|
|
||||||
@ -84,7 +79,6 @@ public class Main {
|
|||||||
|
|
||||||
tr.commit();
|
tr.commit();
|
||||||
|
|
||||||
s.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -55,12 +55,12 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||||||
new InputSource(new ByteArrayInputStream(request.loadBody().getResult().asArray())));
|
new InputSource(new ByteArrayInputStream(request.loadBody().getResult().asArray())));
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
feed.getEntries().forEach(entry -> {
|
for (var entry : feed.getEntries()) {
|
||||||
ResponseHelper.handleNewVideo(entry.getLinks().get(0).getHref(),
|
ResponseHelper.handleNewVideo(entry.getLinks().get(0).getHref(),
|
||||||
entry.getPublishedDate().getTime(), null, s);
|
entry.getPublishedDate().getTime(), null, s);
|
||||||
});
|
}
|
||||||
s.close();
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return HttpResponse.ofCode(204);
|
return HttpResponse.ofCode(204);
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.cfg.Configuration;
|
|
||||||
|
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.obj.db.Channel;
|
import me.kavin.piped.utils.obj.db.Channel;
|
||||||
import me.kavin.piped.utils.obj.db.PubSub;
|
import me.kavin.piped.utils.obj.db.PubSub;
|
||||||
import me.kavin.piped.utils.obj.db.User;
|
import me.kavin.piped.utils.obj.db.User;
|
||||||
import me.kavin.piped.utils.obj.db.Video;
|
import me.kavin.piped.utils.obj.db.Video;
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.SessionFactory;
|
||||||
|
import org.hibernate.cfg.Configuration;
|
||||||
|
|
||||||
public class DatabaseSessionFactory {
|
public class DatabaseSessionFactory {
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package me.kavin.piped.utils;
|
package me.kavin.piped.utils;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class Multithreading {
|
public class Multithreading {
|
||||||
|
|
||||||
@ -26,4 +28,8 @@ public class Multithreading {
|
|||||||
public static ExecutorService getCachedExecutor() {
|
public static ExecutorService getCachedExecutor() {
|
||||||
return es;
|
return es;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) {
|
||||||
|
return CompletableFuture.supplyAsync(supplier, es);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -50,7 +50,6 @@ import javax.persistence.criteria.JoinType;
|
|||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
@ -66,25 +65,25 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
public static byte[] streamsResponse(String videoId) throws Exception {
|
public static byte[] streamsResponse(String videoId) throws Exception {
|
||||||
|
|
||||||
CompletableFuture<StreamInfo> futureStream = CompletableFuture.supplyAsync(() -> {
|
final var futureStream = Multithreading.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
|
return StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExceptionUtils.rethrow(e);
|
ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}, Multithreading.getCachedExecutor());
|
});
|
||||||
|
|
||||||
CompletableFuture<String> futureLbryId = CompletableFuture.supplyAsync(() -> {
|
final var futureLbryId = Multithreading.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return LbryHelper.getLBRYId(videoId);
|
return LbryHelper.getLBRYId(videoId);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExceptionHandler.handle(e);
|
ExceptionHandler.handle(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}, Multithreading.getCachedExecutor());
|
});
|
||||||
|
|
||||||
CompletableFuture<String> futureLBRY = CompletableFuture.supplyAsync(() -> {
|
final var futureLBRY = Multithreading.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
String lbryId = futureLbryId.completeOnTimeout(null, 2, TimeUnit.SECONDS).get();
|
String lbryId = futureLbryId.completeOnTimeout(null, 2, TimeUnit.SECONDS).get();
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ public class ResponseHelper {
|
|||||||
ExceptionHandler.handle(e);
|
ExceptionHandler.handle(e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}, Multithreading.getCachedExecutor());
|
});
|
||||||
|
|
||||||
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
final List<Subtitle> subtitles = new ObjectArrayList<>();
|
||||||
final List<ChapterSegment> chapters = new ObjectArrayList<>();
|
final List<ChapterSegment> chapters = new ObjectArrayList<>();
|
||||||
@ -187,35 +186,34 @@ public class ResponseHelper {
|
|||||||
info.getRelatedItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
info.getRelatedItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
me.kavin.piped.utils.obj.db.Channel channel = DatabaseHelper.getChannelFromId(s, info.getId());
|
me.kavin.piped.utils.obj.db.Channel channel = DatabaseHelper.getChannelFromId(s, info.getId());
|
||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
if (channel.isVerified() != info.isVerified()
|
if (channel.isVerified() != info.isVerified()
|
||||||
|| !channel.getUploaderAvatar().equals(info.getAvatarUrl())) {
|
|| !channel.getUploaderAvatar().equals(info.getAvatarUrl())) {
|
||||||
channel.setVerified(info.isVerified());
|
channel.setVerified(info.isVerified());
|
||||||
channel.setUploaderAvatar(info.getAvatarUrl());
|
channel.setUploaderAvatar(info.getAvatarUrl());
|
||||||
if (!s.getTransaction().isActive())
|
if (!s.getTransaction().isActive())
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
s.update(channel);
|
s.update(channel);
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
}
|
}
|
||||||
for (StreamInfoItem item : info.getRelatedItems()) {
|
for (StreamInfoItem item : info.getRelatedItems()) {
|
||||||
long time = item.getUploadDate() != null
|
long time = item.getUploadDate() != null
|
||||||
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
||||||
: System.currentTimeMillis();
|
: System.currentTimeMillis();
|
||||||
if (System.currentTimeMillis() - time < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION))
|
if (System.currentTimeMillis() - time < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION))
|
||||||
try {
|
try {
|
||||||
String id = YOUTUBE_SERVICE.getStreamLHFactory().getId(item.getUrl());
|
String id = YOUTUBE_SERVICE.getStreamLHFactory().getId(item.getUrl());
|
||||||
updateVideo(id, item, time, true);
|
updateVideo(id, item, time, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ExceptionHandler.handle(e);
|
ExceptionHandler.handle(e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
String nextpage = null;
|
String nextpage = null;
|
||||||
@ -527,40 +525,38 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
user = user.toLowerCase();
|
user = user.toLowerCase();
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
CriteriaQuery<User> cr = cb.createQuery(User.class);
|
CriteriaQuery<User> cr = cb.createQuery(User.class);
|
||||||
Root<User> root = cr.from(User.class);
|
Root<User> root = cr.from(User.class);
|
||||||
cr.select(root).where(root.get("username").in(user));
|
cr.select(root).where(cb.equal(root.get("username"), user));
|
||||||
boolean registered = s.createQuery(cr).uniqueResult() != null;
|
boolean registered = s.createQuery(cr).uniqueResult() != null;
|
||||||
|
|
||||||
if (registered) {
|
if (registered) {
|
||||||
s.close();
|
return Constants.mapper.writeValueAsBytes(new AlreadyRegisteredResponse());
|
||||||
return Constants.mapper.writeValueAsBytes(new AlreadyRegisteredResponse());
|
}
|
||||||
|
|
||||||
|
if (Constants.COMPROMISED_PASSWORD_CHECK) {
|
||||||
|
String sha1Hash = DigestUtils.sha1Hex(pass).toUpperCase();
|
||||||
|
String prefix = sha1Hash.substring(0, 5);
|
||||||
|
String suffix = sha1Hash.substring(5);
|
||||||
|
String[] entries = RequestUtils
|
||||||
|
.sendGet("https://api.pwnedpasswords.com/range/" + prefix, "github.com/TeamPiped/Piped-Backend")
|
||||||
|
.split("\n");
|
||||||
|
for (String entry : entries)
|
||||||
|
if (StringUtils.substringBefore(entry, ":").equals(suffix))
|
||||||
|
return Constants.mapper.writeValueAsBytes(new CompromisedPasswordResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
User newuser = new User(user, argon2PasswordEncoder.encode(pass), Collections.emptyList());
|
||||||
|
|
||||||
|
s.save(newuser);
|
||||||
|
s.getTransaction().begin();
|
||||||
|
s.getTransaction().commit();
|
||||||
|
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new LoginResponse(newuser.getSessionId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Constants.COMPROMISED_PASSWORD_CHECK) {
|
|
||||||
String sha1Hash = DigestUtils.sha1Hex(pass).toUpperCase();
|
|
||||||
String prefix = sha1Hash.substring(0, 5);
|
|
||||||
String suffix = sha1Hash.substring(5);
|
|
||||||
String[] entries = RequestUtils
|
|
||||||
.sendGet("https://api.pwnedpasswords.com/range/" + prefix, "github.com/TeamPiped/Piped-Backend")
|
|
||||||
.split("\n");
|
|
||||||
for (String entry : entries)
|
|
||||||
if (StringUtils.substringBefore(entry, ":").equals(suffix))
|
|
||||||
return Constants.mapper.writeValueAsBytes(new CompromisedPasswordResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
User newuser = new User(user, argon2PasswordEncoder.encode(pass), Collections.emptyList());
|
|
||||||
|
|
||||||
s.save(newuser);
|
|
||||||
s.getTransaction().begin();
|
|
||||||
s.getTransaction().commit();
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new LoginResponse(newuser.getSessionId()));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder();
|
private static final BCryptPasswordEncoder bcryptPasswordEncoder = new BCryptPasswordEncoder();
|
||||||
@ -573,394 +569,352 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
user = user.toLowerCase();
|
user = user.toLowerCase();
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
CriteriaQuery<User> cr = cb.createQuery(User.class);
|
CriteriaQuery<User> cr = cb.createQuery(User.class);
|
||||||
Root<User> root = cr.from(User.class);
|
Root<User> root = cr.from(User.class);
|
||||||
cr.select(root).where(root.get("username").in(user));
|
cr.select(root).where(root.get("username").in(user));
|
||||||
|
|
||||||
User dbuser = s.createQuery(cr).uniqueResult();
|
User dbuser = s.createQuery(cr).uniqueResult();
|
||||||
|
|
||||||
if (dbuser != null) {
|
if (dbuser != null) {
|
||||||
String hash = dbuser.getPassword();
|
String hash = dbuser.getPassword();
|
||||||
if (hash.startsWith("$argon2")) {
|
if (hash.startsWith("$argon2")) {
|
||||||
if (argon2PasswordEncoder.matches(pass, hash)) {
|
if (argon2PasswordEncoder.matches(pass, hash)) {
|
||||||
s.close();
|
return Constants.mapper.writeValueAsBytes(new LoginResponse(dbuser.getSessionId()));
|
||||||
|
}
|
||||||
|
} else if (bcryptPasswordEncoder.matches(pass, hash)) {
|
||||||
return Constants.mapper.writeValueAsBytes(new LoginResponse(dbuser.getSessionId()));
|
return Constants.mapper.writeValueAsBytes(new LoginResponse(dbuser.getSessionId()));
|
||||||
}
|
}
|
||||||
} else if (bcryptPasswordEncoder.matches(pass, hash)) {
|
|
||||||
s.close();
|
|
||||||
return Constants.mapper.writeValueAsBytes(new LoginResponse(dbuser.getSessionId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new IncorrectCredentialsResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new IncorrectCredentialsResponse());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] subscribeResponse(String session, String channelId)
|
public static byte[] subscribeResponse(String session, String channelId)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
User user = DatabaseHelper.getUserFromSessionWithSubscribed(s, session);
|
User user = DatabaseHelper.getUserFromSessionWithSubscribed(s, session);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
if (!user.getSubscribed().contains(channelId)) {
|
if (!user.getSubscribed().contains(channelId)) {
|
||||||
|
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
s.createNativeQuery("insert into users_subscribed (subscriber, channel) values (?,?)")
|
s.createNativeQuery("insert into users_subscribed (subscriber, channel) values (?,?)")
|
||||||
.setParameter(1, user.getId()).setParameter(2, channelId).executeUpdate();
|
.setParameter(1, user.getId()).setParameter(2, channelId).executeUpdate();
|
||||||
s.getTransaction().commit();
|
s.getTransaction().commit();
|
||||||
s.close();
|
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
Session sess = DatabaseSessionFactory.createSession();
|
try (Session sess = DatabaseSessionFactory.createSession()) {
|
||||||
var channel = DatabaseHelper.getChannelFromId(sess, channelId);
|
var channel = DatabaseHelper.getChannelFromId(sess, channelId);
|
||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
ChannelInfo info = null;
|
ChannelInfo info = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);
|
info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);
|
||||||
} catch (IOException | ExtractionException e) {
|
} catch (IOException | ExtractionException e) {
|
||||||
ExceptionUtils.rethrow(e);
|
ExceptionUtils.rethrow(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
channel = new me.kavin.piped.utils.obj.db.Channel(channelId, info.getName(),
|
channel = new me.kavin.piped.utils.obj.db.Channel(channelId, info.getName(),
|
||||||
info.getAvatarUrl(), info.isVerified());
|
info.getAvatarUrl(), info.isVerified());
|
||||||
sess.save(channel);
|
sess.save(channel);
|
||||||
sess.beginTransaction().commit();
|
sess.beginTransaction().commit();
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
try {
|
try (Session sessSub = DatabaseSessionFactory.createSession()) {
|
||||||
Session sessSub = DatabaseSessionFactory.createSession();
|
subscribePubSub(channelId, sessSub);
|
||||||
subscribePubSub(channelId, sessSub);
|
} catch (Exception e) {
|
||||||
sessSub.close();
|
ExceptionHandler.handle(e);
|
||||||
} catch (Exception e) {
|
}
|
||||||
ExceptionHandler.handle(e);
|
});
|
||||||
|
|
||||||
|
for (StreamInfoItem item : info.getRelatedItems()) {
|
||||||
|
long time = item.getUploadDate() != null
|
||||||
|
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
||||||
|
: System.currentTimeMillis();
|
||||||
|
if ((System.currentTimeMillis() - time) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION))
|
||||||
|
handleNewVideo(item.getUrl(), time, channel, sess);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
for (StreamInfoItem item : info.getRelatedItems()) {
|
|
||||||
long time = item.getUploadDate() != null
|
|
||||||
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
|
||||||
: System.currentTimeMillis();
|
|
||||||
if ((System.currentTimeMillis() - time) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION))
|
|
||||||
handleNewVideo(item.getUrl(), time, channel, sess);
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
sess.close();
|
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] unsubscribeResponse(String session, String channelId)
|
public static byte[] unsubscribeResponse(String session, String channelId)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
User user = DatabaseHelper.getUserFromSession(s, session);
|
||||||
|
|
||||||
User user = DatabaseHelper.getUserFromSession(s, session);
|
if (user != null) {
|
||||||
|
s.getTransaction().begin();
|
||||||
if (user != null) {
|
s.createNativeQuery("delete from users_subscribed where subscriber = :id and channel = :channel")
|
||||||
s.getTransaction().begin();
|
.setParameter("id", user.getId()).setParameter("channel", channelId).executeUpdate();
|
||||||
s.createNativeQuery("delete from users_subscribed where subscriber = :id and channel = :channel")
|
s.getTransaction().commit();
|
||||||
.setParameter("id", user.getId()).setParameter("channel", channelId).executeUpdate();
|
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
||||||
s.getTransaction().commit();
|
|
||||||
s.close();
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
|
||||||
}
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] isSubscribedResponse(String session, String channelId)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
|
||||||
|
|
||||||
var cb = s.getCriteriaBuilder();
|
|
||||||
var query = cb.createQuery(Long.class);
|
|
||||||
var root = query.from(User.class);
|
|
||||||
query.select(cb.count(root))
|
|
||||||
.where(cb.and(
|
|
||||||
cb.equal(root.get("sessionId"), session),
|
|
||||||
cb.isMember(channelId, root.get("subscribed_ids"))
|
|
||||||
));
|
|
||||||
var subscribed = s.createQuery(query).getSingleResult() > 0;
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new SubscribeStatusResponse(subscribed));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] feedResponse(String session)
|
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
|
||||||
|
|
||||||
User user = DatabaseHelper.getUserFromSession(s, session);
|
|
||||||
|
|
||||||
if (user != null) {
|
|
||||||
|
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
|
||||||
|
|
||||||
// Get all videos from subscribed channels, with channel info
|
|
||||||
CriteriaQuery<Video> criteria = cb.createQuery(Video.class);
|
|
||||||
criteria.distinct(true);
|
|
||||||
var root = criteria.from(Video.class);
|
|
||||||
var userRoot = criteria.from(User.class);
|
|
||||||
root.fetch("channel", JoinType.INNER);
|
|
||||||
|
|
||||||
criteria.select(root)
|
|
||||||
.where(cb.and(
|
|
||||||
cb.isMember(root.get("channel"), userRoot.<Collection<String>>get("subscribed_ids")),
|
|
||||||
cb.equal(userRoot.get("id"), user.getId())
|
|
||||||
))
|
|
||||||
.orderBy(cb.desc(root.get("uploaded")));
|
|
||||||
|
|
||||||
List<StreamItem> feedItems = new ObjectArrayList<>();
|
|
||||||
|
|
||||||
for (Video video : s.createQuery(criteria).list()) {
|
|
||||||
var channel = video.getChannel();
|
|
||||||
|
|
||||||
feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(),
|
|
||||||
rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(),
|
|
||||||
rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(),
|
|
||||||
video.getUploaded(), channel.isVerified()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
feedItems.sort(Comparator.<StreamItem>comparingLong(o -> o.uploaded).reversed());
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(feedItems);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] feedResponseRSS(String session)
|
public static byte[] isSubscribedResponse(String session, String channelId) throws IOException {
|
||||||
throws IOException, FeedException {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
var cb = s.getCriteriaBuilder();
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
var query = cb.createQuery(Long.class);
|
||||||
|
var root = query.from(User.class);
|
||||||
User user = DatabaseHelper.getUserFromSession(s, session);
|
query.select(cb.count(root))
|
||||||
|
|
||||||
if (user != null) {
|
|
||||||
|
|
||||||
SyndFeed feed = new SyndFeedImpl();
|
|
||||||
feed.setFeedType("atom_1.0");
|
|
||||||
feed.setTitle("Piped - Feed");
|
|
||||||
feed.setDescription(String.format("Piped's RSS subscription feed for %s.", user.getUsername()));
|
|
||||||
feed.setUri(Constants.FRONTEND_URL + "/feed");
|
|
||||||
feed.setPublishedDate(new Date());
|
|
||||||
|
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
|
||||||
|
|
||||||
// Get all videos from subscribed channels, with channel info
|
|
||||||
CriteriaQuery<Video> criteria = cb.createQuery(Video.class);
|
|
||||||
criteria.distinct(true);
|
|
||||||
var root = criteria.from(Video.class);
|
|
||||||
var userRoot = criteria.from(User.class);
|
|
||||||
root.fetch("channel", JoinType.INNER);
|
|
||||||
|
|
||||||
criteria.select(root)
|
|
||||||
.where(cb.and(
|
.where(cb.and(
|
||||||
cb.isMember(root.get("channel"), userRoot.<Collection<String>>get("subscribed_ids")),
|
cb.equal(root.get("sessionId"), session),
|
||||||
cb.equal(userRoot.get("id"), user.getId())
|
cb.isMember(channelId, root.get("subscribed_ids"))
|
||||||
))
|
));
|
||||||
.orderBy(cb.desc(root.get("uploaded")));
|
var subscribed = s.createQuery(query).getSingleResult() > 0;
|
||||||
|
|
||||||
List<Video> videos = s.createQuery(criteria).list();
|
return Constants.mapper.writeValueAsBytes(new SubscribeStatusResponse(subscribed));
|
||||||
|
|
||||||
final List<SyndEntry> entries = new ObjectArrayList<>();
|
|
||||||
|
|
||||||
for (Video video : videos) {
|
|
||||||
var channel = video.getChannel();
|
|
||||||
SyndEntry entry = new SyndEntryImpl();
|
|
||||||
|
|
||||||
SyndPerson person = new SyndPersonImpl();
|
|
||||||
person.setName(channel.getUploader());
|
|
||||||
person.setUri(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId());
|
|
||||||
|
|
||||||
entry.setAuthors(Collections.singletonList(person));
|
|
||||||
|
|
||||||
entry.setLink(Constants.FRONTEND_URL + "/watch?v=" + video.getId());
|
|
||||||
entry.setUri(Constants.FRONTEND_URL + "/watch?v=" + video.getId());
|
|
||||||
entry.setTitle(video.getTitle());
|
|
||||||
entry.setPublishedDate(new Date(video.getUploaded()));
|
|
||||||
entries.add(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
feed.setEntries(entries);
|
|
||||||
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return new SyndFeedOutput().outputString(feed).getBytes(UTF_8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] importResponse(String session, String[] channelIds, boolean override)
|
public static byte[] feedResponse(String session) throws IOException {
|
||||||
throws IOException {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
User user = DatabaseHelper.getUserFromSession(s, session);
|
||||||
|
|
||||||
User user = DatabaseHelper.getUserFromSessionWithSubscribed(s, session);
|
if (user != null) {
|
||||||
|
|
||||||
if (user != null) {
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
// Get all videos from subscribed channels, with channel info
|
||||||
if (override)
|
CriteriaQuery<Video> criteria = cb.createQuery(Video.class);
|
||||||
user.setSubscribed(Arrays.asList(channelIds));
|
criteria.distinct(true);
|
||||||
else
|
var root = criteria.from(Video.class);
|
||||||
for (String channelId : channelIds)
|
var userRoot = criteria.from(User.class);
|
||||||
if (!user.getSubscribed().contains(channelId))
|
root.fetch("channel", JoinType.INNER);
|
||||||
user.getSubscribed().add(channelId);
|
|
||||||
|
|
||||||
if (channelIds.length > 0) {
|
criteria.select(root)
|
||||||
s.update(user);
|
.where(cb.and(
|
||||||
s.beginTransaction().commit();
|
cb.isMember(root.get("channel"), userRoot.<Collection<String>>get("subscribed_ids")),
|
||||||
|
cb.equal(userRoot.get("id"), user.getId())
|
||||||
|
))
|
||||||
|
.orderBy(cb.desc(root.get("uploaded")));
|
||||||
|
|
||||||
|
List<StreamItem> feedItems = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
for (Video video : s.createQuery(criteria).list()) {
|
||||||
|
var channel = video.getChannel();
|
||||||
|
|
||||||
|
feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(),
|
||||||
|
rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(),
|
||||||
|
rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(),
|
||||||
|
video.getUploaded(), channel.isVerified()));
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
feedItems.sort(Comparator.<StreamItem>comparingLong(o -> o.uploaded).reversed());
|
||||||
});
|
|
||||||
|
|
||||||
for (String channelId : channelIds) {
|
|
||||||
|
|
||||||
Multithreading.runAsyncLimited(() -> {
|
|
||||||
try {
|
|
||||||
|
|
||||||
Session sess = DatabaseSessionFactory.createSession();
|
|
||||||
|
|
||||||
var channel = DatabaseHelper.getChannelFromId(sess, channelId);
|
|
||||||
|
|
||||||
if (channel == null) {
|
|
||||||
ChannelInfo info;
|
|
||||||
|
|
||||||
try {
|
|
||||||
info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
channel = new me.kavin.piped.utils.obj.db.Channel(channelId, info.getName(),
|
|
||||||
info.getAvatarUrl(), info.isVerified());
|
|
||||||
sess.save(channel);
|
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
|
||||||
try {
|
|
||||||
Session sessSub = DatabaseSessionFactory.createSession();
|
|
||||||
subscribePubSub(channelId, sessSub);
|
|
||||||
sessSub.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
ExceptionHandler.handle(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (StreamInfoItem item : info.getRelatedItems()) {
|
|
||||||
long time = item.getUploadDate() != null
|
|
||||||
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
|
||||||
: System.currentTimeMillis();
|
|
||||||
if ((System.currentTimeMillis() - time) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION))
|
|
||||||
handleNewVideo(item.getUrl(), time, channel, sess);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!sess.getTransaction().isActive())
|
|
||||||
sess.getTransaction().begin();
|
|
||||||
sess.getTransaction().commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
sess.close();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
ExceptionHandler.handle(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(feedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s.close();
|
public static byte[] feedResponseRSS(String session) throws IOException, FeedException {
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
|
User user = DatabaseHelper.getUserFromSession(s, session);
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
|
||||||
|
SyndFeed feed = new SyndFeedImpl();
|
||||||
|
feed.setFeedType("atom_1.0");
|
||||||
|
feed.setTitle("Piped - Feed");
|
||||||
|
feed.setDescription(String.format("Piped's RSS subscription feed for %s.", user.getUsername()));
|
||||||
|
feed.setUri(Constants.FRONTEND_URL + "/feed");
|
||||||
|
feed.setPublishedDate(new Date());
|
||||||
|
|
||||||
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
|
|
||||||
|
// Get all videos from subscribed channels, with channel info
|
||||||
|
CriteriaQuery<Video> criteria = cb.createQuery(Video.class);
|
||||||
|
criteria.distinct(true);
|
||||||
|
var root = criteria.from(Video.class);
|
||||||
|
var userRoot = criteria.from(User.class);
|
||||||
|
root.fetch("channel", JoinType.INNER);
|
||||||
|
|
||||||
|
criteria.select(root)
|
||||||
|
.where(cb.and(
|
||||||
|
cb.isMember(root.get("channel"), userRoot.<Collection<String>>get("subscribed_ids")),
|
||||||
|
cb.equal(userRoot.get("id"), user.getId())
|
||||||
|
))
|
||||||
|
.orderBy(cb.desc(root.get("uploaded")));
|
||||||
|
|
||||||
|
List<Video> videos = s.createQuery(criteria).list();
|
||||||
|
|
||||||
|
final List<SyndEntry> entries = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
for (Video video : videos) {
|
||||||
|
var channel = video.getChannel();
|
||||||
|
SyndEntry entry = new SyndEntryImpl();
|
||||||
|
|
||||||
|
SyndPerson person = new SyndPersonImpl();
|
||||||
|
person.setName(channel.getUploader());
|
||||||
|
person.setUri(Constants.FRONTEND_URL + "/channel/" + channel.getUploaderId());
|
||||||
|
|
||||||
|
entry.setAuthors(Collections.singletonList(person));
|
||||||
|
|
||||||
|
entry.setLink(Constants.FRONTEND_URL + "/watch?v=" + video.getId());
|
||||||
|
entry.setUri(Constants.FRONTEND_URL + "/watch?v=" + video.getId());
|
||||||
|
entry.setTitle(video.getTitle());
|
||||||
|
entry.setPublishedDate(new Date(video.getUploaded()));
|
||||||
|
entries.add(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
feed.setEntries(entries);
|
||||||
|
|
||||||
|
return new SyndFeedOutput().outputString(feed).getBytes(UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] importResponse(String session, String[] channelIds, boolean override) throws IOException {
|
||||||
|
|
||||||
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
|
User user = DatabaseHelper.getUserFromSessionWithSubscribed(s, session);
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
|
||||||
|
Multithreading.runAsync(() -> {
|
||||||
|
if (override)
|
||||||
|
user.setSubscribed(Arrays.asList(channelIds));
|
||||||
|
else
|
||||||
|
for (String channelId : channelIds)
|
||||||
|
if (!user.getSubscribed().contains(channelId))
|
||||||
|
user.getSubscribed().add(channelId);
|
||||||
|
|
||||||
|
if (channelIds.length > 0) {
|
||||||
|
s.update(user);
|
||||||
|
s.beginTransaction().commit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (String channelId : channelIds) {
|
||||||
|
|
||||||
|
Multithreading.runAsyncLimited(() -> {
|
||||||
|
try (Session sess = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
|
var channel = DatabaseHelper.getChannelFromId(sess, channelId);
|
||||||
|
|
||||||
|
if (channel == null) {
|
||||||
|
ChannelInfo info;
|
||||||
|
|
||||||
|
try {
|
||||||
|
info = ChannelInfo.getInfo("https://youtube.com/channel/" + channelId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
channel = new me.kavin.piped.utils.obj.db.Channel(channelId, info.getName(),
|
||||||
|
info.getAvatarUrl(), info.isVerified());
|
||||||
|
sess.save(channel);
|
||||||
|
|
||||||
|
Multithreading.runAsync(() -> {
|
||||||
|
try (Session sessSub = DatabaseSessionFactory.createSession()) {
|
||||||
|
subscribePubSub(channelId, sessSub);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ExceptionHandler.handle(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (StreamInfoItem item : info.getRelatedItems()) {
|
||||||
|
long time = item.getUploadDate() != null
|
||||||
|
? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli()
|
||||||
|
: System.currentTimeMillis();
|
||||||
|
if ((System.currentTimeMillis() - time) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION))
|
||||||
|
handleNewVideo(item.getUrl(), time, channel, sess);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sess.getTransaction().isActive())
|
||||||
|
sess.getTransaction().begin();
|
||||||
|
sess.getTransaction().commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
ExceptionHandler.handle(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new AcceptedResponse());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] subscriptionsResponse(String session)
|
public static byte[] subscriptionsResponse(String session)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
User user = DatabaseHelper.getUserFromSession(s, session);
|
User user = DatabaseHelper.getUserFromSession(s, session);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
|
||||||
List<SubscriptionChannel> subscriptionItems = new ObjectArrayList<>();
|
List<SubscriptionChannel> subscriptionItems = new ObjectArrayList<>();
|
||||||
|
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
var query = cb.createQuery(me.kavin.piped.utils.obj.db.Channel.class);
|
var query = cb.createQuery(me.kavin.piped.utils.obj.db.Channel.class);
|
||||||
var root = query.from(me.kavin.piped.utils.obj.db.Channel.class);
|
var root = query.from(me.kavin.piped.utils.obj.db.Channel.class);
|
||||||
var userRoot = query.from(User.class);
|
var userRoot = query.from(User.class);
|
||||||
query.select(root);
|
query.select(root);
|
||||||
query.where(cb.and(
|
query.where(cb.and(
|
||||||
cb.isMember(root.get("uploader_id"), userRoot.<Collection<String>>get("subscribed_ids")),
|
cb.isMember(root.get("uploader_id"), userRoot.<Collection<String>>get("subscribed_ids")),
|
||||||
cb.equal(userRoot.get("id"), user.getId())
|
cb.equal(userRoot.get("id"), user.getId())
|
||||||
));
|
));
|
||||||
|
|
||||||
var channels = s.createQuery(query).list();
|
var channels = s.createQuery(query).list();
|
||||||
|
|
||||||
channels.forEach(channel -> subscriptionItems.add(new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
channels.forEach(channel -> subscriptionItems.add(new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
||||||
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified())));
|
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified())));
|
||||||
|
|
||||||
subscriptionItems.sort(Comparator.comparing(o -> o.name));
|
subscriptionItems.sort(Comparator.comparing(o -> o.name));
|
||||||
|
|
||||||
s.close();
|
return Constants.mapper.writeValueAsBytes(subscriptionItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(subscriptionItems);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(new AuthenticationFailureResponse());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String registeredBadgeRedirect() {
|
public static String registeredBadgeRedirect() {
|
||||||
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
long registered = (Long) s.createQuery("select count(*) from User").uniqueResult();
|
||||||
|
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
return String.format("https://img.shields.io/badge/Registered%%20Users-%s-blue", registered);
|
||||||
|
}
|
||||||
long registered = (Long) s.createQuery("select count(*) from User").uniqueResult();
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
|
|
||||||
return String.format("https://img.shields.io/badge/Registered%%20Users-%s-blue", registered);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handleNewVideo(String url, long time, me.kavin.piped.utils.obj.db.Channel channel, Session s) {
|
public static void handleNewVideo(String url, long time, me.kavin.piped.utils.obj.db.Channel channel, Session s) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user