Updated frontend to new Protocol
This commit is contained in:
@@ -1,36 +1,59 @@
|
||||
package ins.frontend;
|
||||
|
||||
import ins.frontend.utils.WebApp;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_1.beta.web.impl.resource.WebResourceResponsePacket;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketFlags;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_1.beta.WebPacketHeader;
|
||||
import org.openautonomousconnection.webserver.api.Route;
|
||||
import org.openautonomousconnection.webserver.api.WebPage;
|
||||
import org.openautonomousconnection.webserver.api.WebPageContext;
|
||||
import org.openautonomousconnection.webserver.utils.HeaderMaps;
|
||||
import org.openautonomousconnection.webserver.utils.Html;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Landing page for the registrar ins.frontend.
|
||||
* Landing page for INS registrar frontend (v1.0.1).
|
||||
*/
|
||||
@Route(path = "index.html")
|
||||
@Route(path = "/index.html")
|
||||
public final class index implements WebPage {
|
||||
|
||||
@Override
|
||||
public WebResponsePacket handle(WebPageContext ctx) {
|
||||
public WebResourceResponsePacket handle(WebPageContext ctx) {
|
||||
WebApp.init();
|
||||
|
||||
String html = Html.page("OAC INS Registrar", """
|
||||
<div class="card">
|
||||
<h2>OAC INS Registrar</h2>
|
||||
<p class="muted">What you want to do?</p>
|
||||
<div class="col"><a href="info.html">Info</a></div><br />
|
||||
<div class="row">
|
||||
<div class="col"><a href="login.html">Login</a></div>
|
||||
<div class="col"><a href="register.html">Register</a></div>
|
||||
<div class="col"><a href="dashboard.html">Dashboard</a></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>OAC INS Registrar</h2>
|
||||
<p class="muted">What you want to do?</p>
|
||||
<div class="col"><a href="info.html">Info</a></div><br />
|
||||
<div class="row">
|
||||
<div class="col"><a href="login.html">Login</a></div>
|
||||
<div class="col"><a href="register.html">Register</a></div>
|
||||
<div class="col"><a href="dashboard.html">Dashboard</a></div>
|
||||
</div>
|
||||
</div>
|
||||
""");
|
||||
|
||||
return new WebResponsePacket(200, "text/html", new HashMap<>(), Html.utf8(html));
|
||||
byte[] body = Html.utf8(html);
|
||||
Map<String, String> headers = HeaderMaps.mutable();
|
||||
headers.put("content-length", String.valueOf(body.length));
|
||||
|
||||
return new WebResourceResponsePacket(outHeader(ctx), 200, "text/html; charset=utf-8", headers, body, null);
|
||||
}
|
||||
}
|
||||
|
||||
private WebPacketHeader outHeader(WebPageContext ctx) {
|
||||
WebPacketHeader in = (ctx != null && ctx.request != null) ? ctx.request.getHeader() : null;
|
||||
if (in == null) {
|
||||
return new WebPacketHeader(0, 0, 0, 0, WebPacketFlags.RESOURCE, System.currentTimeMillis());
|
||||
}
|
||||
return new WebPacketHeader(
|
||||
in.getRequestId(),
|
||||
in.getTabId(),
|
||||
in.getPageId(),
|
||||
in.getFrameId(),
|
||||
in.getFlags() | WebPacketFlags.RESOURCE,
|
||||
System.currentTimeMillis()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user