cloud upload files

This commit is contained in:
2022-03-16 00:34:44 -05:00
parent 5753f7cf26
commit 6c60c6656a
20 changed files with 317 additions and 8 deletions

71
package-lock.json generated
View File

@@ -12,6 +12,7 @@
"axios": "^0.26.0", "axios": "^0.26.0",
"ejs": "^3.0.2", "ejs": "^3.0.2",
"express": "^4.17.1", "express": "^4.17.1",
"express-fileupload": "^1.3.1",
"express-myconnection": "^1.0.4", "express-myconnection": "^1.0.4",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"mysql": "^2.18.1", "mysql": "^2.18.1",
@@ -189,6 +190,17 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/busboy": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
"integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
"dependencies": {
"dicer": "0.3.0"
},
"engines": {
"node": ">=4.5.0"
}
},
"node_modules/bytes": { "node_modules/bytes": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@@ -402,6 +414,17 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
}, },
"node_modules/dicer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
"integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
"dependencies": {
"streamsearch": "0.1.2"
},
"engines": {
"node": ">=4.5.0"
}
},
"node_modules/dot-prop": { "node_modules/dot-prop": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz",
@@ -521,6 +544,17 @@
"node": ">= 0.10.0" "node": ">= 0.10.0"
} }
}, },
"node_modules/express-fileupload": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.3.1.tgz",
"integrity": "sha512-LD1yabD3exmWIFujKGDnT1rmxSomaqQSlUvzIsrA1ZgwCJ6ci7lg2YHFGM3Q6DfK+Yk0gAVU7GWLE7qDMwZLkw==",
"dependencies": {
"busboy": "^0.3.1"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/express-myconnection": { "node_modules/express-myconnection": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/express-myconnection/-/express-myconnection-1.0.4.tgz", "resolved": "https://registry.npmjs.org/express-myconnection/-/express-myconnection-1.0.4.tgz",
@@ -1487,6 +1521,14 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo=",
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/string_decoder": { "node_modules/string_decoder": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
@@ -1934,6 +1976,14 @@
"fill-range": "^7.0.1" "fill-range": "^7.0.1"
} }
}, },
"busboy": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/busboy/-/busboy-0.3.1.tgz",
"integrity": "sha512-y7tTxhGKXcyBxRKAni+awqx8uqaJKrSFSNFSeRG5CsWNdmy2BIK+6VGWEW7TZnIO/533mtMEA4rOevQV815YJw==",
"requires": {
"dicer": "0.3.0"
}
},
"bytes": { "bytes": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
@@ -2103,6 +2153,14 @@
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
}, },
"dicer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/dicer/-/dicer-0.3.0.tgz",
"integrity": "sha512-MdceRRWqltEG2dZqO769g27N/3PXfcKl04VhYnBlo2YhH7zPi88VebsjTKclaOyiuMaGU72hTfw3VkUitGcVCA==",
"requires": {
"streamsearch": "0.1.2"
}
},
"dot-prop": { "dot-prop": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz",
@@ -2201,6 +2259,14 @@
"vary": "~1.1.2" "vary": "~1.1.2"
} }
}, },
"express-fileupload": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/express-fileupload/-/express-fileupload-1.3.1.tgz",
"integrity": "sha512-LD1yabD3exmWIFujKGDnT1rmxSomaqQSlUvzIsrA1ZgwCJ6ci7lg2YHFGM3Q6DfK+Yk0gAVU7GWLE7qDMwZLkw==",
"requires": {
"busboy": "^0.3.1"
}
},
"express-myconnection": { "express-myconnection": {
"version": "1.0.4", "version": "1.0.4",
"resolved": "https://registry.npmjs.org/express-myconnection/-/express-myconnection-1.0.4.tgz", "resolved": "https://registry.npmjs.org/express-myconnection/-/express-myconnection-1.0.4.tgz",
@@ -2931,6 +2997,11 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
}, },
"streamsearch": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string_decoder": { "string_decoder": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",

View File

@@ -17,6 +17,7 @@
"axios": "^0.26.0", "axios": "^0.26.0",
"ejs": "^3.0.2", "ejs": "^3.0.2",
"express": "^4.17.1", "express": "^4.17.1",
"express-fileupload": "^1.3.1",
"express-myconnection": "^1.0.4", "express-myconnection": "^1.0.4",
"morgan": "^1.10.0", "morgan": "^1.10.0",
"mysql": "^2.18.1", "mysql": "^2.18.1",

View File

@@ -2,6 +2,7 @@ const express = require('express');
const path = require('path'); const path = require('path');
const morgan = require('morgan'); const morgan = require('morgan');
const mysql = require('mysql'); const mysql = require('mysql');
const cloud_file = require('express-fileupload');
const myConecction = require('express-myconnection'); const myConecction = require('express-myconnection');
var puerto = 3001 var puerto = 3001
@@ -11,6 +12,7 @@ const app = express();
const clientesRutas = require('./rutas/rt_clientes'); const clientesRutas = require('./rutas/rt_clientes');
const productosRutas = require('./rutas/rt_items'); const productosRutas = require('./rutas/rt_items');
const generalesRutas = require('./rutas/rt_Generales'); const generalesRutas = require('./rutas/rt_Generales');
const cloud_rutas = require('./rutas/rt_cloud');
//configuraciones //configuraciones
app.set('port',process.env.PORT||puerto); app.set('port',process.env.PORT||puerto);
@@ -19,6 +21,7 @@ app.set('views',path.join(__dirname, 'views'));
//app.set('vistas',path.join(__dirname, 'vistas')); //app.set('vistas',path.join(__dirname, 'vistas'));
//middlewares //middlewares
app.use(morgan('dev')); app.use(morgan('dev'));
app.use(myConecction(mysql,{ app.use(myConecction(mysql,{
//host:'192.168.10.50', //host:'192.168.10.50',
@@ -31,11 +34,17 @@ app.use(myConecction(mysql,{
//cuando reciba dato desde req body //cuando reciba dato desde req body
app.use(express.json({limit: '25mb'})); app.use(express.json({limit: '25mb'}));
app.use(express.urlencoded({limit:'25mb',extended:false})); app.use(express.urlencoded({limit:'25mb',extended:false}));
//
//app.use(cloud_file);
app.use(cloud_file({
limits: { fileSize: 50 * 1024 * 1024 },
}));
//rutas //rutas
app.use('/', clientesRutas); app.use('/', clientesRutas);
app.use('/', productosRutas); app.use('/', productosRutas);
app.use('/', generalesRutas); app.use('/', generalesRutas);
app.use('/', cloud_rutas);
//prueba de json directa //prueba de json directa
app.get('/pruebaJson',function(req,res){ app.get('/pruebaJson',function(req,res){

View File

@@ -80,10 +80,4 @@ controlador.verVentasJson = (req, res) => {
res.render('panel_control'); res.render('panel_control');
}; };
module.exports = controlador; module.exports = controlador;

View File

@@ -0,0 +1,45 @@
const controlador={};
const dirPath = "/home/pablinux/Projects/Node/APP-SIGMA-WEB/src/public/files/";
//********* APP-panel control ********//
controlador.upload = (req, res) => {
if(!req.files||Object.keys(req.files).lenght===0){
return res.status(400).send({message:'archivos no cargados'});
}else{
const file = req.files.file_toUpload;
const path = dirPath + file.name;
console.log(path);
file.mv(path, (err) => {
if (err) {
return res.status(500).send(err);
}
return res.send({ status: "success", path: path });
});
}
};
//ruta actual
const procesarPath = (path) => {
return path ? path.replace(/-/g,'/'):'/';
}
const fs = require('fs');
function leer_dir(dir){
var json = [];
var files = fs.readdirSync(dirPath);
files.forEach(function(arch,idx){
json.push({"indice": idx, "archivo": arch});
});
//console.log(json);
return json;
}
controlador.ver_dirActual = (req, res) => {
let dir = procesarPath(req.params.path);
var files = leer_dir("files");
//res.render('cloud');
res.render('cloud',{
data:files
});
};
module.exports = controlador;

17
src/public/css/cloud.css Normal file
View File

@@ -0,0 +1,17 @@
body{
background:rgb(10, 10, 10);
color: rgb(255, 255, 255);
}
.files{
background: rgba(100, 100, 100, 0.5);
margin: 10px;
padding: 5px;
}
.info{
font-family: sigma_font;
font-size: 20px;
margin-left: 10px;
}
.upload{
margin: 2px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>Error</h1>
</body>
</html>

View File

@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="es" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
body{
background: rgba(0, 0, 0, 0.8);
}
.etiqueta{
background: rgb(255, 255, 255);
width: 34mm;
height: 25mm;
}
.titulo{
text-align: center;
}
.codigo{
align-items: center;
}
.codigo img{
display:block;
margin:auto;
}
.precio{
display: flex;
font-size: 18px;
margin-top: 4px;
}
.p1{
left: 0px;
margin: auto;
font-weight: bold;
}
.p2{
right: 0px;
margin: auto;
}
/*1mm = 3,779 527 559 055 1 Pixel [px]
34mm = 128px
25mm = 94px
*/
</style>
</head>
<body>
<div class="etiqueta">
<div class="titulo">Nombre Producto</div>
<div class="codigo">
<img src="bar_generado.png" alt="Codigo Barra" height="48" width="96"/>
</div>
<div class="precio">
<div class="p1"> $15.23</div>
<div class="p2"> $15.23</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="es" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
body{
background: rgba(0, 0, 0, 0.8);
}
.etiqueta{
padding-top: 3px;
background: rgb(255, 255, 255);
width: 34mm;
height: 25mm;
}
.titulo{
text-align: center;
}
.codigo{
}
.p1{
margin-top: 10px;
font-weight: bold;
}
.p2{
margin-top: 10px;
}
.row{
display: flex;
}
</style>
</head>
<body>
<div class="etiqueta">
<div class="titulo">Nombre Producto</div>
<div class="row">
<div class="codigo">
<img src="qr_generado.png" alt="Codigo Barra" height="70" width="70"/>
</div>
<div class="precio">
<div class="p1"> $15.23</div>
<div class="p2"> $15.23</div>
</div>
</div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -10,6 +10,4 @@ rutas.get('/gp_precios', controlador_init.app_GpPrecios);//consulta grupo precio
rutas.get('/origen_pedidos', controlador_init.app_ORIGENES);//consulta grupo precios rutas.get('/origen_pedidos', controlador_init.app_ORIGENES);//consulta grupo precios
rutas.get('/panel_control', controlador_init.panel_control);//consulta grupo precios rutas.get('/panel_control', controlador_init.panel_control);//consulta grupo precios
module.exports = rutas; module.exports = rutas;

9
src/rutas/rt_cloud.js Normal file
View File

@@ -0,0 +1,9 @@
const express = require('express');
const rutas = express.Router();
const controlador_cloud = require('../controladores/controlador_cloud');
//para cargar archivos
rutas.post('/upload', controlador_cloud.upload);//ver productos en modo json/get
rutas.get('/cloud/', controlador_cloud.ver_dirActual);//ver productos en modo json/get
module.exports = rutas;

50
src/views/cloud.ejs Normal file
View File

@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<title>Cloud SIGMA</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="./css/tipografias.css" rel="stylesheet" type="text/css"/>
<link href="./css/cloud.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="img/favicon_sigma/android-chrome-192x192.png" alt="" width="36" height="36"></a>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Buscar Archivo" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav>
<!-- formulario para subir archivos --->
</br>
<div class="row upload">
<label for="basic-url" class="form-label info">SIGMA Cloud</label>
<form class="d-flex" method="POST" action="/upload" enctype="multipart/form-data">
<div class="input-group mb-3">
<input type="file" name="file_toUpload" class="form-control"/>
<input type="submit" class="btn btn-outline-secondary"/>
</div>
</form>
</div>
<!-- formulario para subir archivos --->
</br>
<div class="row mb-3 files">
<div><a href="">.. retornar</a></div>
<% for (i in data) { %>
<div>
<span>#<%= data[i].indice%> </span>
<a href=""><%= data[i].archivo%></a>
</div>
</br>
<% } %>
</div>
<script type="text/javascript">
var files=[];
files = <%= data %>;
console.log(data);
</script>
</body>
</html>