diff --git a/.dockerignore b/.dockerignore index b493384..5b65182 100644 --- a/.dockerignore +++ b/.dockerignore @@ -6,3 +6,4 @@ Dockerfile LICENSE *.md config.properties +data/ diff --git a/.gitignore b/.gitignore index f2fc8dd..ca75516 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,11 @@ bin/ ### Gradle ### /build/ +# Database Data +/data/ + # TxT File *.txt # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* \ No newline at end of file +hs_err_pid* diff --git a/config.properties b/config.properties index 255546a..ae67038 100644 --- a/config.properties +++ b/config.properties @@ -1,13 +1,22 @@ - # The port to Listen on. PORT: 8080 -# The number of workers to use for the server -HTTP_WORKERS: 2 - -# Proxy -PROXY_PART: https://pipedproxy-ams.kavin.rocks +# The number of workers to use for the server +HTTP_WORKERS: 2 -# Captcha Parameters -CAPTCHA_BASE_URL: https://api.capmonster.cloud/ -CAPTCHA_API_KEY: INSERT_HERE +# Proxy +PROXY_PART: https://pipedproxy-ams.kavin.rocks + +# Captcha Parameters +CAPTCHA_BASE_URL: https://api.capmonster.cloud/ +CAPTCHA_API_KEY: INSERT_HERE + +# Public API URL +API_URL: https://pipedapi.kavin.rocks + +# Hibernate properties +hibernate.connection.url: jdbc:postgresql://postgres:5432/piped +hibernate.connection.driver_class: org.postgresql.Driver +hibernate.dialect: org.hibernate.dialect.PostgreSQL10Dialect +hibernate.connection.username: piped +hibernate.connection.password: changeme diff --git a/docker-compose.yml b/docker-compose.yml index 859d04f..74a386b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,19 @@ -version: "3.8" services: - piped: - image: 1337kavin/piped:latest - restart: unless-stopped - ports: - - "127.0.0.1:8080:8080" - volumes: - - ./config.properties:/app/config.properties + piped: + image: 1337piped:latest + restart: unless-stopped + ports: + - "127.0.0.1:8080:8080" + volumes: + - ./config.properties:/app/config.properties + depends_on: + - postgres + postgres: + image: postgres:13-alpine + restart: unless-stopped + volumes: + - ./data/db:/var/lib/postgresql/data + environment: + - POSTGRES_DB=piped + - POSTGRES_USER=piped + - POSTGRES_PASSWORD=changeme diff --git a/src/main/java/me/kavin/piped/Main.java b/src/main/java/me/kavin/piped/Main.java index b18a8df..a2837fb 100644 --- a/src/main/java/me/kavin/piped/Main.java +++ b/src/main/java/me/kavin/piped/Main.java @@ -1,6 +1,7 @@ package me.kavin.piped; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Timer; import java.util.TimerTask; @@ -35,6 +36,13 @@ public class Main { List channels = DatabaseHelper.getGlobalSubscribedChannelIds(s); + DatabaseHelper.getPubSubFromIds(s, channels).forEach(pubsub -> { + if (System.currentTimeMillis() - pubsub.getSubbedAt() < TimeUnit.DAYS.toMillis(4)) + channels.remove(pubsub.getId()); + }); + + Collections.shuffle(channels); + for (String channelId : channels) Multithreading.runAsyncLimitedPubSub(() -> { Session sess = DatabaseSessionFactory.createSession(); diff --git a/src/main/java/me/kavin/piped/utils/DatabaseHelper.java b/src/main/java/me/kavin/piped/utils/DatabaseHelper.java index 5872a49..7fb1ce7 100644 --- a/src/main/java/me/kavin/piped/utils/DatabaseHelper.java +++ b/src/main/java/me/kavin/piped/utils/DatabaseHelper.java @@ -82,4 +82,13 @@ public class DatabaseHelper { return s.createQuery(cr).uniqueResult(); } + + public static final List getPubSubFromIds(Session s, List id) { + CriteriaBuilder cb = s.getCriteriaBuilder(); + CriteriaQuery cr = cb.createQuery(PubSub.class); + Root root = cr.from(PubSub.class); + cr.select(root).where(root.get("id").in(id)); + + return s.createQuery(cr).getResultList(); + } } diff --git a/src/main/java/me/kavin/piped/utils/obj/db/Channel.java b/src/main/java/me/kavin/piped/utils/obj/db/Channel.java index db94722..e204e0b 100644 --- a/src/main/java/me/kavin/piped/utils/obj/db/Channel.java +++ b/src/main/java/me/kavin/piped/utils/obj/db/Channel.java @@ -7,7 +7,7 @@ import javax.persistence.Index; import javax.persistence.Table; @Entity -@Table(name = "channels", indexes = { @Index(columnList = "uploader_id", name = "uploader_id_idx") }) +@Table(name = "channels", indexes = { @Index(columnList = "uploader_id", name = "channels_uploader_id_idx") }) public class Channel { @Id diff --git a/src/main/java/me/kavin/piped/utils/obj/db/User.java b/src/main/java/me/kavin/piped/utils/obj/db/User.java index 73f050b..9905a5e 100644 --- a/src/main/java/me/kavin/piped/utils/obj/db/User.java +++ b/src/main/java/me/kavin/piped/utils/obj/db/User.java @@ -16,7 +16,7 @@ import javax.persistence.JoinColumn; import javax.persistence.Table; @Entity -@Table(name = "users", indexes = { @Index(columnList = "id", name = "id_idx"), +@Table(name = "users", indexes = { @Index(columnList = "id", name = "users_id_idx"), @Index(columnList = "username", name = "username_idx") }) public class User implements Serializable { diff --git a/src/main/java/me/kavin/piped/utils/obj/db/Video.java b/src/main/java/me/kavin/piped/utils/obj/db/Video.java index 9d2172c..adc9d5a 100644 --- a/src/main/java/me/kavin/piped/utils/obj/db/Video.java +++ b/src/main/java/me/kavin/piped/utils/obj/db/Video.java @@ -10,8 +10,8 @@ import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity -@Table(name = "videos", indexes = { @Index(columnList = "id", name = "id_idx"), - @Index(columnList = "uploader_id", name = "uploader_id_idx") }) +@Table(name = "videos", indexes = { @Index(columnList = "id", name = "videos_id_idx"), + @Index(columnList = "uploader_id", name = "video_uploader_id_idx") }) public class Video { @Id diff --git a/src/main/resources/hibernate.cfg.xml b/src/main/resources/hibernate.cfg.xml index da2eca0..ac7c317 100644 --- a/src/main/resources/hibernate.cfg.xml +++ b/src/main/resources/hibernate.cfg.xml @@ -11,5 +11,6 @@ org.hibernate.hikaricp.internal.HikariCPConnectionProvider DELAYED_ACQUISITION_AND_RELEASE_AFTER_STATEMENT + 50