This commit is contained in:
Telesphoreo 2022-04-17 18:26:01 -05:00
parent b6b5a7f227
commit 1a139034b5
10 changed files with 49 additions and 55 deletions

View File

@ -8,8 +8,7 @@ import dev.plex.request.impl.IndefBansEndpoint;
import dev.plex.request.impl.IndexEndpoint;
import dev.plex.request.impl.ListEndpoint;
import dev.plex.request.impl.PunishmentsEndpoint;
import dev.plex.request.impl.SchematicDownloadEndpoint;
import dev.plex.request.impl.SchematicIndexEndpoint;
import dev.plex.request.impl.SchematicEndpoint;
import dev.plex.util.PlexLog;
import java.util.concurrent.atomic.AtomicReference;
import lombok.Getter;
@ -72,8 +71,7 @@ public class HTTPDModule extends PlexModule
new IndexEndpoint();
new ListEndpoint();
new PunishmentsEndpoint();
new SchematicDownloadEndpoint();
new SchematicIndexEndpoint();
new SchematicEndpoint();
server.setConnectors(new Connector[]{connector});
server.setHandler(context);

View File

@ -4,18 +4,17 @@ import dev.plex.HTTPDModule;
import dev.plex.request.AbstractServlet;
import dev.plex.request.GetMapping;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import jakarta.servlet.http.HttpServletResponse;
import org.bukkit.Bukkit;
public class SchematicDownloadEndpoint extends AbstractServlet
public class SchematicEndpoint extends AbstractServlet
{
@GetMapping(endpoint = "/api/schematics/download/")
public String downloadSchematics(HttpServletRequest request, HttpServletResponse response)
public String schematicIndex(HttpServletRequest request, HttpServletResponse response)
{
if (request.getPathInfo() == null || request.getPathInfo().equals("/"))
{
@ -24,9 +23,12 @@ public class SchematicDownloadEndpoint extends AbstractServlet
else
{
OutputStream outputStream = null;
try {
try
{
outputStream = response.getOutputStream();
} catch (IOException e) {
}
catch (IOException e)
{
return null;
}
schematicServe(request.getPathInfo().replace("/", ""), outputStream);
@ -53,7 +55,10 @@ public class SchematicDownloadEndpoint extends AbstractServlet
private void schematicServe(String requestedSchematic, OutputStream outputStream)
{
File worldeditFolder = getWorldeditFolder();
if (worldeditFolder == null) return;
if (worldeditFolder == null)
{
return;
}
File[] schems = worldeditFolder.listFiles();
if (schems != null)
{
@ -63,7 +68,10 @@ public class SchematicDownloadEndpoint extends AbstractServlet
try
{
outputStream.write(HTTPDModule.fileCache.getFile(schemFile));
} catch (IOException ignored) {}
}
catch (IOException ignored)
{
}
}
}
}
@ -72,7 +80,10 @@ public class SchematicDownloadEndpoint extends AbstractServlet
{
String file = readFile(this.getClass().getResourceAsStream("/httpd/schematic_list.html"));
File worldeditFolder = getWorldeditFolder();
if (worldeditFolder == null) return null;
if (worldeditFolder == null)
{
return null;
}
StringBuilder sb = new StringBuilder();
File[] alphabetical = worldeditFolder.listFiles();
if (alphabetical != null)

View File

@ -1,15 +0,0 @@
package dev.plex.request.impl;
import dev.plex.request.AbstractServlet;
import dev.plex.request.GetMapping;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
public class SchematicIndexEndpoint extends AbstractServlet
{
@GetMapping(endpoint = "/api/schematics/")
public String schematicIndex(HttpServletRequest request, HttpServletResponse response)
{
return readFile(this.getClass().getResourceAsStream("/httpd/schematic_list.html"));
}
}

View File

@ -26,16 +26,16 @@
<a class="nav-link active" aria-current="page" href="#">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="punishments/">Punishments</a>
<a class="nav-link" href="/api/punishments/">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="schematics/">Schematics</a>
<a class="nav-link" href="/api/schematics/">Schematics</a>
</li>
</ul>
</div>

View File

@ -23,19 +23,19 @@
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="api/admins/">Admins</a>
<a class="nav-link" href="/api/admins/">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="api/indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="api/list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="api/punishments/">Punishments</a>
<a class="nav-link" href="/api/punishments/">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="schematics/">Schematics</a>
<a class="nav-link" href="/api/schematics/">Schematics</a>
</li>
</ul>
</div>

View File

@ -23,19 +23,19 @@
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="admins/">Admins</a>
<a class="nav-link" href="/api/admins/">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="schematics/">Schematics</a>
<a class="nav-link" href="/api/schematics/">Schematics</a>
</li>
</ul>
</div>

View File

@ -23,19 +23,19 @@
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../admins/">Admins</a>
<a class="nav-link" href="/api/admins/">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="schematics/">Schematics</a>
<a class="nav-link" href="/api/schematics/">Schematics</a>
</li>
</ul>
</div>

View File

@ -23,19 +23,19 @@
<a class="nav-link" href="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../admins/">Admins</a>
<a class="nav-link" href="/api/admins/">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link" href="schematics/">Schematics</a>
<a class="nav-link" href="/api/schematics/">Schematics</a>
</li>
</ul>
</div>

View File

@ -26,13 +26,13 @@
<a class="nav-link" href="#">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="punishments/">Punishments</a>
<a class="nav-link" href="/api/punishments/">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Schematics</a>

View File

@ -26,13 +26,13 @@
<a class="nav-link" href="#">Admins</a>
</li>
<li class="nav-item">
<a class="nav-link" href="indefbans/">Indefinite Bans</a>
<a class="nav-link" href="/api/indefbans/">Indefinite Bans</a>
</li>
<li class="nav-item">
<a class="nav-link" href="list/">List</a>
<a class="nav-link" href="/api/list/">List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="punishments/">Punishments</a>
<a class="nav-link" href="/api/punishments/">Punishments</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Schematics</a>