diff --git a/changelog/76_UNRELEASED_xxxx-xx-xx.md b/changelog/76_UNRELEASED_xxxx-xx-xx.md index 66c69666..8e383116 100644 --- a/changelog/76_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/76_UNRELEASED_xxxx-xx-xx.md @@ -59,4 +59,4 @@ ### API -- xxx +- Optimized that uploading files where the file name contains non-ASCII characters is now also possible diff --git a/public/js/extensions.js b/public/js/extensions.js index 2c694917..a0e81fb9 100644 --- a/public/js/extensions.js +++ b/public/js/extensions.js @@ -205,6 +205,9 @@ function CleanFileName(fileName) // Multiple spaces seem to be a problem, so simply strip them all fileName = fileName.replace(/\s+/g, ""); + // Remove any non-ASCII character + fileName = fileName.replace(/[^\x00-\x7F]/g, ""); + return fileName; } diff --git a/public/viewjs/equipmentform.js b/public/viewjs/equipmentform.js index 498d431c..6675a5c6 100644 --- a/public/viewjs/equipmentform.js +++ b/public/viewjs/equipmentform.js @@ -17,8 +17,7 @@ if ($("#instruction-manual")[0].files.length > 0) { - var someRandomStuff = RandomString(); - jsonData.instruction_manual_file_name = someRandomStuff + CleanFileName($("#instruction-manual")[0].files[0].name); + jsonData.instruction_manual_file_name = RandomString() + CleanFileName($("#instruction-manual")[0].files[0].name); } if (Grocy.DeleteInstructionManualOnSave) diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index 4b991f3f..7675e2a1 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -95,8 +95,7 @@ $('.save-product-button').on('click', function(e) if ($("#product-picture")[0].files.length > 0) { - var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100); - jsonData.picture_file_name = someRandomStuff + CleanFileName($("#product-picture")[0].files[0].name); + jsonData.picture_file_name = RandomString() + CleanFileName($("#product-picture")[0].files[0].name); } const location = $(e.currentTarget).attr('data-location') == 'return' ? '/products?product=' : '/product/'; diff --git a/public/viewjs/recipeform.js b/public/viewjs/recipeform.js index f10a90d0..e5a35179 100644 --- a/public/viewjs/recipeform.js +++ b/public/viewjs/recipeform.js @@ -40,8 +40,7 @@ $('.save-recipe').on('click', function(e) if ($("#recipe-picture")[0].files.length > 0) { - var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100); - jsonData.picture_file_name = someRandomStuff + CleanFileName($("#recipe-picture")[0].files[0].name); + jsonData.picture_file_name = RandomString() + CleanFileName($("#recipe-picture")[0].files[0].name); } const location = $(e.currentTarget).attr('data-location') == 'return' ? '/recipes?recipe=' : '/recipe/'; diff --git a/public/viewjs/userform.js b/public/viewjs/userform.js index 2e0f8482..a5a8dd0e 100644 --- a/public/viewjs/userform.js +++ b/public/viewjs/userform.js @@ -43,8 +43,7 @@ $('#save-user-button').on('click', function(e) if ($("#user-picture")[0].files.length > 0) { - var someRandomStuff = Math.random().toString(36).substring(2, 100) + Math.random().toString(36).substring(2, 100); - jsonData.picture_file_name = someRandomStuff + CleanFileName($("#user-picture")[0].files[0].name); + jsonData.picture_file_name = RandomString() + CleanFileName($("#user-picture")[0].files[0].name); } if (Grocy.EditMode === 'create')