Skip to content

Commit

Permalink
Replace randomstring with nanoid
Browse files Browse the repository at this point in the history
randomstring requires Node.js polyfill for crypto, and I believe that
nanoid doesn't require anything.
  • Loading branch information
janko committed Sep 19, 2021
1 parent 8900c6c commit da6f0d2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/javascript/fileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 1 addition & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit da6f0d2

Please sign in to comment.