diff --git a/src/components/generateUrlCode.js b/src/components/generateUrlCode.js new file mode 100644 index 0000000..52126c8 --- /dev/null +++ b/src/components/generateUrlCode.js @@ -0,0 +1,22 @@ + +export const generateUrlCode = ( type ) => { + let code = 'op?' + type + '=' + let hash = [ + '!', '@', '#', '$', '%', '^', '&', '*', + 'Q', 'W', 'X', 'S', 'q', 'w', 'x', 's' + ] + code += hash[ randomInt(7, 14) ] + + hash[ randomInt(7, 14) ] + + hash[ randomInt(7, 14) ] + + hash[ randomInt(0, 7) ] + + hash[ randomInt(0, 7) ] + + hash[ randomInt(0, 7) ] + + randomInt(0, 9) + + randomInt(0, 9) + + randomInt(0, 9) + return code +} + +const randomInt = (min, max) => { + return min + Math.floor((max - min) * Math.random()) +} \ No newline at end of file diff --git a/src/components/index/indexConsole/commands/fetchCommands/Abstract Utils/FormGenerator.js b/src/components/index/indexConsole/commands/fetchCommands/Abstract Utils/FormGenerator.js index 88e32af..5b7ec75 100644 --- a/src/components/index/indexConsole/commands/fetchCommands/Abstract Utils/FormGenerator.js +++ b/src/components/index/indexConsole/commands/fetchCommands/Abstract Utils/FormGenerator.js @@ -40,6 +40,7 @@ const FormGenerator = ({ * { * type: 'text', * name: 'name', + * endpoint: 'Album', * ref: React.createRef() * } } input - basic text input */ @@ -50,7 +51,7 @@ const TextInputGenerator = ({
{ input.name + ':' } @@ -64,7 +65,8 @@ const TextInputGenerator = ({ * { * type: 'file', * name: 'name', - * fileType: 'image', + * endpoint: 'Album', + * fileType: 'image' or 'audio', * dropInfo: dropInfo, setDropInfo: setDropInfo(), #useState * file: file, setFile: setFile() #useState * } } input - @@ -112,9 +114,10 @@ const UploadInputGenerator = ({ onLoadFile( event ) } /> diff --git a/src/components/index/indexConsole/commands/fetchCommands/Album/Create.js b/src/components/index/indexConsole/commands/fetchCommands/Album/Create.js index 85b01cd..962af3c 100644 --- a/src/components/index/indexConsole/commands/fetchCommands/Album/Create.js +++ b/src/components/index/indexConsole/commands/fetchCommands/Album/Create.js @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react' import { connect } from 'react-redux' import { createAlbum } from '../../../../../../stores/album/duck/operations' +import { generateUrlCode } from '../../../../../generateUrlCode' import FormGenerator from '../Abstract Utils/FormGenerator' @@ -23,17 +24,20 @@ const AlbumCreate = ({ let inputList = [ { type: 'text', - name: 'titleAlbum', + name: 'title', + endpoint: 'Album', ref: titleInput }, { type: 'text', - name: 'descriptionAlbum', + name: 'description', + endpoint: 'Album', ref: descriptionInput }, { type: 'file', - name: 'imageAlbum', + name: 'image', + endpoint: 'Album', fileType: 'image', dropInfo: imageInfo, setDropInfo: setImageInfo, @@ -59,7 +63,7 @@ const AlbumCreate = ({ title: title, description: description, image: image, - url_code: generateUrlCode(), + url_code: generateUrlCode( 'album' ), } await createAlbum( album, @@ -68,29 +72,6 @@ const AlbumCreate = ({ setMessage( response['info'] + '\n' ) }) } - - const generateUrlCode = () => { - let code = 'op?album=' - let hash = [ - '!', '@', '#', '$', '%', '^', '&', '*', - 'Q', 'W', 'X', 'S', 'q', 'w', 'x', 's' - ] - code += - + hash[ randomInt(7, 14) ] - + hash[ randomInt(7, 14) ] - + hash[ randomInt(7, 14) ] - + hash[ randomInt(0, 7) ] - + hash[ randomInt(0, 7) ] - + hash[ randomInt(0, 7) ] - + randomInt(0, 9) - + randomInt(0, 9) - + randomInt(0, 9) - return code - } - - const randomInt = (min, max) => { - return min + Math.floor((max - min) * Math.random()) - } useEffect( () => {