mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
don't allow setting image quality to empty value, #3894
This commit is contained in:
parent
331d280075
commit
cc1f831a6a
@ -48,7 +48,7 @@ export default class ImageOptions extends OptionsWidget {
|
|||||||
this.updateOption('imageMaxWidthHeight', this.$imageMaxWidthHeight.val()));
|
this.updateOption('imageMaxWidthHeight', this.$imageMaxWidthHeight.val()));
|
||||||
|
|
||||||
this.$imageJpegQuality.on('change', () =>
|
this.$imageJpegQuality.on('change', () =>
|
||||||
this.updateOption('imageJpegQuality', this.$imageJpegQuality.val()));
|
this.updateOption('imageJpegQuality', this.$imageJpegQuality.val().trim() || "75"));
|
||||||
|
|
||||||
this.$downloadImagesAutomatically = this.$widget.find(".download-images-automatically");
|
this.$downloadImagesAutomatically = this.$widget.find(".download-images-automatically");
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch,
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function shrinkImage(buffer, originalName) {
|
async function shrinkImage(buffer, originalName) {
|
||||||
let jpegQuality = optionService.getOptionInt('imageJpegQuality');
|
let jpegQuality = optionService.getOptionInt('imageJpegQuality', 0);
|
||||||
|
|
||||||
if (jpegQuality < 10 || jpegQuality > 100) {
|
if (jpegQuality < 10 || jpegQuality > 100) {
|
||||||
jpegQuality = 75;
|
jpegQuality = 75;
|
||||||
|
@ -27,13 +27,17 @@ function getOption(name) {
|
|||||||
/**
|
/**
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function getOptionInt(name) {
|
function getOptionInt(name, defaultValue = undefined) {
|
||||||
const val = getOption(name);
|
const val = getOption(name);
|
||||||
|
|
||||||
const intVal = parseInt(val);
|
const intVal = parseInt(val);
|
||||||
|
|
||||||
if (isNaN(intVal)) {
|
if (isNaN(intVal)) {
|
||||||
|
if (defaultValue === undefined) {
|
||||||
throw new Error(`Could not parse "${val}" into integer for option "${name}"`);
|
throw new Error(`Could not parse "${val}" into integer for option "${name}"`);
|
||||||
|
} else {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return intVal;
|
return intVal;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user