Skip to content

Commit

Permalink
Changed javalin to TJS
Browse files Browse the repository at this point in the history
  • Loading branch information
LatvianModder committed Sep 27, 2024
1 parent 4ccb604 commit 5912e43
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 272 deletions.
15 changes: 14 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ tasks.withType(JavaCompile) {

repositories {
mavenCentral()

maven {
url "https://maven.latvian.dev/releases"
content {
includeGroup "dev.latvian.apps"
}
}
}

dependencies {
implementation('net.dv8tion:JDA:5.0.0-beta.21')
implementation('io.javalin:javalin:6.1.3')
implementation('dev.latvian.apps:tiny-java-server:1.0.0-build.7')
implementation('org.mongodb:mongodb-driver-sync:5.0.0')
// implementation('org.slf4j:slf4j-simple:2.0.5')
// implementation('com.google.guava:guava:31.1-jre') { exclude group: "com.google.code.findbugs" }
Expand All @@ -45,7 +52,13 @@ test {
useJUnitPlatform()
}

compileJava {
options.encoding = "UTF-8"
options.release.set(21)
}

java {
sourceCompatibility = targetCompatibility = '21'
withSourcesJar()
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.gradle.jvmargs=-Xmx2G
org.gradle.daemon=false
project_version=1.0.0
project_version=1.1.0
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Wed Dec 18 16:24:02 EET 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/dev/latvian/apps/webutils/html/RootTag.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.latvian.apps.webutils.html;

import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.HttpStatus;
import dev.latvian.apps.tinyserver.http.response.HTTPResponse;
import dev.latvian.apps.tinyserver.http.response.HTTPStatus;

import java.util.List;

Expand Down Expand Up @@ -91,8 +91,8 @@ public void append(StringBuilder builder, boolean header) {
}

@Override
public Response asResponse() {
return asResponse(HttpStatus.OK, true);
public HTTPResponse asResponse() {
return asResponse(HTTPStatus.OK, true);
}

public abstract String getSiteName();
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/dev/latvian/apps/webutils/html/Tag.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dev.latvian.apps.webutils.html;

import dev.latvian.apps.tinyserver.content.MimeType;
import dev.latvian.apps.tinyserver.http.response.HTTPResponse;
import dev.latvian.apps.tinyserver.http.response.HTTPStatus;
import dev.latvian.apps.webutils.ansi.Ansi;
import dev.latvian.apps.webutils.ansi.AnsiComponent;
import dev.latvian.apps.webutils.ansi.Log;
import dev.latvian.apps.webutils.net.FileResponse;
import dev.latvian.apps.webutils.net.MimeType;
import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.HttpStatus;
import org.jetbrains.annotations.Nullable;

import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -132,12 +131,12 @@ default boolean isEmptyRecursively() {
default void replace(Pattern pattern, BiConsumer<Tag, Matcher> replace) {
}

default Response asResponse() {
return asResponse(HttpStatus.OK, false);
default HTTPResponse asResponse() {
return asResponse(HTTPStatus.OK, false);
}

default Response asResponse(HttpStatus status, boolean header) {
return FileResponse.of(status, MimeType.HTML, toTagString(header).getBytes(StandardCharsets.UTF_8));
default HTTPResponse asResponse(HTTPStatus status, boolean header) {
return status.content(toTagString(header).getBytes(StandardCharsets.UTF_8), MimeType.HTML);
}

default Tag string(Object string) {
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/dev/latvian/apps/webutils/html/XMLTag.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package dev.latvian.apps.webutils.html;

import dev.latvian.apps.webutils.net.FileResponse;
import dev.latvian.apps.webutils.net.MimeType;
import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.HttpStatus;
import dev.latvian.apps.tinyserver.content.MimeType;
import dev.latvian.apps.tinyserver.http.response.HTTPResponse;
import dev.latvian.apps.tinyserver.http.response.HTTPStatus;

import java.nio.charset.StandardCharsets;

Expand All @@ -27,12 +26,12 @@ protected XMLTag copy0() {
}

@Override
public Response asResponse() {
return asResponse(HttpStatus.OK, true);
public HTTPResponse asResponse() {
return asResponse(HTTPStatus.OK, true);
}

@Override
public Response asResponse(HttpStatus status, boolean header) {
return FileResponse.of(status, MimeType.XML_TEXT, toTagString(header).getBytes(StandardCharsets.UTF_8));
public HTTPResponse asResponse(HTTPStatus status, boolean header) {
return status.content(toTagString(header).getBytes(StandardCharsets.UTF_8), MimeType.XML_TEXT);
}
}
17 changes: 8 additions & 9 deletions src/main/java/dev/latvian/apps/webutils/json/JSONResponse.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package dev.latvian.apps.webutils.json;

import dev.latvian.apps.webutils.net.FileResponse;
import dev.latvian.apps.webutils.net.MimeType;
import dev.latvian.apps.webutils.net.Response;
import io.javalin.http.HttpStatus;
import dev.latvian.apps.tinyserver.content.MimeType;
import dev.latvian.apps.tinyserver.http.response.HTTPResponse;
import dev.latvian.apps.tinyserver.http.response.HTTPStatus;

import java.nio.charset.StandardCharsets;

public interface JSONResponse {
Response SUCCESS = of(HttpStatus.OK, JSONObject.of("success", true));
HTTPResponse SUCCESS = HTTPStatus.OK.json(JSONObject.of("success", true).toString());

static Response of(HttpStatus status, Object json) {
return FileResponse.of(status, MimeType.JSON, JSON.DEFAULT.write(json).getBytes(StandardCharsets.UTF_8));
static HTTPResponse of(HTTPStatus status, Object json) {
return status.content(JSON.DEFAULT.write(json).getBytes(StandardCharsets.UTF_8), MimeType.JSON);
}

static Response of(Object json) {
return of(HttpStatus.OK, json);
static HTTPResponse of(Object json) {
return of(HTTPStatus.OK, json);
}
}
49 changes: 0 additions & 49 deletions src/main/java/dev/latvian/apps/webutils/net/FileResponse.java

This file was deleted.

18 changes: 0 additions & 18 deletions src/main/java/dev/latvian/apps/webutils/net/MimeType.java

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/java/dev/latvian/apps/webutils/net/NoLogResponse.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/dev/latvian/apps/webutils/net/RedirectResponse.java

This file was deleted.

66 changes: 0 additions & 66 deletions src/main/java/dev/latvian/apps/webutils/net/Response.java

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5912e43

Please sign in to comment.