mirror of
https://github.com/zadam/trilium.git
synced 2025-01-15 19:51:57 +08:00
don't allow setting image quality to empty value, #3894
This commit is contained in:
parent
331d280075
commit
cc1f831a6a
3 changed files with 9 additions and 5 deletions
|
@ -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;
|
||||||
|
|
|
@ -10,7 +10,7 @@ function getOptionOrNull(name) {
|
||||||
// e.g. in initial sync becca is not loaded because DB is not initialized
|
// e.g. in initial sync becca is not loaded because DB is not initialized
|
||||||
option = sql.getRow("SELECT * FROM options WHERE name = ?", name);
|
option = sql.getRow("SELECT * FROM options WHERE name = ?", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return option ? option.value : null;
|
return option ? option.value : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)) {
|
||||||
throw new Error(`Could not parse "${val}" into integer for option "${name}"`);
|
if (defaultValue === undefined) {
|
||||||
|
throw new Error(`Could not parse "${val}" into integer for option "${name}"`);
|
||||||
|
} else {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return intVal;
|
return intVal;
|
||||||
|
|
Loading…
Reference in a new issue