From da6f0d232ac3d4bfb5f869a3cd07c39788bcbbee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janko=20Marohni=C4=87?= Date: Sun, 19 Sep 2021 11:13:14 +0200 Subject: [PATCH] Replace randomstring with nanoid randomstring requires Node.js polyfill for crypto, and I believe that nanoid doesn't require anything. --- app/javascript/fileUpload.js | 4 ++-- package.json | 2 +- yarn.lock | 14 +------------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/javascript/fileUpload.js b/app/javascript/fileUpload.js index 401e838..fb08b0f 100644 --- a/app/javascript/fileUpload.js +++ b/app/javascript/fileUpload.js @@ -12,7 +12,7 @@ import { AwsS3Multipart, } from 'uppy' -const randomstring = require('randomstring') +import { nanoid } from 'nanoid' const singleFileUpload = (fileInput) => { const imagePreview = document.getElementById(fileInput.dataset.previewElement) @@ -67,7 +67,7 @@ const multipleFileUpload = (fileInput) => { const hiddenField = document.createElement('input') hiddenField.type = 'hidden' - hiddenField.name = `album[photos_attributes][${randomstring.generate()}][image]` + hiddenField.name = `album[photos_attributes][${nanoid()}][image]` hiddenField.value = uploadedFileData(file, response, fileInput) document.querySelector('form').appendChild(hiddenField) diff --git a/package.json b/package.json index 9f83d9a..3a90ed3 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "css-loader": "^6.3.0", "css-minimizer-webpack-plugin": "^3.0.2", "mini-css-extract-plugin": "^2.3.0", - "randomstring": "^1.1.5", + "nanoid": "^3.1.25", "style-loader": "^3.2.1", "uppy": "^1.8.0", "webpack": "^5.51.1", diff --git a/yarn.lock b/yarn.lock index c364d47..b6a0abe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1599,11 +1599,6 @@ array-union@^2.1.0: resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== -array-uniq@1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.2.tgz#5fcc373920775723cfd64d65c64bef53bf9eba6d" - integrity sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0= - arraybuffer.slice@~0.0.7: version "0.0.7" resolved "https://registry.yarnpkg.com/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz#3bbc4275dd584cc1b10809b89d4e8b63a69e7675" @@ -3437,7 +3432,7 @@ namespace-emitter@^2.0.1: resolved "https://registry.yarnpkg.com/namespace-emitter/-/namespace-emitter-2.0.1.tgz#978d51361c61313b4e6b8cf6f3853d08dfa2b17c" integrity sha512-N/sMKHniSDJBjfrkbS/tpkPj4RAbvW3mr8UAzvlMHyun93XEm83IAvhWtJVHo+RHn/oO8Job5YN4b+wRjSVp5g== -nanoid@^3.1.23: +nanoid@^3.1.23, nanoid@^3.1.25: version "3.1.25" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.25.tgz#09ca32747c0e543f0e1814b7d3793477f9c8e152" integrity sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q== @@ -4022,13 +4017,6 @@ randombytes@^2.1.0: dependencies: safe-buffer "^5.1.0" -randomstring@^1.1.5: - version "1.1.5" - resolved "https://registry.yarnpkg.com/randomstring/-/randomstring-1.1.5.tgz#6df0628f75cbd5932930d9fe3ab4e956a18518c3" - integrity sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM= - dependencies: - array-uniq "1.0.2" - range-parser@^1.2.1, range-parser@~1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"