Skip to content

Commit

Permalink
port
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Jan 17, 2024
1 parent 811c6cf commit 3a081e6
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ public ProviderParser(Key<T> key, T value) {
this.value = value;
}

public T getValue() {
return value;
}

@Override
public T apply(ArgumentStack arg) {
return value;
return getValue();
}

@Override
public T apply(ValueStore store, Object t) {
return value;
return getValue();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public <V extends T> Parser<V> get(Key<V> key) {
return new ProviderParser<>((Key) key, this);
}
if (key.getType() == WebStore.class) {
return new ProviderParser<>((Key) key, new WebStore(this));
return new SupplierParser<>((Key) key, () -> new WebStore(this));
}
if (!key.getAnnotationTypes().isEmpty()) {
Set<Class<?>> types = new LinkedHashSet<>(key.getAnnotationTypes());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package link.locutus.discord.commands.manager.v2.binding;

import java.util.function.Supplier;

public class SupplierParser<T> extends ProviderParser<T> {
public SupplierParser(Key<T> key, Supplier<T> value) {
super(key, (T) value);
}

@Override
public T getValue() {
return ((Supplier<T>) super.getValue()).get();
}
}
16 changes: 9 additions & 7 deletions src/main/java/link/locutus/discord/web/jooby/WebRoot.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package link.locutus.discord.web.jooby;


import com.aayushatharva.brotli4j.Brotli4jLoader;
import gg.jte.ContentType;
import gg.jte.TemplateEngine;
import io.javalin.Javalin;
Expand Down Expand Up @@ -81,12 +82,12 @@ public WebRoot(int portMain, int portHTTPS) {
this.app = Javalin.create(config -> {
config.plugins.register(plugin);
// config.enableCorsForOrigin();
config.compression.brotliAndGzip();
// config.server(() -> {
// Server server = new Server(); // configure this however you want
// LocutusSSLHandler.configureServer(server, portMain, portHTTPS);
// return server;
// });
// check if brotli available
if (Brotli4jLoader.isAvailable()) {
config.compression.brotliAndGzip();
} else {
config.compression.gzipOnly();
}
for (Map.Entry<String, String> entry : staticFileMap.entrySet()) {
config.staticFiles.add(new Consumer<StaticFileConfig>() {
@Override
Expand All @@ -98,7 +99,7 @@ public void accept(StaticFileConfig staticFiles) {
}
});
}
}).start();
}).start(Settings.INSTANCE.WEB.PORT_HTTPS > 0 ? Settings.INSTANCE.WEB.PORT_HTTPS : Settings.INSTANCE.WEB.PORT_HTTP);

System.out.println("Started");

Expand All @@ -107,6 +108,7 @@ public void accept(StaticFileConfig staticFiles) {
this.app.get("/test", new Handler() {
@Override
public void handle(@NotNull Context context) throws Exception {
System.out.println("Test");
pageHandler.handle(context);
}
});
Expand Down
1 change: 0 additions & 1 deletion src/main/jte/alert.jte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@param link.locutus.discord.commands.manager.v2.binding.WebStore ws
@param String title
@param String message

<h1 class="text-primary">${title}</h1>
<p>${message}</p>
2 changes: 0 additions & 2 deletions src/main/jte/main.jte
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
@import link.locutus.discord.web.jooby.WebRoot
@import link.locutus.discord.config.Settings
@import gg.jte.Content

@param WebStore ws
@param Content content
@param String title
@param List<Map.Entry<String, String>> navbar

<!DOCTYPE html>
<html lang="en">
<head>
Expand Down

0 comments on commit 3a081e6

Please sign in to comment.