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;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class WebAppImpl implements WebApp {
|
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;
|
private final Plugin plugin;
|
||||||
|
|
||||||
@ -43,9 +43,10 @@ public String createImage(BufferedImage image, String path) throws IOException {
|
|||||||
Path webRoot = getWebRoot().toAbsolutePath();
|
Path webRoot = getWebRoot().toAbsolutePath();
|
||||||
String separator = webRoot.getFileSystem().getSeparator();
|
String separator = webRoot.getFileSystem().getSeparator();
|
||||||
|
|
||||||
Path webDataRoot = webRoot.resolve("data");
|
Path imageRootFolder = webRoot.resolve(IMAGE_ROOT_PATH);
|
||||||
Path imagePath = webDataRoot.resolve(Path.of(IMAGE_ROOT_PATH, path.replace("/", separator) + ".png")).toAbsolutePath();
|
Path imagePath = imageRootFolder.resolve(Path.of(path.replace("/", separator) + ".png")).toAbsolutePath();
|
||||||
|
|
||||||
|
Files.createDirectories(imagePath.getParent());
|
||||||
Files.deleteIfExists(imagePath);
|
Files.deleteIfExists(imagePath);
|
||||||
Files.createFile(imagePath);
|
Files.createFile(imagePath);
|
||||||
|
|
||||||
@ -64,24 +65,27 @@ public Map<String, String> availableImages() throws IOException {
|
|||||||
|
|
||||||
Map<String, String> availableImagesMap = new HashMap<>();
|
Map<String, String> availableImagesMap = new HashMap<>();
|
||||||
|
|
||||||
try (Stream<Path> fileStream = Files.walk(imageRootPath)){
|
if (Files.exists(imageRootPath)) {
|
||||||
fileStream
|
try (Stream<Path> fileStream = Files.walk(imageRootPath)) {
|
||||||
.filter(p -> !Files.isDirectory(p))
|
fileStream
|
||||||
.filter(p -> p.getFileName().toString().endsWith(".png"))
|
.filter(p -> !Files.isDirectory(p))
|
||||||
.map(Path::toAbsolutePath)
|
.filter(p -> p.getFileName().toString().endsWith(".png"))
|
||||||
.forEach(p -> {
|
.map(Path::toAbsolutePath)
|
||||||
try {
|
.forEach(p -> {
|
||||||
String key = imageRootPath.relativize(p).toString();
|
try {
|
||||||
key = key
|
String key = imageRootPath.relativize(p).toString();
|
||||||
.substring(0, key.length() - 4) //remove .png
|
key = key
|
||||||
.replace(separator, "/");
|
.substring(0, key.length() - 4) //remove .png
|
||||||
|
.replace(separator, "/");
|
||||||
|
|
||||||
String value = webRoot.relativize(p).toString()
|
String value = webRoot.relativize(p).toString()
|
||||||
.replace(separator, "/");
|
.replace(separator, "/");
|
||||||
|
|
||||||
availableImagesMap.put(key, value);
|
availableImagesMap.put(key, value);
|
||||||
} catch (IllegalArgumentException ignore) {}
|
} catch (IllegalArgumentException ignore) {
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return availableImagesMap;
|
return availableImagesMap;
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@ -168,7 +170,9 @@ private void dumpInstance(Object instance, ConfigurationOptions options, Configu
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} 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