mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-02-15 08:08:42 -06:00
[DASHBOARD] verify image link supplied is valid.
This commit is contained in:
@@ -216,7 +216,7 @@ public class EventEndpoint {
|
||||
|
||||
Event event = new Event();
|
||||
event.setId(eventId);
|
||||
event.setVisibility("web/public");
|
||||
event.setVisibility("public");
|
||||
event.setSummary(body.getString("summary"));
|
||||
event.setDescription(body.getString("description"));
|
||||
|
||||
@@ -249,10 +249,21 @@ public class EventEndpoint {
|
||||
}
|
||||
|
||||
EventData ed = new EventData(settings.getGuildID());
|
||||
if (!body.getString("image").equalsIgnoreCase("") && ImageUtils.validate(body.getString("image"))) {
|
||||
if (!body.getString("image").equalsIgnoreCase("")) {
|
||||
ed.setImageLink(body.getString("image"));
|
||||
ed.setEventId(eventId);
|
||||
ed.setEventEnd(event.getEnd().getDateTime().getValue());
|
||||
|
||||
if (!ImageUtils.validate(ed.getImageLink())) {
|
||||
response.status(400);
|
||||
JSONObject respondBody = new JSONObject();
|
||||
respondBody.put("Message", "Failed to create event!");
|
||||
respondBody.put("reason", "Invalid image link and/or GIF image not supported.");
|
||||
|
||||
response.body(respondBody.toString());
|
||||
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
|
||||
if (ed.shouldBeSaved()) {
|
||||
@@ -268,8 +279,11 @@ public class EventEndpoint {
|
||||
Logger.getLogger().exception(null, "[WEB] Failed to update event!", e, EventEndpoint.class, true);
|
||||
e.printStackTrace();
|
||||
|
||||
response.status(500);
|
||||
response.body(ResponseUtils.getJsonResponseMessage("Failed to update event!"));
|
||||
JSONObject respondBody = new JSONObject();
|
||||
respondBody.put("Message", "Failed to create event!");
|
||||
respondBody.put("reason", "Google API may be at fault. Please try again.");
|
||||
|
||||
response.body(respondBody.toString());
|
||||
}
|
||||
|
||||
return response.body();
|
||||
@@ -289,7 +303,7 @@ public class EventEndpoint {
|
||||
settings = DatabaseManager.getManager().getSettings(guildId);
|
||||
}
|
||||
|
||||
//Okay, time to update the event
|
||||
//Okay, time to create the event
|
||||
try {
|
||||
Calendar service;
|
||||
if (settings.useExternalCalendar()) {
|
||||
@@ -302,7 +316,7 @@ public class EventEndpoint {
|
||||
|
||||
Event event = new Event();
|
||||
event.setId(KeyGenerator.generateEventId());
|
||||
event.setVisibility("web/public");
|
||||
event.setVisibility("public");
|
||||
event.setSummary(body.getString("summary"));
|
||||
event.setDescription(body.getString("description"));
|
||||
|
||||
@@ -335,11 +349,23 @@ public class EventEndpoint {
|
||||
}
|
||||
|
||||
EventData ed = new EventData(settings.getGuildID());
|
||||
if (!body.getString("image").equalsIgnoreCase("") && ImageUtils.validate(body.getString("image"))) {
|
||||
if (!body.getString("image").equalsIgnoreCase("")) {
|
||||
ed.setImageLink(body.getString("image"));
|
||||
ed.setEventEnd(event.getEnd().getDateTime().getValue());
|
||||
|
||||
if (!ImageUtils.validate(ed.getImageLink())) {
|
||||
response.status(400);
|
||||
JSONObject respondBody = new JSONObject();
|
||||
respondBody.put("Message", "Failed to create event!");
|
||||
respondBody.put("reason", "Invalid image link and/or GIF image not supported.");
|
||||
|
||||
response.body(respondBody.toString());
|
||||
|
||||
return response.body();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ed.shouldBeSaved()) {
|
||||
DatabaseManager.getManager().updateEventData(ed);
|
||||
}
|
||||
@@ -354,11 +380,14 @@ public class EventEndpoint {
|
||||
response.body(respondBody.toString());
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.getLogger().exception(null, "[WEB] Failed to update event!", e, EventEndpoint.class, true);
|
||||
Logger.getLogger().exception(null, "[WEB] Failed to create event!", e, EventEndpoint.class, true);
|
||||
e.printStackTrace();
|
||||
|
||||
response.status(500);
|
||||
response.body(ResponseUtils.getJsonResponseMessage("Failed to update event!"));
|
||||
JSONObject respondBody = new JSONObject();
|
||||
respondBody.put("Message", "Failed to create event!");
|
||||
respondBody.put("reason", "Google API may be at fault. Please try again.");
|
||||
|
||||
response.body(respondBody.toString());
|
||||
}
|
||||
|
||||
return response.body();
|
||||
|
||||
@@ -606,21 +606,30 @@ function updateEvent(editSubmitId) {
|
||||
};
|
||||
}
|
||||
|
||||
var q = $.post("/api/v1/events/update", JSON.stringify(bodyRaw), function (response) {
|
||||
$.ajax({
|
||||
url: "/api/v1/events/update",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(bodyRaw),
|
||||
success: function (data) {
|
||||
$('#modal-' + bodyRaw.id).modal('hide');
|
||||
|
||||
$('#modal-' + bodyRaw.id).modal('hide');
|
||||
showSnackbar("Event successfully updated!");
|
||||
|
||||
showSnackbar("Event successfully updated!");
|
||||
setMonth({date: calendar.selectedDate});
|
||||
getEventsForMonth();
|
||||
|
||||
setMonth({date: calendar.selectedDate});
|
||||
getEventsForMonth();
|
||||
|
||||
getEventsForSelectedDate();
|
||||
})
|
||||
.fail(function () {
|
||||
showSnackbar("Our hippos failed to update your event!");
|
||||
}, "json");
|
||||
getEventsForSelectedDate();
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
var obj = JSON.parse(jqXHR.responseText);
|
||||
|
||||
showSnackbar("[ERROR] " + obj.reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createNewEvent() {
|
||||
@@ -658,23 +667,34 @@ function createNewEvent() {
|
||||
"epochEnd": endDate.getTime() + timeOffset
|
||||
};
|
||||
|
||||
var q = $.post("/api/v1/events/create", JSON.stringify(bodyRaw), function (response) {
|
||||
showSnackbar("Event successfully created!");
|
||||
$.ajax({
|
||||
url: "/api/v1/events/create",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
method: "POST",
|
||||
dataType: "json",
|
||||
data: JSON.stringify(bodyRaw),
|
||||
success: function (data) {
|
||||
showSnackbar("Event successfully created!");
|
||||
|
||||
$('html:not(:animated), body:not(:animated)').animate({
|
||||
scrollTop: $("#calendar").offset().top
|
||||
}, 2000);
|
||||
$('html:not(:animated), body:not(:animated)').animate({
|
||||
scrollTop: $("#calendar").offset().top
|
||||
}, 2000);
|
||||
|
||||
document.getElementById("create-form").reset();
|
||||
document.getElementById("create-form").reset();
|
||||
|
||||
setMonth({date: calendar.selectedDate});
|
||||
getEventsForMonth();
|
||||
setMonth({date: calendar.selectedDate});
|
||||
getEventsForMonth();
|
||||
|
||||
getEventsForSelectedDate();
|
||||
})
|
||||
.fail(function () {
|
||||
showSnackbar("Our hippos failed to create your event!");
|
||||
}, "json");
|
||||
getEventsForSelectedDate();
|
||||
},
|
||||
error: function (jqXHR, textStatus, errorThrown) {
|
||||
var obj = JSON.parse(jqXHR.responseText);
|
||||
|
||||
showSnackbar("[ERROR] " + obj.reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteEvent(clickedId) {
|
||||
|
||||
Reference in New Issue
Block a user