More http server tinkering.

This commit is contained in:
Steven Lawson 2013-09-03 17:47:42 -04:00
parent e70f8ffff3
commit 4bef1a06a4
3 changed files with 80 additions and 62 deletions

View File

@ -149,9 +149,9 @@ public class Module_help extends TFM_HTTPD_Module
return ".commandName{font-weight:bold;}.commandDescription{padding-left:15px;}li{margin:.15em;padding:.15em;}";
}
@Override
public String getScript()
{
return "$(document).ready(function(){console.log(\"Ready\");});";
}
// @Override
// public String getScript()
// {
// return "$(document).ready(function(){console.log(\"Ready\");});";
// }
}

View File

@ -40,6 +40,11 @@ public class Module_schematic extends TFM_HTTPD_Module
@Override
public String getBody()
{
if (!SCHEMATIC_FOLDER.exists())
{
return HTMLGenerationTools.paragraph("Can't find WorldEdit schematic folder.");
}
final StringBuilder out = new StringBuilder();
final String[] args = StringUtils.split(uri, "/");
@ -118,6 +123,8 @@ public class Module_schematic extends TFM_HTTPD_Module
{
final File tempFile = new File(tempFileName);
if (tempFile.exists())
{
if (tempFile.length() <= FileUtils.ONE_KB * 64L)
{
if (SCHEMATIC_FILENAME.matcher(origFileName).find())
{
@ -145,6 +152,11 @@ public class Module_schematic extends TFM_HTTPD_Module
}
}
else
{
throw new SchematicUploadException("Schematic is too big (64kb max).");
}
}
else
{
throw new SchematicUploadException();
}

View File

@ -9,12 +9,12 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.MIME_PLAINTEXT;
import me.StevenLawson.TotalFreedomMod.HTTPD.NanoHTTPD.Response;
import me.StevenLawson.TotalFreedomMod.TFM_ConfigEntry;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit;
public class TFM_HTTPD_Manager
@ -129,6 +129,9 @@ public class TFM_HTTPD_Manager
{
Response response = null;
try
{
final String[] args = StringUtils.split(uri, "/");
final ModuleType moduleType = args.length >= 1 ? ModuleType.getByName(args[0]) : ModuleType.FILE;
@ -175,17 +178,20 @@ public class TFM_HTTPD_Manager
response = new Module_file(uri, method, headers, params, files, socket).getResponse();
}
}
}
catch (Exception ex)
{
response = new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "Error 500: Internal Server Error\r\n" + ex.getMessage() + "\r\n" + ExceptionUtils.getFullStackTrace(ex));
}
if (response == null)
{
return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
response = new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Error 404: Not Found - The requested resource was not found on this server.");
}
else
{
return response;
}
}
}
public static Response serveFileBasic(File file)
{