mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Use int values for canvas size
This commit is contained in:
@@ -204,6 +204,7 @@ public class ChannelDirectoryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CanvasSettingsRequest updateCanvasSettings(String broadcaster, CanvasSettingsRequest req, String actor) {
|
public CanvasSettingsRequest updateCanvasSettings(String broadcaster, CanvasSettingsRequest req, String actor) {
|
||||||
|
validateCanvasSettings(req);
|
||||||
Channel channel = getOrCreateChannel(broadcaster);
|
Channel channel = getOrCreateChannel(broadcaster);
|
||||||
double beforeWidth = channel.getCanvasWidth();
|
double beforeWidth = channel.getCanvasWidth();
|
||||||
double beforeHeight = channel.getCanvasHeight();
|
double beforeHeight = channel.getCanvasHeight();
|
||||||
@@ -230,6 +231,30 @@ public class ChannelDirectoryService {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateCanvasSettings(CanvasSettingsRequest req) {
|
||||||
|
Settings settings = settingsService.get();
|
||||||
|
int canvasMaxSizePixels = settings.getMaxCanvasSideLengthPixels();
|
||||||
|
|
||||||
|
if (
|
||||||
|
req.getWidth() <= 0 ||
|
||||||
|
req.getWidth() > canvasMaxSizePixels ||
|
||||||
|
!Double.isFinite(req.getWidth()) ||
|
||||||
|
req.getWidth() % 1 != 0
|
||||||
|
) throw new ResponseStatusException(
|
||||||
|
BAD_REQUEST,
|
||||||
|
"Canvas width must be a whole number within [1 to " + canvasMaxSizePixels + "]"
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
req.getHeight() <= 0 ||
|
||||||
|
req.getHeight() > canvasMaxSizePixels ||
|
||||||
|
!Double.isFinite(req.getHeight()) ||
|
||||||
|
req.getHeight() % 1 != 0
|
||||||
|
) throw new ResponseStatusException(
|
||||||
|
BAD_REQUEST,
|
||||||
|
"Canvas height must be a whole number within [1 to " + canvasMaxSizePixels + "]"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public ChannelScriptSettingsRequest getChannelScriptSettings(String broadcaster) {
|
public ChannelScriptSettingsRequest getChannelScriptSettings(String broadcaster) {
|
||||||
Channel channel = getOrCreateChannel(broadcaster);
|
Channel channel = getOrCreateChannel(broadcaster);
|
||||||
return new ChannelScriptSettingsRequest(
|
return new ChannelScriptSettingsRequest(
|
||||||
|
|||||||
@@ -216,12 +216,16 @@ async function fetchCanvasSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function saveCanvasSettings() {
|
async function saveCanvasSettings() {
|
||||||
const width = parseFloat(elements.canvasWidth?.value) || 0;
|
const width = Number(elements.canvasWidth?.value);
|
||||||
const height = parseFloat(elements.canvasHeight?.value) || 0;
|
const height = Number(elements.canvasHeight?.value);
|
||||||
if (width <= 0 || height <= 0) {
|
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
|
||||||
showToast("Please enter a valid width and height.", "info");
|
showToast("Please enter a valid width and height.", "info");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!Number.isInteger(width) || !Number.isInteger(height)) {
|
||||||
|
showToast("Please enter whole-number dimensions for the canvas size.", "info");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (elements.canvasStatus) elements.canvasStatus.textContent = "Saving...";
|
if (elements.canvasStatus) elements.canvasStatus.textContent = "Saving...";
|
||||||
setButtonBusy(elements.canvasSaveButton, true, "Saving...");
|
setButtonBusy(elements.canvasSaveButton, true, "Saving...");
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user