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) {
|
||||
validateCanvasSettings(req);
|
||||
Channel channel = getOrCreateChannel(broadcaster);
|
||||
double beforeWidth = channel.getCanvasWidth();
|
||||
double beforeHeight = channel.getCanvasHeight();
|
||||
@@ -230,6 +231,30 @@ public class ChannelDirectoryService {
|
||||
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) {
|
||||
Channel channel = getOrCreateChannel(broadcaster);
|
||||
return new ChannelScriptSettingsRequest(
|
||||
|
||||
@@ -216,12 +216,16 @@ async function fetchCanvasSettings() {
|
||||
}
|
||||
|
||||
async function saveCanvasSettings() {
|
||||
const width = parseFloat(elements.canvasWidth?.value) || 0;
|
||||
const height = parseFloat(elements.canvasHeight?.value) || 0;
|
||||
if (width <= 0 || height <= 0) {
|
||||
const width = Number(elements.canvasWidth?.value);
|
||||
const height = Number(elements.canvasHeight?.value);
|
||||
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
|
||||
showToast("Please enter a valid width and height.", "info");
|
||||
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...";
|
||||
setButtonBusy(elements.canvasSaveButton, true, "Saving...");
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user