mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-11-22 10:35:16 +01:00
Fix web-app api throwing an error and add full errors to the StateDumper
This commit is contained in:
parent
38f23f2374
commit
d4f00682a6
@ -14,7 +14,7 @@
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class WebAppImpl implements WebApp {
|
||||
private static final String IMAGE_ROOT_PATH = "images";
|
||||
private static final Path IMAGE_ROOT_PATH = Path.of("data", "images");
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
@ -43,9 +43,10 @@ public String createImage(BufferedImage image, String path) throws IOException {
|
||||
Path webRoot = getWebRoot().toAbsolutePath();
|
||||
String separator = webRoot.getFileSystem().getSeparator();
|
||||
|
||||
Path webDataRoot = webRoot.resolve("data");
|
||||
Path imagePath = webDataRoot.resolve(Path.of(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
|
||||
Path imageRootFolder = webRoot.resolve(IMAGE_ROOT_PATH);
|
||||
Path imagePath = imageRootFolder.resolve(Path.of(path.replace("/", separator) + ".png")).toAbsolutePath();
|
||||
|
||||
Files.createDirectories(imagePath.getParent());
|
||||
Files.deleteIfExists(imagePath);
|
||||
Files.createFile(imagePath);
|
||||
|
||||
@ -64,24 +65,27 @@ public Map<String, String> availableImages() throws IOException {
|
||||
|
||||
Map<String, String> availableImagesMap = new HashMap<>();
|
||||
|
||||
try (Stream<Path> fileStream = Files.walk(imageRootPath)){
|
||||
fileStream
|
||||
.filter(p -> !Files.isDirectory(p))
|
||||
.filter(p -> p.getFileName().toString().endsWith(".png"))
|
||||
.map(Path::toAbsolutePath)
|
||||
.forEach(p -> {
|
||||
try {
|
||||
String key = imageRootPath.relativize(p).toString();
|
||||
key = key
|
||||
.substring(0, key.length() - 4) //remove .png
|
||||
.replace(separator, "/");
|
||||
if (Files.exists(imageRootPath)) {
|
||||
try (Stream<Path> fileStream = Files.walk(imageRootPath)) {
|
||||
fileStream
|
||||
.filter(p -> !Files.isDirectory(p))
|
||||
.filter(p -> p.getFileName().toString().endsWith(".png"))
|
||||
.map(Path::toAbsolutePath)
|
||||
.forEach(p -> {
|
||||
try {
|
||||
String key = imageRootPath.relativize(p).toString();
|
||||
key = key
|
||||
.substring(0, key.length() - 4) //remove .png
|
||||
.replace(separator, "/");
|
||||
|
||||
String value = webRoot.relativize(p).toString()
|
||||
.replace(separator, "/");
|
||||
String value = webRoot.relativize(p).toString()
|
||||
.replace(separator, "/");
|
||||
|
||||
availableImagesMap.put(key, value);
|
||||
} catch (IllegalArgumentException ignore) {}
|
||||
});
|
||||
availableImagesMap.put(key, value);
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return availableImagesMap;
|
||||
|
@ -32,6 +32,8 @@
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
@ -168,7 +170,9 @@ private void dumpInstance(Object instance, ConfigurationOptions options, Configu
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
node.set("Error: " + ex);
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
ex.printStackTrace(new PrintWriter(stringWriter));
|
||||
node.set("Error: " + ex + " >> " + stringWriter);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user