Code cleanup

This commit is contained in:
SinTan1729
2022-11-10 23:19:42 -06:00
parent 53ba9eb129
commit e5f1839822
3 changed files with 27 additions and 26 deletions

View File

@@ -36,7 +36,7 @@ public class App {
get("/all", Routes::getAll);
post("/new", Routes::addUrl);
delete("/:shortUrl", Routes::delete);
get("/siteUrl", Routes::siteUrl);
get("/site", Routes::getSiteUrl);
});
get("/:shortUrl", Routes::goToLongUrl);

View File

@@ -18,17 +18,16 @@ public class Routes {
public static String addUrl(Request req, Response res) {
var body = req.body();
if (body.endsWith(";")) {
body = body + "$";
}
var split = body.split(";");
String longUrl = split[0];
if (split[1].equals("$")) {
split[1] = Utils.randomString();
String shortUrl;
try {
shortUrl = split[1];
} catch (ArrayIndexOutOfBoundsException e) {
shortUrl = Utils.randomString();
}
String shortUrl = split[1];
shortUrl = shortUrl.toLowerCase();
var shortUrlPresent = urlRepository
@@ -42,7 +41,7 @@ public class Routes {
}
}
public static String siteUrl(Request req, Response res) {
public static String getSiteUrl(Request req, Response res) {
return System.getenv().getOrDefault("site_url", "unset");
}