Skip to content

Commit e4f97da

Browse files
Release 1.6.0 (#120)
2 parents cc03f35 + 41ac12c commit e4f97da

40 files changed

+637
-641
lines changed

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
allowed-conclusions: success
2525
- name: Checkout
2626
uses: actions/checkout@v4
27-
- uses: gradle/wrapper-validation-action@v1
27+
- uses: gradle/wrapper-validation-action@v3
2828
- name: Login to GitHub Packages
2929
uses: docker/login-action@v3
3030
with:

.github/workflows/verify.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
steps:
1111
- uses: actions/checkout@v4
12-
- uses: gradle/wrapper-validation-action@v1
12+
- uses: gradle/wrapper-validation-action@v3
1313
- name: Set up JDK 18
1414
uses: actions/setup-java@v4
1515
with:

build.gradle.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "de.chojo"
9-
version = "1.5.0"
9+
version = "1.6.0"
1010

1111
repositories {
1212
mavenCentral()
@@ -21,14 +21,14 @@ dependencies {
2121
}
2222

2323
// database
24-
implementation("org.postgresql", "postgresql", "42.7.1")
24+
implementation("org.postgresql", "postgresql", "42.7.3")
2525
implementation(libs.bundles.sadu)
2626

2727
// Download api
2828
implementation("de.chojo", "nexus-api-wrapper", "1.0.5")
2929

3030
// Mailing
31-
implementation("org.eclipse.angus", "angus-mail", "2.0.2")
31+
implementation("org.eclipse.angus", "angus-mail", "2.0.3")
3232
implementation("org.jsoup", "jsoup", "1.17.2")
3333

3434

@@ -39,7 +39,7 @@ dependencies {
3939
}
4040

4141
// unit testing
42-
testImplementation(platform("org.junit:junit-bom:5.10.1"))
42+
testImplementation(platform("org.junit:junit-bom:5.10.2"))
4343
testImplementation("org.junit.jupiter", "junit-jupiter")
4444
testImplementation("org.mockito", "mockito-core", "5.+")
4545
}

gradle/wrapper/gradle-wrapper.jar

-9 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
# Darwin, MinGW, and NonStop.
5656
#
5757
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
58+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5959
# within the Gradle project.
6060
#
6161
# You can find Gradle at https://github.com/gradle/gradle/.

gradlew.bat

+10-10
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
4343
%JAVA_EXE% -version >NUL 2>&1
4444
if %ERRORLEVEL% equ 0 goto execute
4545

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
46+
echo. 1>&2
47+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
48+
echo. 1>&2
49+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
50+
echo location of your Java installation. 1>&2
5151

5252
goto fail
5353

@@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5757

5858
if exist "%JAVA_EXE%" goto execute
5959

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
60+
echo. 1>&2
61+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
62+
echo. 1>&2
63+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
64+
echo location of your Java installation. 1>&2
6565

6666
goto fail
6767

settings.gradle.kts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ dependencyResolutionManagement {
55
create("libs") {
66
// misc
77
library("jetbrains-annotations", "org.jetbrains:annotations:24.1.0")
8-
version("sadu", "1.4.0")
8+
version("sadu", "2.2.0")
99
library("sadu-queries", "de.chojo.sadu", "sadu-queries").versionRef("sadu")
1010
library("sadu-updater", "de.chojo.sadu", "sadu-updater").versionRef("sadu")
1111
library("sadu-postgresql", "de.chojo.sadu", "sadu-postgresql").versionRef("sadu")
1212
library("sadu-datasource", "de.chojo.sadu", "sadu-datasource").versionRef("sadu")
1313
bundle("sadu", listOf("sadu-queries", "sadu-updater", "sadu-postgresql", "sadu-datasource"))
1414

15-
version("log4j", "2.22.1")
15+
version("log4j", "2.23.1")
1616

17-
library("slf4j-api", "org.slf4j:slf4j-api:2.0.11")
17+
library("slf4j-api", "org.slf4j:slf4j-api:2.0.13")
1818
library("log4j-core", "org.apache.logging.log4j", "log4j-core").versionRef("log4j")
1919
library("log4j-slf4j2", "org.apache.logging.log4j", "log4j-slf4j2-impl").versionRef("log4j")
2020
library("log4j-jsontemplate","org.apache.logging.log4j", "log4j-layout-template-json").versionRef("log4j")
2121
bundle("log4j", listOf("slf4j-api", "log4j-core", "log4j-slf4j2", "log4j-jsontemplate"))
2222

2323
// plugins
24-
plugin("spotless", "com.diffplug.spotless").version("6.24.0")
24+
plugin("spotless", "com.diffplug.spotless").version("6.25.0")
2525
plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1")
2626

2727
}

src/main/java/de/chojo/lyna/Lyna.java

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
import java.io.IOException;
1212
import java.sql.SQLException;
13+
import java.util.ArrayList;
14+
import java.util.concurrent.CompletableFuture;
15+
import java.util.concurrent.ExecutorService;
16+
import java.util.concurrent.Executors;
17+
import java.util.stream.IntStream;
18+
import java.util.stream.Stream;
1319

1420
public class Lyna {
1521
private static Lyna instance;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package de.chojo.lyna.api.v1.download.proxy;
22

3-
public record AssetDownload(String assetId, Runnable postDownload) {
3+
public record AssetDownload(String assetId, Runnable postDownload, String userId) {
44
}

src/main/java/de/chojo/lyna/api/v1/download/proxy/Proxy.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import com.google.common.cache.Cache;
44
import com.google.common.cache.CacheBuilder;
55
import com.google.common.hash.Hashing;
6+
import de.chojo.jdautil.util.SnowflakeCreator;
67
import de.chojo.lyna.api.v1.download.Download;
8+
import de.chojo.lyna.util.JarUtil;
79
import io.javalin.http.ContentType;
810
import io.javalin.http.HttpCode;
911
import org.intellij.lang.annotations.Language;
1012

1113
import java.nio.charset.StandardCharsets;
1214
import java.util.Locale;
15+
import java.util.Map;
1316
import java.util.concurrent.TimeUnit;
1417

1518
import static io.javalin.apibuilder.ApiBuilder.get;
@@ -44,6 +47,7 @@ public class Proxy {
4447
</html>
4548
4649
""";
50+
private final SnowflakeCreator snowflakeCreator = SnowflakeCreator.builder().build();
4751

4852
public Proxy(Download download) {
4953
this.download = download;
@@ -79,11 +83,20 @@ public void init() {
7983

8084
download.postDownload().run();
8185

86+
Map<String, String> replacements = Map.of(
87+
"%%__USER__%%", download.userId(),
88+
"%%__RESOURCE__%%", download.assetId(),
89+
"%%__NONCE__%%", snowflakeCreator.nextString()
90+
);
91+
92+
var complete = asset.downloadStream().complete();
93+
var replacedJarFile = JarUtil.replaceStringsInJar(complete, replacements);
94+
8295
ctx.header("Content-Disposition", "attachment; filename=\"%s\"".formatted(filename))
8396
.header("X-Content-Type-Options", "nosniff")
8497
.contentType(ContentType.APPLICATION_OCTET_STREAM)
8598
.status(HttpCode.OK)
86-
.result(asset.downloadStream().complete());
99+
.result(replacedJarFile);
87100
});
88101
});
89102
}

src/main/java/de/chojo/lyna/commands/download/handler/Default.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
101101

102102
String typeId = ctx.event().getInteraction().getSelectedOptions().get(0).getValue();
103103
var downloadType = product.products().licenseGuild().downloadTypes().byId(Integer.parseInt(typeId)).get();
104-
var versionMenu = getVersionMenu(product, downloadType);
104+
var versionMenu = getVersionMenu(member,product, downloadType);
105105
if (versionMenu.isEmpty()) {
106106
ctx.refresh("No build of this type found. Please choose another one.");
107107
return;
@@ -113,7 +113,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
113113
}));
114114
}
115115

116-
private Optional<MenuEntry<?, ?>> getVersionMenu(Product product, DownloadType downloadType) {
116+
private Optional<MenuEntry<?, ?>> getVersionMenu(Member member, Product product, DownloadType downloadType) {
117117
var download = product.downloads().byType(downloadType).get();
118118
StringSelectMenu.Builder versionMenu = StringSelectMenu.create("version")
119119
.setMinValues(1)
@@ -132,7 +132,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
132132
String assetId = ctx.event().getInteraction().getSelectedOptions().get(0).getValue();
133133
AssetXO asset = assets.stream().filter(assetXO -> assetXO.id().equals(assetId)).findFirst().get();
134134
String url = api.v1().download().proxy()
135-
.registerAsset(new AssetDownload(assetId, () -> download.downloaded(asset.maven2().version())));
135+
.registerAsset(new AssetDownload(assetId, () -> download.downloaded(asset.maven2().version()), "%s(%s)".formatted(member.getUser().getName(), member.getId())));
136136
ctx.container().entries().add(MenuEntry.of(Button.of(ButtonStyle.LINK, url, "Download", Emoji.fromUnicode("⬇️")), c -> {
137137
}));
138138
ctx.entry().hidden();
@@ -141,8 +141,9 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
141141
MessageEmbed build = new EmbedBuilder()
142142
.setTitle("📦 " + filename)
143143
.addField("Size", humanReadableByteCountSI(asset.fileSize()), true)
144-
.addField("Md5", asset.checksum().md5(), true)
145-
.addField("Sha256", asset.checksum().sha256(), true)
144+
// TODO: Files are individual per user. Therefore a static hash can't be used.
145+
//.addField("Md5", asset.checksum().md5(), true)
146+
//.addField("Sha256", asset.checksum().sha256(), true)
146147
.setColor(Colors.Strong.PINK)
147148
.setFooter("This is a one time use link. Do not distribute.")
148149
.build();

src/main/java/de/chojo/lyna/commands/info/handler/Default.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import de.chojo.jdautil.util.Colors;
1212
import de.chojo.jdautil.wrapper.EventContext;
1313
import de.chojo.lyna.configuration.ConfigFile;
14-
import de.chojo.lyna.data.access.Guilds;
1514
import net.dv8tion.jda.api.entities.MessageEmbed;
1615
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
1716
import org.jetbrains.annotations.NotNull;
@@ -43,7 +42,7 @@ public class Default implements SlashHandler {
4342
private String contributors;
4443
private Instant lastFetch = Instant.MIN;
4544

46-
public Default(String version, Configuration configuration) {
45+
public Default(String version, Configuration<ConfigFile> configuration) {
4746
this.version = version;
4847
this.configuration = configuration;
4948
}

src/main/java/de/chojo/lyna/commands/trial/handler/Default.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public void onSlashCommand(SlashCommandInteractionEvent event, EventContext cont
138138
String url = api.v1().download().proxy().registerAsset(new AssetDownload(asset.id(), () -> {
139139
download.downloaded(asset.maven2().version());
140140
product.claimTrial(member);
141-
}));
141+
},"%s(%s)".formatted(member.getUser().getName(), member.getId())));
142142
ctx.entry().hidden();
143143

144144
ctx.container().entries().add(MenuEntry.of(Button.of(ButtonStyle.LINK, url, "Download", Emoji.fromUnicode("⬇️")), c -> {

src/main/java/de/chojo/lyna/core/Data.java

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
import de.chojo.logutil.marker.LogNotify;
66
import de.chojo.lyna.configuration.ConfigFile;
77
import de.chojo.lyna.configuration.elements.Nexus;
8-
import de.chojo.lyna.data.StaticQueryAdapter;
98
import de.chojo.lyna.data.access.Guilds;
109
import de.chojo.lyna.data.access.KoFiProducts;
1110
import de.chojo.lyna.data.access.Mailings;
1211
import de.chojo.lyna.data.access.Products;
1312
import de.chojo.nexus.NexusRest;
14-
import de.chojo.sadu.databases.PostgreSql;
1513
import de.chojo.sadu.datasource.DataSourceCreator;
14+
import de.chojo.sadu.postgresql.databases.PostgreSql;
15+
import de.chojo.sadu.queries.configuration.QueryConfiguration;
1616
import de.chojo.sadu.updater.QueryReplacement;
1717
import de.chojo.sadu.updater.SqlUpdater;
18-
import de.chojo.sadu.wrapper.QueryBuilderConfig;
1918
import org.slf4j.Logger;
2019

2120
import java.io.IOException;
@@ -46,17 +45,11 @@ public static Data create(Threading threading, Configuration<ConfigFile> configu
4645
}
4746

4847
public void init() throws SQLException, IOException, InterruptedException {
49-
configure();
5048
initConnection();
49+
configure();
5150
updateDatabase();
52-
initSaduAdapter();
5351
initDao();
5452
}
55-
56-
private void initSaduAdapter() {
57-
StaticQueryAdapter.start(dataSource);
58-
}
59-
6053
public void initConnection() {
6154
try {
6255
dataSource = getConnectionPool();
@@ -82,9 +75,8 @@ private void updateDatabase() throws IOException, SQLException {
8275
private void configure() {
8376
log.info("Configuring QueryBuilder");
8477
var logger = getLogger("DbLogger");
85-
QueryBuilderConfig.setDefault(QueryBuilderConfig.builder()
86-
.withExceptionHandler(err -> logger.error(LogNotify.NOTIFY_ADMIN, "An error occurred during a database request", err))
87-
.withExecutor(threading.botWorker())
78+
QueryConfiguration.setDefault(QueryConfiguration.builder(dataSource)
79+
.setExceptionHandler(err -> logger.error(LogNotify.NOTIFY_ADMIN, "An error occurred during a database request", err))
8880
.build());
8981
}
9082

src/main/java/de/chojo/lyna/data/StaticQueryAdapter.java

-52
This file was deleted.

0 commit comments

Comments
 (0)